Module: Unix::Pkg
Constant Summary collapse
- DEBIAN_PLATFORM_CODENAMES =
Debian repositories contain packages for all architectures, so we need to map to an architecturless name for each platform
{ 'debian-6-amd64' => 'squeeze', 'debian-6-i386' => 'squeeze', 'debian-7-amd64' => 'wheezy', 'debian-7-i386' => 'wheezy', 'ubuntu-10.04-amd64' => 'lucid', 'ubuntu-10.04-i386' => 'lucid', 'ubuntu-12.04-amd64' => 'precise', 'ubuntu-12.04-i386' => 'precise', }
Instance Method Summary collapse
- #check_for_package(name) ⇒ Object
-
#deploy_apt_repo(path, name, version) ⇒ Object
Deploy apt configuration generated by the packaging tooling.
-
#deploy_package_repo(path, name, version) ⇒ Object
Deploy configuration generated by the packaging tooling to this host.
-
#deploy_yum_repo(path, name, version) ⇒ Object
Deploy yum configuration generated by the packaging tooling.
-
#deploy_zyp_repo(path, name, version) ⇒ Object
Deploy zypper repo configuration generated by the packaging tooling.
- #install_package(name, cmdline_args = '') ⇒ Object
-
#pkg_initialize ⇒ Object
This method overrides Host::pkg_initialize to provide unix-specific package management setup.
- #uninstall_package(name, cmdline_args = '') ⇒ Object
-
#update_apt_if_needed ⇒ Object
If apt has not been updated since the last repo deployment it is updated.
-
#upgrade_package(name, cmdline_args = '') ⇒ Object
Upgrade an installed package to the latest available version.
Methods included from Beaker::CommandFactory
Instance Method Details
#check_for_package(name) ⇒ Object
10 11 12 13 14 15 16 17 18 |
# File 'lib/beaker/host/unix/pkg.rb', line 10 def check_for_package(name) result = exec(Beaker::Command.new("which #{name}"), :acceptable_exit_codes => (0...127)) case self['platform'] when /solaris-10/ result.stdout =~ %r|/.*/#{name}| else result.exit_code == 0 end end |
#deploy_apt_repo(path, name, version) ⇒ Object
Due to the debian use of codenames in repos, the DEBIAN_PLATFORM_CODENAMES map must be kept up-to-date as support for new versions is added.
See Beaker::DSL::Helpers::deploy_package_repo for info on params
Deploy apt configuration generated by the packaging tooling
116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/beaker/host/unix/pkg.rb', line 116 def deploy_apt_repo(path, name, version) codename = DEBIAN_PLATFORM_CODENAMES[self['platform']] if codename.nil? @logger.warning "Could not determine codename for debian platform #{self['platform']}. Skipping deployment of repo #{name}" return end repo_file = "#{path}/deb/pl-#{name}-#{version}-#{codename}.list" do_scp_to repo_file, "/etc/apt/sources.list.d/#{name}.list", {} @apt_needs_update = true end |
#deploy_package_repo(path, name, version) ⇒ Object
See Beaker::DSL::Helpers::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.
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 |
# File 'lib/beaker/host/unix/pkg.rb', line 156 def deploy_package_repo(path, name, version) if not File.exists? path @logger.warning "Was asked to deploy package repository from #{path}, but it doesn't exist!" return end case self['platform'] when /el-4/ @logger.debug("Package repo deploy is not supported on rhel4") when /fedora|centos|el-/ deploy_yum_repo(path, name, version) when /ubuntu|debian/ deploy_apt_repo(path, name, version) when /sles/ deploy_zyp_repo(path, name, version) else # solaris, windows raise "Package repo cannot be deployed on #{self}; the platform is not supported" end end |
#deploy_yum_repo(path, name, version) ⇒ Object
See Beaker::DSL::Helpers::deploy_package_repo for info on params
Deploy yum configuration generated by the packaging tooling
132 133 134 135 |
# File 'lib/beaker/host/unix/pkg.rb', line 132 def deploy_yum_repo(path, name, version) repo_file = "#{path}/rpm/pl-#{name}-#{version}-repos-pe-#{self['platform']}.repo" do_scp_to repo_file, "/etc/yum.repos.d/#{name}.repo", {} end |
#deploy_zyp_repo(path, name, version) ⇒ Object
See Beaker::DSL::Helpers::deploy_package_repo for info on params
Deploy zypper repo configuration generated by the packaging tooling
141 142 143 144 145 146 147 |
# File 'lib/beaker/host/unix/pkg.rb', line 141 def deploy_zyp_repo(path, name, version) repo_file = "#{path}/rpm/pl-#{name}-#{version}-repos-pe-#{self['platform']}.repo" repo = IniFile.load(repo_file) repo_name = repo.sections[0] repo_url = repo[repo_name]["baseurl"] execute("zypper ar -t YUM #{repo_url} #{repo_name}") end |
#install_package(name, cmdline_args = '') ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/beaker/host/unix/pkg.rb', line 31 def install_package(name, cmdline_args = '') case self['platform'] when /sles-/ execute("zypper --non-interactive in #{name}") when /el-4/ @logger.debug("Package installation not supported on rhel4") when /fedora|centos|el-/ execute("yum -y #{cmdline_args} install #{name}") when /ubuntu|debian/ update_apt_if_needed execute("apt-get install #{cmdline_args} -y #{name}") when /solaris-11/ execute("pkg #{cmdline_args} install #{name}") when /solaris-10/ execute("pkgutil -i -y #{cmdline_args} #{name}") else raise "Package #{name} cannot be installed on #{self}" end end |
#pkg_initialize ⇒ Object
This method overrides Host::pkg_initialize to provide unix-specific package management setup
6 7 8 |
# File 'lib/beaker/host/unix/pkg.rb', line 6 def pkg_initialize @apt_needs_update = true end |
#uninstall_package(name, cmdline_args = '') ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/beaker/host/unix/pkg.rb', line 51 def uninstall_package(name, cmdline_args = '') case self['platform'] when /sles-/ execute("zypper --non-interactive rm #{name}") when /el-4/ @logger.debug("Package uninstallation not supported on rhel4") when /fedora|centos|el-/ execute("yum -y #{cmdline_args} remove #{name}") when /ubuntu|debian/ execute("apt-get purge #{cmdline_args} -y #{name}") when /solaris-11/ execute("pkg #{cmdline_args} uninstall #{name}") when /solaris-10/ execute("pkgutil -r -y #{cmdline_args} #{name}") else raise "Package #{name} cannot be installed on #{self}" end end |
#update_apt_if_needed ⇒ Object
If apt has not been updated since the last repo deployment it is updated. Otherwise this is a noop
22 23 24 25 26 27 28 29 |
# File 'lib/beaker/host/unix/pkg.rb', line 22 def update_apt_if_needed if self['platform'] =~ /debian|ubuntu/ if @apt_needs_update execute("apt-get update") @apt_needs_update = false end end end |
#upgrade_package(name, cmdline_args = '') ⇒ Object
Upgrade an installed package to the latest available version
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/beaker/host/unix/pkg.rb', line 75 def upgrade_package(name, cmdline_args = '') case self['platform'] when /sles-/ execute("zypper --non-interactive --no-gpg-checks up #{name}") when /el-4/ @logger.debug("Package upgrade is not supported on rhel4") when /fedora|centos|el-/ execute("yum -y #{cmdline_args} update #{name}") when /ubuntu|debian/ update_apt_if_needed execute("apt-get install -o Dpkg::Options::='--force-confold' #{cmdline_args} -y --force-yes #{name}") when /solaris-11/ execute("pkg #{cmdline_args} update #{name}") when /solaris-10/ execute("pkgutil -u -y #{cmdline_args} ${name}") else raise "Package #{name} cannot be upgraded on #{self}" end end |