beaker 4.40.1 → 5.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (217) hide show
  1. checksums.yaml +4 -4
  2. data/.github/dependabot.yml +9 -0
  3. data/.github/workflows/release.yml +2 -2
  4. data/.github/workflows/test.yml +26 -13
  5. data/.rubocop.yml +23 -10
  6. data/.rubocop_todo.yml +34 -10
  7. data/CHANGELOG.md +13 -11
  8. data/Gemfile +12 -7
  9. data/Rakefile +99 -111
  10. data/acceptance/config/acceptance-options.rb +1 -1
  11. data/acceptance/config/base/acceptance-options.rb +2 -2
  12. data/acceptance/config/hypervisor/acceptance-options.rb +2 -2
  13. data/acceptance/config/subcommands/acceptance-options.rb +2 -2
  14. data/acceptance/fixtures/module/Rakefile +1 -1
  15. data/acceptance/fixtures/module/spec/acceptance/demo_spec.rb +8 -12
  16. data/acceptance/fixtures/module/spec/classes/init_spec.rb +0 -1
  17. data/acceptance/fixtures/module/spec/spec_helper_acceptance.rb +3 -5
  18. data/acceptance/lib/helpers/test_helper.rb +4 -3
  19. data/acceptance/pre_suite/subcommands/05_install_ruby.rb +2 -3
  20. data/acceptance/pre_suite/subcommands/08_install_beaker.rb +1 -2
  21. data/acceptance/tests/base/dsl/helpers/configuration_test.rb +4 -4
  22. data/acceptance/tests/base/dsl/helpers/hocon_helpers_test.rb +1 -2
  23. data/acceptance/tests/base/dsl/helpers/host_helpers/add_system32_hosts_entry_test.rb +0 -3
  24. data/acceptance/tests/base/dsl/helpers/host_helpers/archive_file_from_test.rb +3 -1
  25. data/acceptance/tests/base/dsl/helpers/host_helpers/backup_the_file_test.rb +9 -9
  26. data/acceptance/tests/base/dsl/helpers/host_helpers/check_for_package_test.rb +0 -4
  27. data/acceptance/tests/base/dsl/helpers/host_helpers/create_remote_file_test.rb +19 -26
  28. data/acceptance/tests/base/dsl/helpers/host_helpers/curl_on_test.rb +2 -2
  29. data/acceptance/tests/base/dsl/helpers/host_helpers/curl_with_retries_test.rb +0 -1
  30. data/acceptance/tests/base/dsl/helpers/host_helpers/on_test.rb +18 -13
  31. data/acceptance/tests/base/dsl/helpers/host_helpers/retry_on_test.rb +3 -3
  32. data/acceptance/tests/base/dsl/helpers/host_helpers/rsync_to_test.rb +22 -27
  33. data/acceptance/tests/base/dsl/helpers/host_helpers/run_cron_on_test.rb +12 -16
  34. data/acceptance/tests/base/dsl/helpers/host_helpers/run_script_on_test.rb +3 -4
  35. data/acceptance/tests/base/dsl/helpers/host_helpers/run_script_test.rb +3 -3
  36. data/acceptance/tests/base/dsl/helpers/host_helpers/scp_from_test.rb +4 -4
  37. data/acceptance/tests/base/dsl/helpers/host_helpers/scp_to_test.rb +3 -4
  38. data/acceptance/tests/base/dsl/helpers/host_helpers/shell_test.rb +5 -5
  39. data/acceptance/tests/base/dsl/helpers/host_helpers/upgrade_package_test.rb +3 -5
  40. data/acceptance/tests/base/dsl/platform_tag_confiner_test.rb +14 -17
  41. data/acceptance/tests/base/dsl/structure_test.rb +5 -11
  42. data/acceptance/tests/base/host/file_test.rb +2 -2
  43. data/acceptance/tests/base/host/group_test.rb +0 -1
  44. data/acceptance/tests/base/host/host_test.rb +66 -63
  45. data/acceptance/tests/base/host/packages.rb +1 -2
  46. data/acceptance/tests/base/host/packages_unix.rb +0 -55
  47. data/acceptance/tests/base/host/user_test.rb +0 -1
  48. data/acceptance/tests/base/host_prebuilt_steps/ssh_environment_test.rb +1 -2
  49. data/acceptance/tests/base/test_suite/export.rb +6 -9
  50. data/acceptance/tests/install/from_file.rb +2 -4
  51. data/acceptance/tests/load_path_bootstrap.rb +1 -1
  52. data/acceptance/tests/subcommands/destroy.rb +19 -21
  53. data/acceptance/tests/subcommands/exec.rb +0 -1
  54. data/acceptance/tests/subcommands/init.rb +2 -3
  55. data/acceptance/tests/subcommands/provision.rb +0 -1
  56. data/beaker.gemspec +4 -7
  57. data/docs/concepts/argument_processing_and_precedence.md +1 -10
  58. data/docs/how_to/debug_beaker_tests.md +12 -12
  59. data/docs/how_to/hosts/eos.md +2 -12
  60. data/docs/how_to/install_puppet.md +0 -18
  61. data/docs/how_to/the_beaker_dsl.md +0 -2
  62. data/lib/beaker/cli.rb +59 -68
  63. data/lib/beaker/command.rb +20 -28
  64. data/lib/beaker/command_factory.rb +3 -2
  65. data/lib/beaker/dsl/assertions.rb +6 -18
  66. data/lib/beaker/dsl/helpers/hocon_helpers.rb +3 -7
  67. data/lib/beaker/dsl/helpers/host_helpers.rb +62 -123
  68. data/lib/beaker/dsl/helpers/test_helpers.rb +3 -5
  69. data/lib/beaker/dsl/helpers/web_helpers.rb +19 -39
  70. data/lib/beaker/dsl/helpers.rb +2 -4
  71. data/lib/beaker/dsl/outcomes.rb +13 -15
  72. data/lib/beaker/dsl/patterns.rb +1 -3
  73. data/lib/beaker/dsl/roles.rb +17 -20
  74. data/lib/beaker/dsl/structure.rb +53 -65
  75. data/lib/beaker/dsl/test_tagging.rb +7 -10
  76. data/lib/beaker/dsl/wrappers.rb +15 -16
  77. data/lib/beaker/dsl.rb +2 -3
  78. data/lib/beaker/host/aix/exec.rb +1 -1
  79. data/lib/beaker/host/aix/file.rb +0 -1
  80. data/lib/beaker/host/aix/group.rb +1 -1
  81. data/lib/beaker/host/aix/user.rb +1 -1
  82. data/lib/beaker/host/aix.rb +3 -4
  83. data/lib/beaker/host/cisco.rb +27 -39
  84. data/lib/beaker/host/eos.rb +4 -30
  85. data/lib/beaker/host/freebsd/exec.rb +1 -1
  86. data/lib/beaker/host/freebsd/pkg.rb +3 -3
  87. data/lib/beaker/host/freebsd.rb +9 -12
  88. data/lib/beaker/host/mac/exec.rb +4 -4
  89. data/lib/beaker/host/mac/group.rb +7 -7
  90. data/lib/beaker/host/mac/pkg.rb +3 -106
  91. data/lib/beaker/host/mac/user.rb +2 -2
  92. data/lib/beaker/host/mac.rb +8 -9
  93. data/lib/beaker/host/pswindows/exec.rb +66 -70
  94. data/lib/beaker/host/pswindows/file.rb +3 -5
  95. data/lib/beaker/host/pswindows/group.rb +3 -3
  96. data/lib/beaker/host/pswindows/pkg.rb +12 -12
  97. data/lib/beaker/host/pswindows/user.rb +3 -3
  98. data/lib/beaker/host/pswindows.rb +4 -3
  99. data/lib/beaker/host/unix/exec.rb +80 -82
  100. data/lib/beaker/host/unix/file.rb +38 -43
  101. data/lib/beaker/host/unix/group.rb +1 -1
  102. data/lib/beaker/host/unix/pkg.rb +154 -417
  103. data/lib/beaker/host/unix/user.rb +2 -2
  104. data/lib/beaker/host/unix.rb +8 -11
  105. data/lib/beaker/host/windows/exec.rb +17 -17
  106. data/lib/beaker/host/windows/file.rb +3 -3
  107. data/lib/beaker/host/windows/group.rb +3 -3
  108. data/lib/beaker/host/windows/pkg.rb +3 -54
  109. data/lib/beaker/host/windows/user.rb +3 -3
  110. data/lib/beaker/host/windows.rb +12 -12
  111. data/lib/beaker/host.rb +76 -133
  112. data/lib/beaker/host_prebuilt_steps.rb +93 -198
  113. data/lib/beaker/hypervisor/noop.rb +2 -4
  114. data/lib/beaker/hypervisor.rb +44 -61
  115. data/lib/beaker/local_connection.rb +2 -4
  116. data/lib/beaker/logger.rb +68 -76
  117. data/lib/beaker/logger_junit.rb +21 -25
  118. data/lib/beaker/network_manager.rb +39 -42
  119. data/lib/beaker/options/command_line_parser.rb +12 -23
  120. data/lib/beaker/options/hosts_file_parser.rb +16 -24
  121. data/lib/beaker/options/options_file_parser.rb +3 -6
  122. data/lib/beaker/options/options_hash.rb +2 -7
  123. data/lib/beaker/options/parser.rb +86 -102
  124. data/lib/beaker/options/presets.rb +114 -123
  125. data/lib/beaker/options/subcommand_options_file_parser.rb +3 -6
  126. data/lib/beaker/options/validator.rb +26 -31
  127. data/lib/beaker/perf.rb +22 -27
  128. data/lib/beaker/platform.rb +38 -46
  129. data/lib/beaker/result.rb +7 -6
  130. data/lib/beaker/shared/error_handler.rb +8 -10
  131. data/lib/beaker/shared/fog_credentials.rb +5 -9
  132. data/lib/beaker/shared/host_manager.rb +36 -41
  133. data/lib/beaker/shared/options_resolver.rb +3 -7
  134. data/lib/beaker/shared/repetition.rb +2 -4
  135. data/lib/beaker/shared/semvar.rb +37 -41
  136. data/lib/beaker/shared/timed.rb +0 -3
  137. data/lib/beaker/shared.rb +1 -1
  138. data/lib/beaker/ssh_connection.rb +38 -47
  139. data/lib/beaker/subcommand.rb +17 -24
  140. data/lib/beaker/subcommands/subcommand_util.rb +4 -4
  141. data/lib/beaker/tasks/quick_start.rb +4 -9
  142. data/lib/beaker/tasks/rake_task.rb +25 -27
  143. data/lib/beaker/tasks/test.rb +4 -4
  144. data/lib/beaker/test_case.rb +15 -27
  145. data/lib/beaker/test_suite.rb +35 -39
  146. data/lib/beaker/test_suite_result.rb +45 -47
  147. data/lib/beaker/version.rb +1 -1
  148. data/lib/beaker.rb +5 -6
  149. data/spec/beaker/cli_spec.rb +121 -142
  150. data/spec/beaker/command_spec.rb +55 -59
  151. data/spec/beaker/dsl/assertions_spec.rb +36 -36
  152. data/spec/beaker/dsl/helpers/host_helpers_spec.rb +110 -131
  153. data/spec/beaker/dsl/helpers/test_helpers_spec.rb +9 -10
  154. data/spec/beaker/dsl/helpers/web_helpers_spec.rb +22 -31
  155. data/spec/beaker/dsl/outcomes_spec.rb +14 -14
  156. data/spec/beaker/dsl/roles_spec.rb +125 -130
  157. data/spec/beaker/dsl/structure_spec.rb +169 -158
  158. data/spec/beaker/dsl/test_tagging_spec.rb +89 -90
  159. data/spec/beaker/dsl/wrappers_spec.rb +32 -33
  160. data/spec/beaker/host/aix_spec.rb +14 -14
  161. data/spec/beaker/host/cisco_spec.rb +84 -94
  162. data/spec/beaker/host/eos_spec.rb +15 -36
  163. data/spec/beaker/host/freebsd/exec_spec.rb +3 -6
  164. data/spec/beaker/host/freebsd/pkg_spec.rb +24 -27
  165. data/spec/beaker/host/mac/exec_spec.rb +2 -3
  166. data/spec/beaker/host/mac/group_spec.rb +47 -56
  167. data/spec/beaker/host/mac/user_spec.rb +53 -62
  168. data/spec/beaker/host/pswindows/exec_spec.rb +30 -32
  169. data/spec/beaker/host/pswindows/file_spec.rb +16 -16
  170. data/spec/beaker/host/pswindows/user_spec.rb +17 -23
  171. data/spec/beaker/host/pswindows_spec.rb +13 -13
  172. data/spec/beaker/host/unix/exec_spec.rb +75 -80
  173. data/spec/beaker/host/unix/file_spec.rb +66 -73
  174. data/spec/beaker/host/unix/pkg_spec.rb +155 -401
  175. data/spec/beaker/host/unix_spec.rb +11 -207
  176. data/spec/beaker/host/windows/exec_spec.rb +30 -32
  177. data/spec/beaker/host/windows/file_spec.rb +18 -19
  178. data/spec/beaker/host/windows/group_spec.rb +10 -12
  179. data/spec/beaker/host/windows/pkg_spec.rb +6 -9
  180. data/spec/beaker/host/windows/user_spec.rb +17 -23
  181. data/spec/beaker/host/windows_spec.rb +39 -39
  182. data/spec/beaker/host_prebuilt_steps_spec.rb +172 -326
  183. data/spec/beaker/host_spec.rb +204 -284
  184. data/spec/beaker/hypervisor/hypervisor_spec.rb +36 -61
  185. data/spec/beaker/localhost_connection_spec.rb +10 -11
  186. data/spec/beaker/logger_junit_spec.rb +19 -30
  187. data/spec/beaker/logger_spec.rb +153 -136
  188. data/spec/beaker/network_manager_spec.rb +23 -23
  189. data/spec/beaker/options/command_line_parser_spec.rb +20 -23
  190. data/spec/beaker/options/hosts_file_parser_spec.rb +30 -32
  191. data/spec/beaker/options/options_file_parser_spec.rb +4 -7
  192. data/spec/beaker/options/options_hash_spec.rb +4 -6
  193. data/spec/beaker/options/parser_spec.rb +167 -167
  194. data/spec/beaker/options/presets_spec.rb +7 -9
  195. data/spec/beaker/options/subcommand_options_parser_spec.rb +13 -14
  196. data/spec/beaker/options/validator_spec.rb +10 -11
  197. data/spec/beaker/perf_spec.rb +18 -21
  198. data/spec/beaker/platform_spec.rb +25 -36
  199. data/spec/beaker/shared/error_handler_spec.rb +7 -16
  200. data/spec/beaker/shared/fog_credentials_spec.rb +29 -29
  201. data/spec/beaker/shared/host_manager_spec.rb +50 -84
  202. data/spec/beaker/shared/options_resolver_spec.rb +9 -12
  203. data/spec/beaker/shared/repetition_spec.rb +17 -24
  204. data/spec/beaker/shared/semvar_spec.rb +21 -26
  205. data/spec/beaker/ssh_connection_spec.rb +76 -83
  206. data/spec/beaker/subcommand/subcommand_util_spec.rb +31 -33
  207. data/spec/beaker/subcommand_spec.rb +75 -77
  208. data/spec/beaker/test_case_spec.rb +25 -50
  209. data/spec/beaker/test_suite_spec.rb +147 -154
  210. data/spec/helpers.rb +48 -53
  211. data/spec/matchers.rb +8 -7
  212. data/spec/mocks.rb +1 -6
  213. data/spec/spec_helper.rb +0 -1
  214. metadata +7 -24
  215. data/acceptance/tests/base/dsl/helpers/host_helpers/deploy_package_repo_test.rb +0 -142
  216. data/acceptance/tests/base/external_resources_test.rb +0 -31
  217. data/spec/beaker/host/mac_spec.rb +0 -113
@@ -16,47 +16,45 @@ module Unix::Pkg
16
16
  # even if the command didn't exist, so it'll return a 0 exit code in
17
17
  # either case. Instead we match for the phrase output when a match isn't
18
18
  # found: "no #{name} in $PATH", reversing it to match our API
19
- !( result.stdout.match(/^no\ #{name}\ in\ /) )
19
+ !(result.stdout.match(/^no\ #{name}\ in\ /))
20
20
  else
21
21
  result.exit_code == 0
22
22
  end
23
23
  end
24
24
 
25
25
  def check_for_package(name, opts = {})
26
- opts = {:accept_all_exit_codes => true}.merge(opts)
26
+ opts = { :accept_all_exit_codes => true }.merge(opts)
27
27
  case self['platform']
28
- when /sles-10/
29
- result = execute("zypper se -i --match-exact #{name}", opts) { |result| result }
30
- result.stdout.include?('No packages found') ? (return false) : (return result.exit_code == 0)
31
- when /opensuse|sles-/
32
- if !self[:sles_rpmkeys_nightly_pl_imported]
33
- # The `:sles_rpmkeys_nightly_pl_imported` key is only read here at this
34
- # time. It's just to make sure that we only do the key import once, &
35
- # isn't for setting or use outside of beaker.
36
- execute('rpmkeys --import http://nightlies.puppetlabs.com/07BB6C57', opts)
37
- self[:sles_rpmkeys_nightly_pl_imported] = true
38
- end
39
- result = execute("zypper --gpg-auto-import-keys se -i --match-exact #{name}", opts) { |result| result }
40
- when /el-4/
41
- @logger.debug("Package query not supported on rhel4")
42
- return false
43
- when /cisco|fedora|centos|redhat|eos|el-/
44
- result = execute("rpm -q #{name}", opts) { |result| result }
45
- when /ubuntu|debian|cumulus|huaweios/
46
- result = execute("dpkg -s #{name}", opts) { |result| result }
47
- when /solaris-11/
48
- result = execute("pkg info #{name}", opts) { |result| result }
49
- when /solaris-10/
50
- result = execute("pkginfo #{name}", opts) { |result| result }
51
- if result.exit_code == 1
52
- result = execute("pkginfo CSW#{name}", opts) { |result| result }
53
- end
54
- when /openbsd/
55
- result = execute("pkg_info #{name}", opts) { |result| result }
56
- when /archlinux/
57
- result = execute("pacman -Q #{name}", opts) { |result| result }
58
- else
59
- raise "Package #{name} cannot be queried on #{self}"
28
+ when /sles-10/
29
+ result = execute("zypper se -i --match-exact #{name}", opts) { |result| result }
30
+ result.stdout.include?('No packages found') ? (return false) : (return result.exit_code == 0)
31
+ when /opensuse|sles-/
32
+ if !self[:sles_rpmkeys_nightly_pl_imported]
33
+ # The `:sles_rpmkeys_nightly_pl_imported` key is only read here at this
34
+ # time. It's just to make sure that we only do the key import once, &
35
+ # isn't for setting or use outside of beaker.
36
+ execute('rpmkeys --import http://nightlies.puppetlabs.com/07BB6C57', opts)
37
+ self[:sles_rpmkeys_nightly_pl_imported] = true
38
+ end
39
+ result = execute("zypper --gpg-auto-import-keys se -i --match-exact #{name}", opts) { |result| result }
40
+ when /el-4/
41
+ @logger.debug("Package query not supported on rhel4")
42
+ return false
43
+ when /cisco|fedora|centos|redhat|eos|el-/
44
+ result = execute("rpm -q #{name}", opts) { |result| result }
45
+ when /ubuntu|debian|cumulus|huaweios/
46
+ result = execute("dpkg -s #{name}", opts) { |result| result }
47
+ when /solaris-11/
48
+ result = execute("pkg info #{name}", opts) { |result| result }
49
+ when /solaris-10/
50
+ result = execute("pkginfo #{name}", opts) { |result| result }
51
+ result = execute("pkginfo CSW#{name}", opts) { |result| result } if result.exit_code == 1
52
+ when /openbsd/
53
+ result = execute("pkg_info #{name}", opts) { |result| result }
54
+ when /archlinux/
55
+ result = execute("pacman -Q #{name}", opts) { |result| result }
56
+ else
57
+ raise "Package #{name} cannot be queried on #{self}"
60
58
  end
61
59
  result.exit_code == 0
62
60
  end
@@ -64,98 +62,91 @@ module Unix::Pkg
64
62
  # If apt has not been updated since the last repo deployment it is
65
63
  # updated. Otherwise this is a noop
66
64
  def update_apt_if_needed
67
- if /debian|ubuntu|cumulus|huaweios/.match?(self['platform'])
68
- if @apt_needs_update
69
- execute("apt-get update")
70
- @apt_needs_update = false
71
- end
72
- end
65
+ return unless /debian|ubuntu|cumulus|huaweios/.match?(self['platform'])
66
+ return unless @apt_needs_update
67
+
68
+ execute("apt-get update")
69
+ @apt_needs_update = false
73
70
  end
74
71
 
75
72
  # Arch Linux is a rolling release distribution. We need to ensure that it is up2date
76
73
  # Except for the kernel. An upgrade will purge the modules for the currently running kernel
77
74
  # Before upgrading packages, we need to ensure we've the latest keyring
78
75
  def update_pacman_if_needed
79
- if self['platform'].include?('archlinux')
80
- if @pacman_needs_update
81
- execute("pacman --sync --noconfirm --noprogressbar --refresh archlinux-keyring")
82
- execute("pacman --sync --noconfirm --noprogressbar --refresh --sysupgrade --ignore linux --ignore linux-docs --ignore linux-headers")
83
- @pacman_needs_update = false
84
- end
85
- end
76
+ return unless self['platform'].include?('archlinux')
77
+ return unless @pacman_needs_update
78
+
79
+ execute("pacman --sync --noconfirm --noprogressbar --refresh archlinux-keyring")
80
+ execute("pacman --sync --noconfirm --noprogressbar --refresh --sysupgrade --ignore linux --ignore linux-docs --ignore linux-headers")
81
+ @pacman_needs_update = false
86
82
  end
87
83
 
88
84
  def install_package(name, cmdline_args = '', version = nil, opts = {})
89
85
  case self['platform']
90
- when /opensuse|sles-/
91
- execute("zypper --non-interactive --gpg-auto-import-keys in #{name}", opts)
92
- when /el-4/
93
- @logger.debug("Package installation not supported on rhel4")
94
- when /fedora-(2[2-9]|3[0-9])/
95
- if version
96
- name = "#{name}-#{version}"
97
- end
98
- execute("dnf -y #{cmdline_args} install #{name}", opts)
99
- when /cisco|fedora|centos|redhat|eos|el-/
100
- if version
101
- name = "#{name}-#{version}"
102
- end
103
- execute("yum -y #{cmdline_args} install #{name}", opts)
104
- when /ubuntu|debian|cumulus|huaweios/
105
- if version
106
- name = "#{name}=#{version}"
107
- end
108
- update_apt_if_needed
109
- execute("apt-get install --force-yes #{cmdline_args} -y #{name}", opts)
110
- when /solaris-11/
111
- if opts[:acceptable_exit_codes]
112
- opts[:acceptable_exit_codes] << 4
113
- else
114
- opts[:acceptable_exit_codes] = [0, 4] unless opts[:accept_all_exit_codes]
115
- end
116
- execute("pkg #{cmdline_args} install #{name}", opts)
117
- when /solaris-10/
118
- if ! check_for_command('pkgutil')
119
- # https://www.opencsw.org/package/pkgutil/
120
- noask_text = self.noask_file_text
121
- noask_file = File.join(external_copy_base, 'noask')
122
- create_remote_file(self, noask_file, noask_text)
123
- execute("pkgadd -d http://get.opencsw.org/now -a #{noask_file} -n all", opts)
124
- execute('/opt/csw/bin/pkgutil -U', opts)
125
- execute('/opt/csw/bin/pkgutil -y -i pkgutil', opts)
126
- end
127
- execute("pkgutil -i -y #{cmdline_args} #{name}", opts)
128
- when /openbsd/
129
- begin
130
- execute("pkg_add -I #{cmdline_args} #{name}", opts) do |command|
131
- # Handles where there are multiple rubies, installs the latest one
132
- if command.stderr =~ /^Ambiguous: #{name} could be (.+)$/
133
- name = $1.chomp.split(' ').collect { |x|
134
- x =~ /-(\d[^-p]+)/
135
- [x, $1]
136
- }.select { |x|
137
- # Blacklist Ruby 2.2.0+ for the sake of Puppet 3.x
138
- Gem::Version.new(x[1]) < Gem::Version.new('2.2.0')
139
- }.sort { |a,b|
140
- Gem::Version.new(b[1]) <=> Gem::Version.new(a[1])
141
- }.collect { |x|
142
- x[0]
143
- }.first
144
- raise ArgumentException
145
- end
146
- # If the package advises symlinks to be created, do it
147
- command.stdout.split("\n").select { |x| /^\s+ln\s/.match?(x) }.each do |ln|
148
- execute(ln, opts)
149
- end
86
+ when /opensuse|sles-/
87
+ execute("zypper --non-interactive --gpg-auto-import-keys in #{name}", opts)
88
+ when /el-4/
89
+ @logger.debug("Package installation not supported on rhel4")
90
+ when /fedora-(2[2-9]|3[0-9])/
91
+ name = "#{name}-#{version}" if version
92
+ execute("dnf -y #{cmdline_args} install #{name}", opts)
93
+ when /cisco|fedora|centos|redhat|eos|el-/
94
+ name = "#{name}-#{version}" if version
95
+ execute("yum -y #{cmdline_args} install #{name}", opts)
96
+ when /ubuntu|debian|cumulus|huaweios/
97
+ name = "#{name}=#{version}" if version
98
+ update_apt_if_needed
99
+ execute("apt-get install --force-yes #{cmdline_args} -y #{name}", opts)
100
+ when /solaris-11/
101
+ if opts[:acceptable_exit_codes]
102
+ opts[:acceptable_exit_codes] << 4
103
+ else
104
+ opts[:acceptable_exit_codes] = [0, 4] unless opts[:accept_all_exit_codes]
105
+ end
106
+ execute("pkg #{cmdline_args} install #{name}", opts)
107
+ when /solaris-10/
108
+ if !check_for_command('pkgutil')
109
+ # https://www.opencsw.org/package/pkgutil/
110
+ noask_text = self.noask_file_text
111
+ noask_file = File.join(external_copy_base, 'noask')
112
+ create_remote_file(self, noask_file, noask_text)
113
+ execute("pkgadd -d http://get.opencsw.org/now -a #{noask_file} -n all", opts)
114
+ execute('/opt/csw/bin/pkgutil -U', opts)
115
+ execute('/opt/csw/bin/pkgutil -y -i pkgutil', opts)
116
+ end
117
+ execute("pkgutil -i -y #{cmdline_args} #{name}", opts)
118
+ when /openbsd/
119
+ begin
120
+ execute("pkg_add -I #{cmdline_args} #{name}", opts) do |command|
121
+ # Handles where there are multiple rubies, installs the latest one
122
+ if (match = /^Ambiguous: #{name} could be (.+)$/.match(command.stderr))
123
+ name = match[1].chomp.split(' ').collect do |x|
124
+ # FIXME: Ruby 3.2 compatibility?
125
+ x =~ /-(\d[^-p]+)/
126
+ [x, $1]
127
+ end.select do |x|
128
+ # Blacklist Ruby 2.2.0+ for the sake of Puppet 3.x
129
+ Gem::Version.new(x[1]) < Gem::Version.new('2.2.0')
130
+ end.sort do |a, b|
131
+ Gem::Version.new(b[1]) <=> Gem::Version.new(a[1])
132
+ end.collect do |x|
133
+ x[0]
134
+ end.first
135
+ raise ArgumentException
136
+ end
137
+ # If the package advises symlinks to be created, do it
138
+ command.stdout.split("\n").select { |x| /^\s+ln\s/.match?(x) }.each do |ln|
139
+ execute(ln, opts)
150
140
  end
151
- rescue
152
- retry
153
141
  end
154
- when /archlinux/
155
- update_pacman_if_needed
156
- execute("pacman -S --noconfirm #{cmdline_args} #{name}", opts)
157
- else
158
- raise "Package #{name} cannot be installed on #{self}"
142
+ rescue
143
+ retry
144
+ end
145
+ when /archlinux/
146
+ update_pacman_if_needed
147
+ execute("pacman -S --noconfirm #{cmdline_args} #{name}", opts)
148
+ else
149
+ raise "Package #{name} cannot be installed on #{self}"
159
150
  end
160
151
  end
161
152
 
@@ -171,34 +162,32 @@ module Unix::Pkg
171
162
  # @api public
172
163
  def install_package_with_rpm(name, cmdline_args = '', opts = {})
173
164
  proxy = ''
174
- if name&.start_with?('http') and opts[:package_proxy]
175
- proxy = extract_rpm_proxy_options(opts[:package_proxy])
176
- end
165
+ proxy = extract_rpm_proxy_options(opts[:package_proxy]) if name&.start_with?('http') and opts[:package_proxy]
177
166
  execute("rpm #{cmdline_args} -Uvh #{name} #{proxy}")
178
167
  end
179
168
 
180
169
  def uninstall_package(name, cmdline_args = '', opts = {})
181
170
  case self['platform']
182
- when /opensuse|sles-/
183
- execute("zypper --non-interactive rm #{name}", opts)
184
- when /el-4/
185
- @logger.debug("Package uninstallation not supported on rhel4")
186
- when /edora-(2[2-9]|3[0-9])/
187
- execute("dnf -y #{cmdline_args} remove #{name}", opts)
188
- when /cisco|fedora|centos|redhat|eos|el-/
189
- execute("yum -y #{cmdline_args} remove #{name}", opts)
190
- when /ubuntu|debian|cumulus|huaweios/
191
- execute("apt-get purge #{cmdline_args} -y #{name}", opts)
192
- when /solaris-11/
193
- execute("pkg #{cmdline_args} uninstall #{name}", opts)
194
- when /solaris-10/
195
- execute("pkgrm -n #{cmdline_args} #{name}", opts)
196
- when /aix/
197
- execute("rpm #{cmdline_args} -e #{name}", opts)
198
- when /archlinux/
199
- execute("pacman -R --noconfirm #{cmdline_args} #{name}", opts)
200
- else
201
- raise "Package #{name} cannot be installed on #{self}"
171
+ when /opensuse|sles-/
172
+ execute("zypper --non-interactive rm #{name}", opts)
173
+ when /el-4/
174
+ @logger.debug("Package uninstallation not supported on rhel4")
175
+ when /edora-(2[2-9]|3[0-9])/
176
+ execute("dnf -y #{cmdline_args} remove #{name}", opts)
177
+ when /cisco|fedora|centos|redhat|eos|el-/
178
+ execute("yum -y #{cmdline_args} remove #{name}", opts)
179
+ when /ubuntu|debian|cumulus|huaweios/
180
+ execute("apt-get purge #{cmdline_args} -y #{name}", opts)
181
+ when /solaris-11/
182
+ execute("pkg #{cmdline_args} uninstall #{name}", opts)
183
+ when /solaris-10/
184
+ execute("pkgrm -n #{cmdline_args} #{name}", opts)
185
+ when /aix/
186
+ execute("rpm #{cmdline_args} -e #{name}", opts)
187
+ when /archlinux/
188
+ execute("pacman -R --noconfirm #{cmdline_args} #{name}", opts)
189
+ else
190
+ raise "Package #{name} cannot be installed on #{self}"
202
191
  end
203
192
  end
204
193
 
@@ -209,115 +198,37 @@ module Unix::Pkg
209
198
  # the package manager
210
199
  def upgrade_package(name, cmdline_args = '', opts = {})
211
200
  case self['platform']
212
- when /opensuse|sles-/
213
- execute("zypper --non-interactive --no-gpg-checks up #{name}", opts)
214
- when /el-4/
215
- @logger.debug("Package upgrade is not supported on rhel4")
216
- when /fedora-(2[2-9]|3[0-9])/
217
- execute("dnf -y #{cmdline_args} update #{name}", opts)
218
- when /cisco|fedora|centos|redhat|eos|el-/
219
- execute("yum -y #{cmdline_args} update #{name}", opts)
220
- when /ubuntu|debian|cumulus|huaweios/
221
- update_apt_if_needed
222
- execute("apt-get install -o Dpkg::Options::='--force-confold' #{cmdline_args} -y --force-yes #{name}", opts)
223
- when /solaris-11/
224
- if opts[:acceptable_exit_codes]
225
- opts[:acceptable_exit_codes] << 4
226
- else
227
- opts[:acceptable_exit_codes] = [0, 4] unless opts[:accept_all_exit_codes]
228
- end
229
- execute("pkg #{cmdline_args} update #{name}", opts)
230
- when /solaris-10/
231
- execute("pkgutil -u -y #{cmdline_args} #{name}", opts)
201
+ when /opensuse|sles-/
202
+ execute("zypper --non-interactive --no-gpg-checks up #{name}", opts)
203
+ when /el-4/
204
+ @logger.debug("Package upgrade is not supported on rhel4")
205
+ when /fedora-(2[2-9]|3[0-9])/
206
+ execute("dnf -y #{cmdline_args} update #{name}", opts)
207
+ when /cisco|fedora|centos|redhat|eos|el-/
208
+ execute("yum -y #{cmdline_args} update #{name}", opts)
209
+ when /ubuntu|debian|cumulus|huaweios/
210
+ update_apt_if_needed
211
+ execute("apt-get install -o Dpkg::Options::='--force-confold' #{cmdline_args} -y --force-yes #{name}", opts)
212
+ when /solaris-11/
213
+ if opts[:acceptable_exit_codes]
214
+ opts[:acceptable_exit_codes] << 4
232
215
  else
233
- raise "Package #{name} cannot be upgraded on #{self}"
234
- end
235
- end
236
-
237
- # Deploy apt configuration generated by the packaging tooling
238
- #
239
- # @note Due to the debian use of codenames in repos, the
240
- # DEBIAN_PLATFORM_CODENAMES map must be kept up-to-date as
241
- # support for new versions is added.
242
- #
243
- # @note See {Beaker::DSL::Helpers::HostHelpers#deploy_package_repo} for info on
244
- # params
245
- # @deprecated no longer used in beaker, beaker-puppet, or beaker-pe
246
- # @visibility private
247
- def deploy_apt_repo(path, name, version)
248
- codename = self['platform'].codename
249
-
250
- if codename.nil?
251
- @logger.warn "Could not determine codename for debian platform #{self['platform']}. Skipping deployment of repo #{name}"
252
- return
253
- end
254
-
255
- repo_file = "#{path}/deb/pl-#{name}-#{version}-#{codename}.list"
256
- do_scp_to repo_file, "/etc/apt/sources.list.d/#{name}.list", {}
257
- @apt_needs_update = true
258
- end
259
-
260
- # Deploy yum configuration generated by the packaging tooling
261
- #
262
- # @note See {Beaker::DSL::Helpers::HostHelpers#deploy_package_repo} for info on
263
- # params
264
- # @deprecated no longer used in beaker, beaker-puppet, or beaker-pe
265
- # @visibility private
266
- def deploy_yum_repo(path, name, version)
267
- repo_file = "#{path}/rpm/pl-#{name}-#{version}-repos-pe-#{self['platform']}.repo"
268
- do_scp_to repo_file, "/etc/yum.repos.d/#{name}.repo", {}
269
- end
270
-
271
- # Deploy zypper repo configuration generated by the packaging tooling
272
- #
273
- # @note See {Beaker::DSL::Helpers::HostHelpers#deploy_package_repo} for info on
274
- # params
275
- # @deprecated no longer used in beaker, beaker-puppet, or beaker-pe
276
- # @visibility private
277
- def deploy_zyp_repo(path, name, version)
278
- repo_file = "#{path}/rpm/pl-#{name}-#{version}-repos-pe-#{self['platform']}.repo"
279
- repo = IniFile.load(repo_file)
280
- repo_name = repo.sections[0]
281
- repo_url = repo[repo_name]["baseurl"]
282
- execute("zypper ar -t YUM #{repo_url} #{repo_name}")
283
- end
284
-
285
- # Deploy configuration generated by the packaging tooling to this host.
286
- #
287
- # This method calls one of #deploy_apt_repo, #deploy_yum_repo, or
288
- # #deploy_zyp_repo depending on the platform of this Host.
289
- #
290
- # @note See {Beaker::DSL::Helpers::HostHelpers#deploy_package_repo} for info on
291
- # params
292
- # @deprecated no longer used in beaker, beaker-puppet, or beaker-pe
293
- # @visibility private
294
- def deploy_package_repo(path, name, version)
295
- if not File.exist? path
296
- @logger.warn "Was asked to deploy package repository from #{path}, but it doesn't exist!"
297
- return
298
- end
299
-
300
- case self['platform']
301
- when /el-4/
302
- @logger.debug("Package repo deploy is not supported on rhel4")
303
- when /fedora|centos|redhat|eos|el-/
304
- deploy_yum_repo(path, name, version)
305
- when /ubuntu|debian|cumulus|huaweios/
306
- deploy_apt_repo(path, name, version)
307
- when /opensuse|sles/
308
- deploy_zyp_repo(path, name, version)
309
- else
310
- # solaris, windows
311
- raise "Package repo cannot be deployed on #{self}; the platform is not supported"
216
+ opts[:acceptable_exit_codes] = [0, 4] unless opts[:accept_all_exit_codes]
217
+ end
218
+ execute("pkg #{cmdline_args} update #{name}", opts)
219
+ when /solaris-10/
220
+ execute("pkgutil -u -y #{cmdline_args} #{name}", opts)
221
+ else
222
+ raise "Package #{name} cannot be upgraded on #{self}"
312
223
  end
313
224
  end
314
225
 
315
- #Examine the host system to determine the architecture
316
- #@return [Boolean] true if x86_64, false otherwise
226
+ # Examine the host system to determine the architecture
227
+ # @return [Boolean] true if x86_64, false otherwise
317
228
  def determine_if_x86_64
318
229
  if self[:platform].include?('solaris')
319
230
  result = exec(Beaker::Command.new("uname -a | grep x86_64"), :accept_all_exit_codes => true)
320
- result.exit_code == 0
231
+ result.exit_code == 0
321
232
  else
322
233
  result = exec(Beaker::Command.new("arch | grep x86_64"), :accept_all_exit_codes => true)
323
234
  result.exit_code == 0
@@ -334,189 +245,15 @@ module Unix::Pkg
334
245
  # @api private
335
246
  def extract_rpm_proxy_options(url)
336
247
  begin
337
- host, port = url.match(/https?:\/\/(.*):(\d*)/)[1,2]
248
+ host, port = url.match(/https?:\/\/(.*):(\d*)/)[1, 2]
338
249
  raise if host.empty? or port.empty?
250
+
339
251
  "--httpproxy #{host} --httpport #{port}"
340
252
  rescue
341
253
  raise "Cannot extract host and port from '#{url}'"
342
254
  end
343
255
  end
344
256
 
345
- # Gets the path & file name for the puppet agent dev package on Unix
346
- #
347
- # @param [String] puppet_collection Name of the puppet collection to use
348
- # @param [String] puppet_agent_version Version of puppet agent to get
349
- # @param [Hash{Symbol=>String}] opts Options hash to provide extra values
350
- #
351
- # @note Solaris does require :download_url to be set on the opts argument
352
- # in order to check for builds on the builds server
353
- #
354
- # @raise [ArgumentError] If one of the two required parameters (puppet_collection,
355
- # puppet_agent_version) is either not passed or set to nil
356
- #
357
- # @return [String, String] Path to the directory and filename of the package, respectively
358
- def solaris_puppet_agent_dev_package_info( puppet_collection = nil, puppet_agent_version = nil, opts = {} )
359
- error_message = "Must provide %s argument to get puppet agent package information"
360
- raise ArgumentError, error_message % "puppet_collection" unless puppet_collection
361
- raise ArgumentError, error_message % "puppet_agent_version" unless puppet_agent_version
362
- raise ArgumentError, error_message % "opts[:download_url]" unless opts[:download_url]
363
-
364
- variant, version, arch, _codename = self['platform'].to_array
365
-
366
- version = version.split('.')[0] # packages are only published for major versions
367
-
368
- platform_error = "Incorrect platform '#{variant}' for #solaris_puppet_agent_dev_package_info"
369
- raise ArgumentError, platform_error if variant != 'solaris'
370
-
371
- if arch == 'x86_64'
372
- arch = 'i386'
373
- end
374
- release_path_end = "solaris/#{version}/#{puppet_collection}"
375
- solaris_revision_conjunction = '-'
376
- revision = '1'
377
- if version == '10'
378
- solaris_release_version = ''
379
- pkg_suffix = 'pkg.gz'
380
- solaris_name_conjunction = '-'
381
- component_version = puppet_agent_version
382
- elsif version == '11'
383
- # Ref:
384
- # http://www.oracle.com/technetwork/articles/servers-storage-admin/ips-package-versioning-2232906.html
385
- #
386
- # Example to show package name components:
387
- # Full package name: puppet-agent@1.2.5.38.6813,5.11-1.sparc.p5p
388
- # Schema: <component-name><solaris_name_conjunction><component_version><solaris_release_version><solaris_revision_conjunction><revision>.<arch>.<pkg_suffix>
389
- solaris_release_version = ',5.11' # injecting comma to prevent from adding another var
390
- pkg_suffix = 'p5p'
391
- solaris_name_conjunction = '@'
392
- component_version = puppet_agent_version.dup
393
- component_version.gsub!(/[a-zA-Z]/, '')
394
- component_version.gsub!(/(^-)|(-$)/, '')
395
- # Here we strip leading 0 from version components but leave
396
- # singular 0 on their own.
397
- component_version = component_version.split('-').join('.')
398
- component_version = component_version.split('.').map(&:to_i).join('.')
399
- end
400
- release_file_base = "puppet-agent#{solaris_name_conjunction}#{component_version}#{solaris_release_version}"
401
- release_file_end = "#{arch}.#{pkg_suffix}"
402
- release_file = "#{release_file_base}#{solaris_revision_conjunction}#{revision}.#{release_file_end}"
403
- if not link_exists?("#{opts[:download_url]}/#{release_path_end}/#{release_file}")
404
- release_file = "#{release_file_base}.#{release_file_end}"
405
- end
406
- return release_path_end, release_file
407
- end
408
-
409
- # Gets the path & file name for the puppet agent dev package on Unix
410
- #
411
- # @param [String] puppet_collection Name of the puppet collection to use
412
- # @param [String] puppet_agent_version Version of puppet agent to get
413
- # @param [Hash{Symbol=>String}] opts Options hash to provide extra values
414
- #
415
- # @note Solaris & OSX do require some options to be set. See
416
- # {#solaris_puppet_agent_dev_package_info} &
417
- # {Mac::Pkg#puppet_agent_dev_package_info} for more details
418
- #
419
- # @raise [ArgumentError] If one of the two required parameters (puppet_collection,
420
- # puppet_agent_version) is either not passed or set to nil
421
- #
422
- # @return [String, String] Path to the directory and filename of the package, respectively
423
- def puppet_agent_dev_package_info( puppet_collection = nil, puppet_agent_version = nil, opts = {} )
424
- error_message = "Must provide %s argument to get puppet agent dev package information"
425
- raise ArgumentError, error_message % "puppet_collection" unless puppet_collection
426
- raise ArgumentError, error_message % "puppet_agent_version" unless puppet_agent_version
427
-
428
- variant, version, arch, _codename = self['platform'].to_array
429
-
430
- case variant
431
- when /^(solaris)$/
432
- release_path_end, release_file = solaris_puppet_agent_dev_package_info(
433
- puppet_collection, puppet_agent_version, opts )
434
- when /^(opensuse|sles|aix|el|centos|oracle|redhat|scientific)$/
435
- variant = 'el' if variant.match?(/(?:el|centos|oracle|redhat|scientific)/)
436
- variant = 'sles' if variant == 'opensuse'
437
-
438
- if variant == 'aix'
439
- arch = 'ppc' if arch == 'power'
440
- version_x, version_y = /^(\d+)\.(\d+)/.match(puppet_agent_version).captures.map(&:to_i)
441
- if version_x < 5 || version_x == 5 && version_y < 99 # 5.99.z indicates pre-release puppet6
442
- version = '7.1' if version == '7.2'
443
- else
444
- version = '6.1'
445
- end
446
- end
447
- release_path_end = "#{variant}/#{version}/#{puppet_collection}/#{arch}"
448
- release_file = "puppet-agent-#{puppet_agent_version}-1.#{variant}#{version}.#{arch}.rpm"
449
- else
450
- msg = "puppet_agent dev package info unknown for platform '#{self['platform']}'"
451
- raise ArgumentError, msg
452
- end
453
- return release_path_end, release_file
454
- end
455
-
456
- # Gets host-specific information for PE promoted puppet-agent packages
457
- #
458
- # @param [String] puppet_collection Name of the puppet collection to use
459
- # @param [Hash{Symbol=>String}] opts Options hash to provide extra values
460
- #
461
- # @return [String, String, String] Host-specific information for packages
462
- # 1. release_path_end Suffix for the release_path. Used on Windows. Check
463
- # {Windows::Pkg#pe_puppet_agent_promoted_package_info} to see usage.
464
- # 2. release_file Path to the file on release build servers
465
- # 3. download_file Filename for the package itself
466
- def pe_puppet_agent_promoted_package_info( puppet_collection = nil, _opts = {} )
467
- error_message = "Must provide %s argument to get puppet agent dev package information"
468
- raise ArgumentError, error_message % "puppet_collection" unless puppet_collection
469
-
470
- variant, version, arch, codename = self['platform'].to_array
471
- case variant
472
- when /^(fedora|el|centos|redhat|opensuse|sles)$/
473
- variant = ((['centos', 'redhat'].include?(variant)) ? 'el' : variant)
474
- release_file = "/repos/#{variant}/#{version}/#{puppet_collection}/#{arch}/puppet-agent-*.rpm"
475
- download_file = "puppet-agent-#{variant}-#{version}-#{arch}.tar.gz"
476
- when /^(debian|ubuntu|cumulus)$/
477
- if arch == 'x86_64'
478
- arch = 'amd64'
479
- end
480
- version = version[0,2] + '.' + version[2,2] if (variant.include?('ubuntu') && !version.include?("."))
481
- release_file = "/repos/apt/#{codename}/pool/#{puppet_collection}/p/puppet-agent/puppet-agent*#{arch}.deb"
482
- download_file = "puppet-agent-#{variant}-#{version}-#{arch}.tar.gz"
483
- when /^solaris$/
484
- if arch == 'x86_64'
485
- arch = 'i386'
486
- end
487
- release_file = "/repos/solaris/#{version}/#{puppet_collection}/"
488
- download_file = "puppet-agent-#{variant}-#{version}-#{arch}.tar.gz"
489
- else
490
- raise "No pe-promoted installation step for #{variant} yet..."
491
- end
492
- return '', release_file, download_file
493
- end
494
-
495
- # Installs a given PE promoted package on a host
496
- #
497
- # @param [String] onhost_copy_base Base copy directory on the host
498
- # @param [String] onhost_copied_download Downloaded file path on the host
499
- # @param [String] onhost_copied_file Copied file path once un-compressed
500
- # @param [String] download_file File name of the downloaded file
501
- # @param [Hash{Symbol=>String}] opts additional options
502
- #
503
- # @return nil
504
- def pe_puppet_agent_promoted_package_install(
505
- onhost_copy_base, onhost_copied_download, onhost_copied_file, download_file, _opts
506
- )
507
- uncompress_local_tarball( onhost_copied_download, onhost_copy_base, download_file )
508
- if /^solaris/.match?(self['platform'])
509
- # above uncompresses the install from .tar.gz -> .p5p into the
510
- # onhost_copied_file directory w/a weird name. We have to read that file
511
- # name from the filesystem, so that we can provide it to install_local...
512
- pkg_filename = execute( "ls #{onhost_copied_file}" )
513
- onhost_copied_file = "#{onhost_copied_file}#{pkg_filename}"
514
- end
515
-
516
- install_local_package( onhost_copied_file, onhost_copy_base )
517
- nil
518
- end
519
-
520
257
  # Installs a package already located on a SUT
521
258
  #
522
259
  # @param [String] onhost_package_file Path to the package file to install
@@ -537,9 +274,9 @@ module Unix::Pkg
537
274
  execute("dpkg -i --force-all #{onhost_package_file}")
538
275
  execute("apt-get update")
539
276
  when /^solaris$/
540
- self.solaris_install_local_package( onhost_package_file, onhost_copy_dir )
277
+ self.solaris_install_local_package(onhost_package_file, onhost_copy_dir)
541
278
  when /^osx$/
542
- install_package( onhost_package_file )
279
+ install_package(onhost_package_file)
543
280
  else
544
281
  msg = "Platform #{variant} is not supported by the method "
545
282
  msg << 'install_local_package'