Module: Mac::Pkg

Includes:
Beaker::CommandFactory
Included in:
Host
Defined in:
lib/beaker/host/mac/pkg.rb

Instance Attribute Summary

Attributes included from Beaker::CommandFactory

#assertions

Instance Method Summary collapse

Methods included from Beaker::CommandFactory

#execute, #fail_test

Instance Method Details

#check_for_package(name) ⇒ Object



4
5
6
# File 'lib/beaker/host/mac/pkg.rb', line 4

def check_for_package(name)
  raise "Package #{name} cannot be queried on #{self}"
end

#deploy_package_repo(path, name, version) ⇒ Object

Note:

See Beaker::DSL::Helpers::HostHelpers#deploy_package_repo for info on params

Deploy configuration generated by the packaging tooling to this host.

This method calls one of #deploy_apt_repo, #deploy_yum_repo, or #deploy_zyp_repo depending on the platform of this Host.



51
52
53
# File 'lib/beaker/host/mac/pkg.rb', line 51

def deploy_package_repo(path, name, version)
  raise "Package repo cannot be deployed on #{self}; the platform is not supported"
end

#determine_if_x86_64Boolean

Examine the host system to determine the architecture

Returns:

  • (Boolean)

    true if x86_64, false otherwise



57
58
59
60
# File 'lib/beaker/host/mac/pkg.rb', line 57

def determine_if_x86_64
  result = exec(Beaker::Command.new("uname -a | grep x86_64"), :expect_all_exit_codes => true)
  result.exit_code == 0
end

#generic_install_dmg(dmg_file, pkg_base, pkg_name) ⇒ Object

Install a package from a specified dmg

@example: Install vagrant from URL

mymachost.generic_install_dmg('https://releases.hashicorp.com/vagrant/1.8.4/vagrant_1.8.4.dmg', 'Vagrant', 'Vagrant.pkg')

Parameters:

  • dmg_file (String)

    The dmg file, including path if not relative. Can be a URL.

  • pkg_base (String)

    The base name of the directory that the dmg attaches to under `/Volumes`

  • pkg_name (String)

    The name of the package file that should be used by the installer



22
23
24
25
26
27
28
29
# File 'lib/beaker/host/mac/pkg.rb', line 22

def generic_install_dmg(dmg_file, pkg_base, pkg_name)
  execute("test -f #{dmg_file}", :accept_all_exit_codes => true) do |result|
    execute("curl -O #{dmg_file}") unless result.exit_code == 0
  end
  dmg_name = File.basename(dmg_file, '.dmg')
  execute("hdiutil attach #{dmg_name}.dmg")
  execute("installer -pkg /Volumes/#{pkg_base}/#{pkg_name} -target /")
end

#install_package(name, cmdline_args = '', version = nil) ⇒ Object



8
9
10
# File 'lib/beaker/host/mac/pkg.rb', line 8

def install_package(name, cmdline_args = '', version = nil)
  generic_install_dmg("#{name}.dmg", name, "#{name}.pkg")
end

#pe_puppet_agent_promoted_package_info(puppet_collection = nil, opts = {}) ⇒ String

Gets host-specific information for PE promoted puppet-agent packages

Parameters:

  • puppet_collection (String) (defaults to: nil)

    Name of the puppet collection to use

  • opts (Hash{Symbol=>String}) (defaults to: {})

    Options hash to provide extra values

Returns:

  • (String, String, String)

    Host-specific information for packages

    1. release_path_end Suffix for the release_path. Used on Windows. Check

    Windows::Pkg#pe_puppet_agent_promoted_package_info to see usage.

    1. release_file Path to the file on release build servers

    2. download_file Filename for the package itself

Raises:

  • (ArgumentError)


115
116
117
118
119
120
121
122
123
# File 'lib/beaker/host/mac/pkg.rb', line 115

def pe_puppet_agent_promoted_package_info( puppet_collection = nil, opts = {} )
  error_message = "Must provide %s argument to get puppet agent dev package information"
  raise ArgumentError, error_message % "puppet_collection" unless puppet_collection

  variant, version, arch, codename = self['platform'].to_array
  release_file = "/repos/apple/#{version}/#{puppet_collection}/#{arch}/puppet-agent-*"
  download_file = "puppet-agent-#{variant}-#{version}.tar.gz"
  return '', release_file, download_file
end

#pe_puppet_agent_promoted_package_install(onhost_copy_base, onhost_copied_download, onhost_copied_file, download_file, opts) ⇒ Object

Installs a given PE promoted package on a host

Parameters:

  • onhost_copy_base (String)

    Base copy directory on the host

  • onhost_copied_download (String)

    Downloaded file path on the host

  • onhost_copied_file (String)

    Copied file path once un-compressed

  • download_file (String)

    File name of the downloaded file

  • opts (Hash{Symbol=>String})

    additional options

Returns:

  • nil



134
135
136
137
138
139
140
141
# File 'lib/beaker/host/mac/pkg.rb', line 134

def pe_puppet_agent_promoted_package_install(
  onhost_copy_base, onhost_copied_download, onhost_copied_file, download_file, opts
)
  execute("tar -zxvf #{onhost_copied_download} -C #{onhost_copy_base}")
  # move to better location
  execute("mv #{onhost_copied_file}.dmg .")
  self.install_package("puppet-agent-*")
end

#puppet_agent_dev_package_info(puppet_collection = nil, puppet_agent_version = nil, opts = {}) ⇒ String

Note:

OSX does require :download_url to be set on the opts argument in order to check for builds on the builds server

Gets the path & file name for the puppet agent dev package on OSX

Parameters:

  • puppet_collection (String) (defaults to: nil)

    Name of the puppet collection to use

  • puppet_agent_version (String) (defaults to: nil)

    Version of puppet agent to get

  • opts (Hash{Symbol=>String}) (defaults to: {})

    Options hash to provide extra values

Returns:

  • (String, String)

    Path to the directory and filename of the package, respectively

Raises:

  • (ArgumentError)

    If one of the two required parameters (puppet_collection, puppet_agent_version) is either not passed or set to nil



75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/beaker/host/mac/pkg.rb', line 75

def puppet_agent_dev_package_info( puppet_collection = nil, puppet_agent_version = nil, opts = {} )
  error_message = "Must provide %s argument to get puppet agent dev package information"
  raise ArgumentError, error_message % "puppet_collection" unless puppet_collection
  raise ArgumentError, error_message % "puppet_agent_version" unless puppet_agent_version
  raise ArgumentError, error_message % "opts[:download_url]" unless opts[:download_url]

  variant, version, arch, codename = self['platform'].to_array

  mac_pkg_name = "puppet-agent-#{puppet_agent_version}"
  version = version[0,2] + '.' + version[2,2] unless version.include?(".")
  # newest hotness
  path_chunk = "apple/#{version}/#{puppet_collection}/#{arch}"
  release_path_end = path_chunk
  # moved to doing this when 'el capitan' came out & the objection was
  # raised that the code name wasn't a fact, & as such can be hard to script
  # example: puppet-agent-0.1.0-1.osx10.9.dmg
  release_file = "#{mac_pkg_name}-1.osx#{version}.dmg"
  if not link_exists?("#{opts[:download_url]}/#{release_path_end}/#{release_file}") # new hotness
    # little older change involved the code name as only difference from above
    # example: puppet-agent-0.1.0-1.mavericks.dmg
    release_file = "#{mac_pkg_name}-1.#{codename}.dmg"
  end
  if not link_exists?("#{opts[:download_url]}/#{release_path_end}/#{release_file}") # oops, try the old stuff
    release_path_end = "apple/#{puppet_collection}"
    # example: puppet-agent-0.1.0-osx-10.9-x86_64.dmg
    release_file = "#{mac_pkg_name}-#{variant}-#{version}-x86_64.dmg"
  end
  return release_path_end, release_file
end

#uninstall_package(name, cmdline_args = '') ⇒ Object



31
32
33
# File 'lib/beaker/host/mac/pkg.rb', line 31

def uninstall_package(name, cmdline_args = '')
  raise "Package #{name} cannot be uninstalled on #{self}"
end

#upgrade_package(name, cmdline_args = '') ⇒ Object

Upgrade an installed package to the latest available version

Parameters:

  • name (String)

    The name of the package to update

  • cmdline_args (String) (defaults to: '')

    Additional command line arguments for the package manager



40
41
42
# File 'lib/beaker/host/mac/pkg.rb', line 40

def upgrade_package(name, cmdline_args = '')
    raise "Package #{name} cannot be upgraded on #{self}"
end