65
66
67
68
69
70
71
72
73
74
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
|
# File 'lib/beaker/host/unix/pkg.rb', line 65
def install_package(name, cmdline_args = '', version = nil, opts = {})
case self['platform']
when /sles-/
execute("zypper --non-interactive in #{name}", opts)
when /el-4/
@logger.debug("Package installation not supported on rhel4")
when /fedora-(2[2-9])/
if version
name = "#{name}-#{version}"
end
execute("dnf -y #{cmdline_args} install #{name}", opts)
when /cisco|fedora|centos|eos|el-/
if version
name = "#{name}-#{version}"
end
execute("yum -y #{cmdline_args} install #{name}", opts)
when /ubuntu|debian|cumulus|huaweios/
if version
name = "#{name}=#{version}"
end
update_apt_if_needed
execute("apt-get install --force-yes #{cmdline_args} -y #{name}", opts)
when /solaris-11/
if opts[:acceptable_exit_codes]
opts[:acceptable_exit_codes] << 4
else
opts[:acceptable_exit_codes] = [0, 4] unless opts[:accept_all_exit_codes]
end
execute("pkg #{cmdline_args} install #{name}", opts)
when /solaris-10/
execute("pkgutil -i -y #{cmdline_args} #{name}", opts)
when /openbsd/
begin
execute("pkg_add -I #{cmdline_args} #{name}", opts) do |command|
if command.stderr =~ /^Ambiguous: #{name} could be (.+)$/
name = $1.chomp.split(' ').collect { |x|
x =~ /-(\d[^-p]+)/
[x, $1]
}.select { |x|
Gem::Version.new(x[1]) < Gem::Version.new('2.2.0')
}.sort { |a,b|
Gem::Version.new(b[1]) <=> Gem::Version.new(a[1])
}.collect { |x|
x[0]
}.first
raise ArgumentException
end
command.stdout.split(/\n/).select { |x| x =~ /^\s+ln\s/ }.each do |ln|
execute(ln, opts)
end
end
rescue
retry
end
else
raise "Package #{name} cannot be installed on #{self}"
end
end
|