Method: Unix::Pkg#check_for_package

Defined in:
lib/beaker/host/unix/pkg.rb

#check_for_package(name, opts = {}) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/beaker/host/unix/pkg.rb', line 24

def check_for_package(name, opts = {})
  opts = {:accept_all_exit_codes => true}.merge(opts)
  case self['platform']
    when /sles-10/
      result = execute("zypper se -i --match-exact #{name}", opts) { |result| result }
      result.stdout =~ /No packages found/ ? (return false) : (return result.exit_code == 0)
    when /sles-/
      result = execute("zypper se -i --match-exact #{name}", opts) { |result| result }
    when /el-4/
      @logger.debug("Package query not supported on rhel4")
      return false
    when /cisco|fedora|centos|eos|el-/
      result = execute("rpm -q #{name}", opts) { |result| result }
    when /ubuntu|debian|cumulus|huaweios/
      result = execute("dpkg -s #{name}", opts) { |result| result }
    when /solaris-11/
      result = execute("pkg info #{name}", opts) { |result| result }
    when /solaris-10/
      result = execute("pkginfo #{name}", opts) { |result| result }
      if result.exit_code == 1
        result = execute("pkginfo CSW#{name}", opts) { |result| result }
      end
    when /openbsd/
      result = execute("pkg_info #{name}", opts) { |result| result }
    else
      raise "Package #{name} cannot be queried on #{self}"
  end
  result.exit_code == 0
end