beaker 4.41.2 → 5.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (218) 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 +16 -52
  8. data/Gemfile +12 -7
  9. data/HISTORY.md +605 -0
  10. data/Rakefile +99 -111
  11. data/acceptance/config/acceptance-options.rb +1 -1
  12. data/acceptance/config/base/acceptance-options.rb +2 -2
  13. data/acceptance/config/hypervisor/acceptance-options.rb +2 -2
  14. data/acceptance/config/subcommands/acceptance-options.rb +2 -2
  15. data/acceptance/fixtures/module/Rakefile +1 -1
  16. data/acceptance/fixtures/module/spec/acceptance/demo_spec.rb +8 -12
  17. data/acceptance/fixtures/module/spec/classes/init_spec.rb +0 -1
  18. data/acceptance/fixtures/module/spec/spec_helper_acceptance.rb +3 -5
  19. data/acceptance/lib/helpers/test_helper.rb +6 -5
  20. data/acceptance/pre_suite/subcommands/05_install_ruby.rb +2 -3
  21. data/acceptance/pre_suite/subcommands/08_install_beaker.rb +1 -2
  22. data/acceptance/tests/base/dsl/helpers/configuration_test.rb +4 -4
  23. data/acceptance/tests/base/dsl/helpers/hocon_helpers_test.rb +1 -2
  24. data/acceptance/tests/base/dsl/helpers/host_helpers/add_system32_hosts_entry_test.rb +0 -3
  25. data/acceptance/tests/base/dsl/helpers/host_helpers/archive_file_from_test.rb +3 -1
  26. data/acceptance/tests/base/dsl/helpers/host_helpers/backup_the_file_test.rb +9 -9
  27. data/acceptance/tests/base/dsl/helpers/host_helpers/check_for_package_test.rb +0 -4
  28. data/acceptance/tests/base/dsl/helpers/host_helpers/create_remote_file_test.rb +19 -26
  29. data/acceptance/tests/base/dsl/helpers/host_helpers/curl_on_test.rb +2 -2
  30. data/acceptance/tests/base/dsl/helpers/host_helpers/curl_with_retries_test.rb +0 -1
  31. data/acceptance/tests/base/dsl/helpers/host_helpers/on_test.rb +18 -13
  32. data/acceptance/tests/base/dsl/helpers/host_helpers/retry_on_test.rb +3 -3
  33. data/acceptance/tests/base/dsl/helpers/host_helpers/rsync_to_test.rb +22 -27
  34. data/acceptance/tests/base/dsl/helpers/host_helpers/run_cron_on_test.rb +12 -16
  35. data/acceptance/tests/base/dsl/helpers/host_helpers/run_script_on_test.rb +3 -4
  36. data/acceptance/tests/base/dsl/helpers/host_helpers/run_script_test.rb +3 -3
  37. data/acceptance/tests/base/dsl/helpers/host_helpers/scp_from_test.rb +4 -4
  38. data/acceptance/tests/base/dsl/helpers/host_helpers/scp_to_test.rb +3 -4
  39. data/acceptance/tests/base/dsl/helpers/host_helpers/shell_test.rb +5 -5
  40. data/acceptance/tests/base/dsl/helpers/host_helpers/upgrade_package_test.rb +3 -5
  41. data/acceptance/tests/base/dsl/platform_tag_confiner_test.rb +14 -17
  42. data/acceptance/tests/base/dsl/structure_test.rb +5 -11
  43. data/acceptance/tests/base/host/file_test.rb +2 -2
  44. data/acceptance/tests/base/host/group_test.rb +0 -1
  45. data/acceptance/tests/base/host/host_test.rb +66 -63
  46. data/acceptance/tests/base/host/packages.rb +1 -2
  47. data/acceptance/tests/base/host/packages_unix.rb +0 -55
  48. data/acceptance/tests/base/host/user_test.rb +0 -1
  49. data/acceptance/tests/base/host_prebuilt_steps/ssh_environment_test.rb +1 -2
  50. data/acceptance/tests/base/test_suite/export.rb +6 -9
  51. data/acceptance/tests/install/from_file.rb +2 -4
  52. data/acceptance/tests/load_path_bootstrap.rb +1 -1
  53. data/acceptance/tests/subcommands/destroy.rb +19 -21
  54. data/acceptance/tests/subcommands/exec.rb +0 -1
  55. data/acceptance/tests/subcommands/init.rb +2 -3
  56. data/acceptance/tests/subcommands/provision.rb +0 -1
  57. data/beaker.gemspec +4 -7
  58. data/docs/concepts/argument_processing_and_precedence.md +1 -10
  59. data/docs/how_to/debug_beaker_tests.md +12 -12
  60. data/docs/how_to/hosts/eos.md +2 -12
  61. data/docs/how_to/install_puppet.md +0 -18
  62. data/docs/how_to/the_beaker_dsl.md +0 -2
  63. data/lib/beaker/cli.rb +59 -68
  64. data/lib/beaker/command.rb +20 -28
  65. data/lib/beaker/command_factory.rb +3 -2
  66. data/lib/beaker/dsl/assertions.rb +6 -18
  67. data/lib/beaker/dsl/helpers/hocon_helpers.rb +3 -7
  68. data/lib/beaker/dsl/helpers/host_helpers.rb +62 -123
  69. data/lib/beaker/dsl/helpers/test_helpers.rb +3 -5
  70. data/lib/beaker/dsl/helpers/web_helpers.rb +19 -39
  71. data/lib/beaker/dsl/helpers.rb +2 -4
  72. data/lib/beaker/dsl/outcomes.rb +13 -15
  73. data/lib/beaker/dsl/patterns.rb +1 -3
  74. data/lib/beaker/dsl/roles.rb +17 -20
  75. data/lib/beaker/dsl/structure.rb +53 -65
  76. data/lib/beaker/dsl/test_tagging.rb +7 -10
  77. data/lib/beaker/dsl/wrappers.rb +15 -16
  78. data/lib/beaker/dsl.rb +2 -3
  79. data/lib/beaker/host/aix/exec.rb +1 -1
  80. data/lib/beaker/host/aix/file.rb +0 -1
  81. data/lib/beaker/host/aix/group.rb +1 -1
  82. data/lib/beaker/host/aix/user.rb +1 -1
  83. data/lib/beaker/host/aix.rb +3 -4
  84. data/lib/beaker/host/cisco.rb +27 -39
  85. data/lib/beaker/host/eos.rb +4 -30
  86. data/lib/beaker/host/freebsd/exec.rb +1 -1
  87. data/lib/beaker/host/freebsd/pkg.rb +3 -3
  88. data/lib/beaker/host/freebsd.rb +9 -12
  89. data/lib/beaker/host/mac/exec.rb +4 -4
  90. data/lib/beaker/host/mac/group.rb +7 -7
  91. data/lib/beaker/host/mac/pkg.rb +3 -106
  92. data/lib/beaker/host/mac/user.rb +2 -2
  93. data/lib/beaker/host/mac.rb +8 -9
  94. data/lib/beaker/host/pswindows/exec.rb +66 -70
  95. data/lib/beaker/host/pswindows/file.rb +3 -5
  96. data/lib/beaker/host/pswindows/group.rb +3 -3
  97. data/lib/beaker/host/pswindows/pkg.rb +12 -12
  98. data/lib/beaker/host/pswindows/user.rb +3 -3
  99. data/lib/beaker/host/pswindows.rb +4 -3
  100. data/lib/beaker/host/unix/exec.rb +81 -83
  101. data/lib/beaker/host/unix/file.rb +40 -45
  102. data/lib/beaker/host/unix/group.rb +1 -1
  103. data/lib/beaker/host/unix/pkg.rb +138 -401
  104. data/lib/beaker/host/unix/user.rb +2 -2
  105. data/lib/beaker/host/unix.rb +8 -11
  106. data/lib/beaker/host/windows/exec.rb +17 -17
  107. data/lib/beaker/host/windows/file.rb +3 -3
  108. data/lib/beaker/host/windows/group.rb +3 -3
  109. data/lib/beaker/host/windows/pkg.rb +3 -54
  110. data/lib/beaker/host/windows/user.rb +3 -3
  111. data/lib/beaker/host/windows.rb +12 -12
  112. data/lib/beaker/host.rb +76 -133
  113. data/lib/beaker/host_prebuilt_steps.rb +88 -196
  114. data/lib/beaker/hypervisor/noop.rb +2 -4
  115. data/lib/beaker/hypervisor.rb +44 -61
  116. data/lib/beaker/local_connection.rb +2 -4
  117. data/lib/beaker/logger.rb +68 -76
  118. data/lib/beaker/logger_junit.rb +21 -25
  119. data/lib/beaker/network_manager.rb +39 -42
  120. data/lib/beaker/options/command_line_parser.rb +12 -23
  121. data/lib/beaker/options/hosts_file_parser.rb +16 -25
  122. data/lib/beaker/options/options_file_parser.rb +3 -6
  123. data/lib/beaker/options/options_hash.rb +2 -7
  124. data/lib/beaker/options/parser.rb +86 -102
  125. data/lib/beaker/options/presets.rb +114 -123
  126. data/lib/beaker/options/subcommand_options_file_parser.rb +3 -6
  127. data/lib/beaker/options/validator.rb +26 -31
  128. data/lib/beaker/perf.rb +25 -30
  129. data/lib/beaker/platform.rb +26 -37
  130. data/lib/beaker/result.rb +7 -6
  131. data/lib/beaker/shared/error_handler.rb +8 -10
  132. data/lib/beaker/shared/fog_credentials.rb +5 -9
  133. data/lib/beaker/shared/host_manager.rb +36 -41
  134. data/lib/beaker/shared/options_resolver.rb +3 -7
  135. data/lib/beaker/shared/repetition.rb +2 -4
  136. data/lib/beaker/shared/semvar.rb +37 -41
  137. data/lib/beaker/shared/timed.rb +0 -3
  138. data/lib/beaker/shared.rb +1 -1
  139. data/lib/beaker/ssh_connection.rb +38 -47
  140. data/lib/beaker/subcommand.rb +17 -24
  141. data/lib/beaker/subcommands/subcommand_util.rb +4 -4
  142. data/lib/beaker/tasks/quick_start.rb +4 -9
  143. data/lib/beaker/tasks/rake_task.rb +25 -27
  144. data/lib/beaker/tasks/test.rb +4 -4
  145. data/lib/beaker/test_case.rb +16 -28
  146. data/lib/beaker/test_suite.rb +35 -39
  147. data/lib/beaker/test_suite_result.rb +45 -47
  148. data/lib/beaker/version.rb +1 -1
  149. data/lib/beaker.rb +6 -7
  150. data/spec/beaker/cli_spec.rb +121 -142
  151. data/spec/beaker/command_spec.rb +55 -59
  152. data/spec/beaker/dsl/assertions_spec.rb +36 -36
  153. data/spec/beaker/dsl/helpers/host_helpers_spec.rb +110 -131
  154. data/spec/beaker/dsl/helpers/test_helpers_spec.rb +9 -10
  155. data/spec/beaker/dsl/helpers/web_helpers_spec.rb +22 -31
  156. data/spec/beaker/dsl/outcomes_spec.rb +14 -14
  157. data/spec/beaker/dsl/roles_spec.rb +125 -130
  158. data/spec/beaker/dsl/structure_spec.rb +172 -161
  159. data/spec/beaker/dsl/test_tagging_spec.rb +89 -90
  160. data/spec/beaker/dsl/wrappers_spec.rb +32 -33
  161. data/spec/beaker/host/aix_spec.rb +14 -14
  162. data/spec/beaker/host/cisco_spec.rb +84 -94
  163. data/spec/beaker/host/eos_spec.rb +15 -36
  164. data/spec/beaker/host/freebsd/exec_spec.rb +3 -6
  165. data/spec/beaker/host/freebsd/pkg_spec.rb +24 -27
  166. data/spec/beaker/host/mac/exec_spec.rb +2 -3
  167. data/spec/beaker/host/mac/group_spec.rb +48 -57
  168. data/spec/beaker/host/mac/user_spec.rb +54 -63
  169. data/spec/beaker/host/pswindows/exec_spec.rb +30 -32
  170. data/spec/beaker/host/pswindows/file_spec.rb +16 -16
  171. data/spec/beaker/host/pswindows/user_spec.rb +17 -23
  172. data/spec/beaker/host/pswindows_spec.rb +13 -13
  173. data/spec/beaker/host/unix/exec_spec.rb +75 -80
  174. data/spec/beaker/host/unix/file_spec.rb +66 -71
  175. data/spec/beaker/host/unix/pkg_spec.rb +150 -411
  176. data/spec/beaker/host/unix_spec.rb +11 -207
  177. data/spec/beaker/host/windows/exec_spec.rb +30 -32
  178. data/spec/beaker/host/windows/file_spec.rb +18 -19
  179. data/spec/beaker/host/windows/group_spec.rb +10 -12
  180. data/spec/beaker/host/windows/pkg_spec.rb +6 -9
  181. data/spec/beaker/host/windows/user_spec.rb +17 -23
  182. data/spec/beaker/host/windows_spec.rb +39 -39
  183. data/spec/beaker/host_prebuilt_steps_spec.rb +168 -349
  184. data/spec/beaker/host_spec.rb +204 -284
  185. data/spec/beaker/hypervisor/hypervisor_spec.rb +36 -61
  186. data/spec/beaker/localhost_connection_spec.rb +10 -11
  187. data/spec/beaker/logger_junit_spec.rb +19 -30
  188. data/spec/beaker/logger_spec.rb +153 -136
  189. data/spec/beaker/network_manager_spec.rb +23 -23
  190. data/spec/beaker/options/command_line_parser_spec.rb +20 -23
  191. data/spec/beaker/options/hosts_file_parser_spec.rb +30 -32
  192. data/spec/beaker/options/options_file_parser_spec.rb +4 -7
  193. data/spec/beaker/options/options_hash_spec.rb +4 -6
  194. data/spec/beaker/options/parser_spec.rb +167 -167
  195. data/spec/beaker/options/presets_spec.rb +7 -9
  196. data/spec/beaker/options/subcommand_options_parser_spec.rb +13 -14
  197. data/spec/beaker/options/validator_spec.rb +10 -11
  198. data/spec/beaker/perf_spec.rb +18 -21
  199. data/spec/beaker/platform_spec.rb +25 -50
  200. data/spec/beaker/shared/error_handler_spec.rb +7 -16
  201. data/spec/beaker/shared/fog_credentials_spec.rb +29 -29
  202. data/spec/beaker/shared/host_manager_spec.rb +50 -84
  203. data/spec/beaker/shared/options_resolver_spec.rb +9 -12
  204. data/spec/beaker/shared/repetition_spec.rb +17 -24
  205. data/spec/beaker/shared/semvar_spec.rb +21 -26
  206. data/spec/beaker/ssh_connection_spec.rb +76 -83
  207. data/spec/beaker/subcommand/subcommand_util_spec.rb +31 -33
  208. data/spec/beaker/subcommand_spec.rb +75 -77
  209. data/spec/beaker/test_case_spec.rb +25 -50
  210. data/spec/beaker/test_suite_spec.rb +147 -154
  211. data/spec/helpers.rb +39 -45
  212. data/spec/matchers.rb +8 -7
  213. data/spec/mocks.rb +1 -6
  214. data/spec/spec_helper.rb +0 -1
  215. metadata +8 -24
  216. data/acceptance/tests/base/dsl/helpers/host_helpers/deploy_package_repo_test.rb +0 -142
  217. data/acceptance/tests/base/external_resources_test.rb +0 -31
  218. data/spec/beaker/host/mac_spec.rb +0 -113
@@ -1,42 +1,37 @@
1
- require 'pathname'
2
-
3
- [ 'command', "dsl" ].each do |lib|
1
+ %w[command dsl].each do |lib|
4
2
  require "beaker/#{lib}"
5
3
  end
6
4
 
7
5
  module Beaker
8
- #Provides convienience methods for commonly run actions on hosts
6
+ # Provides convienience methods for commonly run actions on hosts
9
7
  module HostPrebuiltSteps
10
8
  include Beaker::DSL::Patterns
11
9
 
12
10
  NTPSERVER = 'pool.ntp.org'
13
11
  SLEEPWAIT = 5
14
12
  TRIES = 5
15
- AMAZON2023_PACKAGES = %w[curl-minimal chrony]
16
13
  RHEL8_PACKAGES = %w[curl chrony]
17
14
  RHEL9_PACKAGES = ['chrony']
18
- FEDORA_PACKAGES = ['curl', 'chrony']
19
- UNIX_PACKAGES = ['curl', 'ntpdate']
15
+ FEDORA_PACKAGES = %w[curl chrony]
16
+ UNIX_PACKAGES = %w[curl ntpdate]
20
17
  FREEBSD_PACKAGES = ['curl', 'perl5|perl']
21
18
  OPENBSD_PACKAGES = ['curl']
22
- ARCHLINUX_PACKAGES = ['curl', 'ntp', 'net-tools', 'openssh']
19
+ ARCHLINUX_PACKAGES = %w[curl ntp net-tools openssh]
23
20
  WINDOWS_PACKAGES = ['curl']
24
21
  PSWINDOWS_PACKAGES = []
25
22
  SLES10_PACKAGES = ['curl']
26
- SLES_PACKAGES = ['curl', 'ntp']
27
- DEBIAN_PACKAGES = ['curl', 'ntpdate', 'lsb-release', 'apt-transport-https']
28
- CUMULUS_PACKAGES = ['curl', 'ntpdate']
29
- SOLARIS10_PACKAGES = ['CSWcurl', 'CSWntp', 'wget']
30
- SOLARIS11_PACKAGES = ['curl', 'ntp']
23
+ SLES_PACKAGES = %w[curl ntp]
24
+ DEBIAN_PACKAGES = %w[curl ntpdate lsb-release apt-transport-https]
25
+ CUMULUS_PACKAGES = %w[curl ntpdate]
26
+ SOLARIS10_PACKAGES = %w[CSWcurl CSWntp wget]
27
+ SOLARIS11_PACKAGES = %w[curl ntp]
31
28
  ETC_HOSTS_PATH = "/etc/hosts"
32
29
  ETC_HOSTS_PATH_SOLARIS = "/etc/inet/hosts"
33
30
  ROOT_KEYS_SCRIPT = "https://raw.githubusercontent.com/puppetlabs/puppetlabs-sshkeys/master/templates/scripts/manage_root_authorized_keys"
34
31
  ROOT_KEYS_SYNC_CMD = "curl -k -o - -L #{ROOT_KEYS_SCRIPT} | %s"
35
32
  ROOT_KEYS_SYNC_CMD_AIX = "curl --tlsv1 -o - -L #{ROOT_KEYS_SCRIPT} | %s"
36
- APT_CFG = %q{ Acquire::http::Proxy "http://proxy.puppetlabs.net:3128/"; }
37
- IPS_PKG_REPO="http://solaris-11-internal-repo.delivery.puppetlabs.net"
38
33
 
39
- #Run timesync on the provided hosts
34
+ # Run timesync on the provided hosts
40
35
  # @param [Host, Array<Host>] host One or more hosts to act upon
41
36
  # @param [Hash{Symbol=>String}] opts Options to alter execution.
42
37
  # @option opts [Beaker::Logger] :logger A {Beaker::Logger} object
@@ -48,38 +43,36 @@ module Beaker
48
43
  if host['platform'].include? 'windows'
49
44
  # The exit code of 5 is for Windows 2008 systems where the w32tm /register command
50
45
  # is not actually necessary.
51
- host.exec(Command.new("w32tm /register"), :acceptable_exit_codes => [0,5])
52
- host.exec(Command.new("net start w32time"), :acceptable_exit_codes => [0,2])
46
+ host.exec(Command.new("w32tm /register"), :acceptable_exit_codes => [0, 5])
47
+ host.exec(Command.new("net start w32time"), :acceptable_exit_codes => [0, 2])
53
48
  host.exec(Command.new("w32tm /config /manualpeerlist:#{ntp_server} /syncfromflags:manual /update"))
54
49
  host.exec(Command.new("w32tm /resync"))
55
50
  logger.notify "NTP date succeeded on #{host}"
56
51
  else
57
- case
58
- when /amazon|el-[89]|fedora/.match?(host['platform'])
52
+ if /el-[89]|fedora/.match?(host['platform'])
59
53
  ntp_command = "chronyc add server #{ntp_server} prefer trust;chronyc makestep;chronyc burst 1/2"
60
- when /opensuse-|sles-/.match?(host['platform'])
54
+ elsif /opensuse-|sles-/.match?(host['platform'])
61
55
  ntp_command = "sntp #{ntp_server}"
62
- when host['platform'].include?('cisco_nexus')
56
+ elsif host['platform'].include?('cisco_nexus')
63
57
  ntp_server = host.exec(Command.new("getent hosts #{NTPSERVER} | head -n1 |cut -d \" \" -f1"), :acceptable_exit_codes => [0]).stdout
64
58
  ntp_command = "sudo -E sh -c 'export DCOS_CONTEXT=2;/isan/bin/ntpdate -u -t 20 #{ntp_server}'"
65
59
  else
66
60
  ntp_command = "ntpdate -u -t 20 #{ntp_server}"
67
61
  end
68
- success=false
62
+ success = false
69
63
  try = 0
70
- until try >= TRIES do
64
+ until try >= TRIES
71
65
  try += 1
72
66
  if host.exec(Command.new(ntp_command), :accept_all_exit_codes => true).exit_code == 0
73
- success=true
67
+ success = true
74
68
  break
75
69
  end
76
70
  sleep SLEEPWAIT
77
71
  end
78
- if success
79
- logger.notify "NTP date succeeded on #{host} after #{try} tries"
80
- else
81
- raise "NTP date was not successful after #{try} tries"
82
- end
72
+ raise "NTP date was not successful after #{try} tries" unless success
73
+
74
+ logger.notify "NTP date succeeded on #{host} after #{try} tries"
75
+
83
76
  end
84
77
  end
85
78
  nil
@@ -115,8 +108,6 @@ module Beaker
115
108
  # @return [Array<String>] A list of packages to install
116
109
  def host_packages(host)
117
110
  case host['platform']
118
- when /amazon/
119
- AMAZON2023_PACKAGES
120
111
  when /el-8/
121
112
  RHEL8_PACKAGES
122
113
  when /el-9/
@@ -132,6 +123,7 @@ module Beaker
132
123
  when /windows/
133
124
  if host.is_cygwin?
134
125
  raise RuntimeError, "cygwin is not installed on #{host}" if !host.cygwin_installed?
126
+
135
127
  WINDOWS_PACKAGES
136
128
  else
137
129
  PSWINDOWS_PACKAGES
@@ -165,6 +157,7 @@ module Beaker
165
157
  package_list.each do |string|
166
158
  alternatives = string.split('|')
167
159
  next if alternatives.any? { |pkg| host.check_for_package pkg }
160
+
168
161
  install_one_of_packages host, alternatives
169
162
  end
170
163
  end
@@ -185,9 +178,9 @@ module Beaker
185
178
  raise error
186
179
  end
187
180
 
188
- #Install a set of authorized keys using {HostPrebuiltSteps::ROOT_KEYS_SCRIPT}. This is a
189
- #convenience method to allow for easy login to hosts after they have been provisioned with
190
- #Beaker.
181
+ # Install a set of authorized keys using {HostPrebuiltSteps::ROOT_KEYS_SCRIPT}. This is a
182
+ # convenience method to allow for easy login to hosts after they have been provisioned with
183
+ # Beaker.
191
184
  # @param [Host, Array<Host>] host One or more hosts to act upon
192
185
  # @param [Hash{Symbol=>String}] opts Options to alter execution.
193
186
  # @option opts [Beaker::Logger] :logger A {Beaker::Logger} object
@@ -198,7 +191,7 @@ module Beaker
198
191
  # when reality dictates otherwise"
199
192
  logger = opts[:logger]
200
193
  block_on host do |host|
201
- logger.notify "Sync root authorized_keys from github on #{host.name}"
194
+ logger.notify "Sync root authorized_keys from github on #{host.name}"
202
195
  # Allow all exit code, as this operation is unlikely to cause problems if it fails.
203
196
  if /solaris|eos/.match?(host['platform'])
204
197
  host.exec(Command.new(ROOT_KEYS_SYNC_CMD % "bash"), :accept_all_exit_codes => true)
@@ -218,124 +211,54 @@ module Beaker
218
211
  # @param [Host, Array<Host>] hosts One or more hosts to act upon
219
212
  def apt_get_update hosts
220
213
  block_on hosts do |host|
221
- if /ubuntu|debian|cumulus/.match?(host[:platform])
222
- host.exec(Command.new("apt-get update"))
223
- end
214
+ host.exec(Command.new("apt-get update")) if /ubuntu|debian|cumulus/.match?(host[:platform])
224
215
  end
225
216
  end
226
217
 
227
- #Create a file on host or hosts at the provided file path with the provided file contents.
218
+ # Create a file on host or hosts at the provided file path with the provided file contents.
228
219
  # @param [Host, Array<Host>] host One or more hosts to act upon
229
220
  # @param [String] file_path The path at which the new file will be created on the host or hosts.
230
221
  # @param [String] file_content The contents of the file to be created on the host or hosts.
231
222
  def copy_file_to_remote(host, file_path, file_content)
232
223
  block_on host do |host|
233
224
  Tempfile.open 'beaker' do |tempfile|
234
- File.open(tempfile.path, 'w') {|file| file.puts file_content }
225
+ File.open(tempfile.path, 'w') { |file| file.puts file_content }
235
226
 
236
227
  host.do_scp_to(tempfile.path, file_path, @options)
237
228
  end
238
229
  end
239
230
  end
240
231
 
241
- # On ubuntu, debian, or cumulus host or hosts: alter apt configuration to use
242
- # the internal Puppet Labs proxy {HostPrebuiltSteps::APT_CFG} proxy.
243
- # On solaris-11 host or hosts: alter pkg to point to
244
- # the internal Puppet Labs proxy {HostPrebuiltSteps::IPS_PKG_REPO}.
245
- #
246
- # Do nothing for other platform host or hosts.
247
- #
248
- # @param [Host, Array<Host>] host One or more hosts to act upon
249
- # @param [Hash{Symbol=>String}] opts Options to alter execution.
250
- # @option opts [Beaker::Logger] :logger A {Beaker::Logger} object
251
- def proxy_config( host, opts )
252
- logger = opts[:logger]
253
- block_on host do |host|
254
- case
255
- when /ubuntu|debian|cumulus/.match?(host['platform'])
256
- host.exec(Command.new("if test -f /etc/apt/apt.conf; then mv /etc/apt/apt.conf /etc/apt/apt.conf.bk; fi"))
257
- copy_file_to_remote(host, '/etc/apt/apt.conf', APT_CFG)
258
- apt_get_update(host)
259
- when host['platform'].include?('solaris-11')
260
- host.exec(Command.new("/usr/bin/pkg unset-publisher solaris || :"))
261
- host.exec(Command.new("/usr/bin/pkg set-publisher -g %s solaris" % IPS_PKG_REPO))
262
- else
263
- logger.debug "#{host}: repo proxy configuration not modified"
264
- end
265
- end
266
- rescue => e
267
- report_and_raise(logger, e, "proxy_config")
268
- end
269
-
270
- #Install EPEL on host or hosts with platform = /el-(6|7)/. Do nothing on host or hosts of other platforms.
271
- # @param [Host, Array<Host>] host One or more hosts to act upon. Will use individual host epel_url, epel_arch
272
- # and epel_pkg before using defaults provided in opts.
273
- # @param [Hash{Symbol=>String}] opts Options to alter execution.
274
- # @option opts [Boolean] :debug If true, print verbose rpm information when installing EPEL
275
- # @option opts [Beaker::Logger] :logger A {Beaker::Logger} object
276
- # @option opts [String] :epel_url Link to download from
277
- def add_el_extras( host, opts )
278
- #add_el_extras
279
- #only supports el-* platforms
280
- logger = opts[:logger]
281
- block_on host do |host|
282
- case
283
- when el_based?(host) && ['6','7'].include?(host['platform'].version)
284
- result = host.exec(Command.new('rpm -qa | grep epel-release'), :acceptable_exit_codes => [0,1])
285
- if result.exit_code == 1
286
- url_base = opts[:epel_url]
287
- host.install_package_with_rpm("#{url_base}/epel-release-latest-#{host['platform'].version}.noarch.rpm", '--replacepkgs', { :package_proxy => opts[:package_proxy] })
288
- #update /etc/yum.repos.d/epel.repo for new baseurl
289
- host.exec(Command.new("sed -i -e 's;#baseurl.*$;baseurl=#{Regexp.escape("#{url_base}/#{host['platform'].version}")}/\$basearch;' /etc/yum.repos.d/epel.repo"))
290
- #remove mirrorlist
291
- host.exec(Command.new("sed -i -e '/mirrorlist/d' /etc/yum.repos.d/epel.repo"))
292
- host.exec(Command.new('yum clean all && yum makecache'))
293
- end
294
- else
295
- logger.debug "#{host}: package repo configuration not modified"
296
- end
297
- end
298
- rescue => e
299
- report_and_raise(logger, e, "add_repos")
300
- end
301
-
302
- #Determine the domain name of the provided host from its /etc/resolv.conf
232
+ # Determine the domain name of the provided host from its /etc/resolv.conf
303
233
  # @param [Host] host the host to act upon
304
234
  def get_domain_name(host)
305
235
  domain = nil
306
236
  search = nil
307
- if host['platform'].include?('windows')
308
- if host.is_cygwin?
309
- resolv_conf = host.exec(Command.new("cat /cygdrive/c/Windows/System32/drivers/etc/hosts")).stdout
310
- else
311
- resolv_conf = host.exec(Command.new('type C:\Windows\System32\drivers\etc\hosts')).stdout
237
+ resolv_conf = if host['platform'].include?('windows')
238
+ if host.is_cygwin?
239
+ host.exec(Command.new("cat /cygdrive/c/Windows/System32/drivers/etc/hosts")).stdout
240
+ else
241
+ host.exec(Command.new('type C:\Windows\System32\drivers\etc\hosts')).stdout
242
+ end
243
+ else
244
+ host.exec(Command.new("cat /etc/resolv.conf")).stdout
245
+ end
246
+ resolv_conf.each_line do |line|
247
+ if (match = /^\s*domain\s+(\S+)/.match(line))
248
+ domain = match[1]
249
+ elsif (match = /^\s*search\s+(\S+)/.match(line))
250
+ search = match[1]
312
251
  end
313
- else
314
- resolv_conf = host.exec(Command.new("cat /etc/resolv.conf")).stdout
315
252
  end
316
- resolv_conf.each_line { |line|
317
- if line =~ /^\s*domain\s+(\S+)/
318
- domain = $1
319
- elsif line =~ /^\s*search\s+(\S+)/
320
- search = $1
321
- end
322
- }
323
253
  return_value ||= domain
324
254
  return_value ||= search
325
255
 
326
- if return_value
327
- return_value.gsub(/\.$/, '')
328
- end
329
- end
256
+ return unless return_value
330
257
 
331
- #Determine the ip address of the provided host
332
- # @param [Host] host the host to act upon
333
- # @deprecated use {Host#get_ip}
334
- def get_ip(host)
335
- host.get_ip
258
+ return_value.gsub(/\.$/, '')
336
259
  end
337
260
 
338
- #Append the provided string to the /etc/hosts file of the provided host
261
+ # Append the provided string to the /etc/hosts file of the provided host
339
262
  # @param [Host] host the host to act upon
340
263
  # @param [String] etc_hosts The string to append to the /etc/hosts file
341
264
  def set_etc_hosts(host, etc_hosts)
@@ -347,16 +270,16 @@ module Beaker
347
270
  host.exec(Command.new("echo '#{etc_hosts}' >> /etc/hosts"))
348
271
  end
349
272
  # AIX must be configured to prefer local DNS over external
350
- if host['platform'].include?('aix')
351
- aix_netsvc = '/etc/netsvc.conf'
352
- aix_local_resolv = 'hosts = local, bind'
353
- unless host.exec(Command.new("grep '#{aix_local_resolv}' #{aix_netsvc}"), :accept_all_exit_codes => true).exit_code == 0
354
- host.exec(Command.new("echo '#{aix_local_resolv}' >> #{aix_netsvc}"))
355
- end
356
- end
273
+ return unless host['platform'].include?('aix')
274
+
275
+ aix_netsvc = '/etc/netsvc.conf'
276
+ aix_local_resolv = 'hosts = local, bind'
277
+ return if host.exec(Command.new("grep '#{aix_local_resolv}' #{aix_netsvc}"), :accept_all_exit_codes => true).exit_code == 0
278
+
279
+ host.exec(Command.new("echo '#{aix_local_resolv}' >> #{aix_netsvc}"))
357
280
  end
358
281
 
359
- #Make it possible to log in as root by copying the current users ssh keys to the root account
282
+ # Make it possible to log in as root by copying the current users ssh keys to the root account
360
283
  # @param [Host, Array<Host>] host One or more hosts to act upon
361
284
  # @param [Hash{Symbol=>String}] opts Options to alter execution.
362
285
  # @option opts [Beaker::Logger] :logger A {Beaker::Logger} object
@@ -379,18 +302,16 @@ module Beaker
379
302
  # existing destination file.
380
303
  host.exec(Command.new("if exist .ssh (xcopy .ssh C:\\Users\\Administrator\\.ssh /s /e /y /i)"))
381
304
  elsif host['platform'].include?('osx')
382
- host.exec(Command.new('sudo cp -r .ssh /var/root/.'), {:pty => true})
305
+ host.exec(Command.new('sudo cp -r .ssh /var/root/.'), { :pty => true })
383
306
  elsif /(free|open)bsd/.match?(host['platform']) || host['platform'].include?('solaris-11')
384
- host.exec(Command.new('sudo cp -r .ssh /root/.'), {:pty => true})
307
+ host.exec(Command.new('sudo cp -r .ssh /root/.'), { :pty => true })
385
308
  elsif host['platform'].include?('solaris-10')
386
- host.exec(Command.new('sudo cp -r .ssh /.'), {:pty => true})
309
+ host.exec(Command.new('sudo cp -r .ssh /.'), { :pty => true })
387
310
  else
388
- host.exec(Command.new('sudo su -c "cp -r .ssh /root/."'), {:pty => true})
311
+ host.exec(Command.new('sudo su -c "cp -r .ssh /root/."'), { :pty => true })
389
312
  end
390
313
 
391
- if host.selinux_enabled?
392
- host.exec(Command.new('sudo fixfiles restore /root'))
393
- end
314
+ host.exec(Command.new('sudo fixfiles restore /root')) if host.selinux_enabled?
394
315
  end
395
316
  end
396
317
 
@@ -422,6 +343,7 @@ module Beaker
422
343
  logger = opts[:logger]
423
344
  hosts.each do |host|
424
345
  next if host['platform'].include?('netscaler')
346
+
425
347
  logger.notify "Disabling updates.puppetlabs.com by modifying hosts file to resolve updates to 127.0.0.1 on #{host}"
426
348
  set_etc_hosts(host, "127.0.0.1\tupdates.puppetlabs.com\n")
427
349
  end
@@ -446,40 +368,40 @@ module Beaker
446
368
  host.exec(Command.new("sudo sed -i '' 's/#PermitRootLogin no/PermitRootLogin Yes/g' #{ssh_config_file}"))
447
369
  host.exec(Command.new("sudo sed -i '' 's/#PermitRootLogin yes/PermitRootLogin Yes/g' #{ssh_config_file}"))
448
370
  elsif host['platform'].include?('freebsd')
449
- host.exec(Command.new("sudo sed -i -e 's/#PermitRootLogin no/PermitRootLogin yes/g' /etc/ssh/sshd_config"), {:pty => true} )
371
+ host.exec(Command.new("sudo sed -i -e 's/#PermitRootLogin no/PermitRootLogin yes/g' /etc/ssh/sshd_config"), { :pty => true })
450
372
  elsif host['platform'].include?('openbsd')
451
- host.exec(Command.new("sudo perl -pi -e 's/^PermitRootLogin no/PermitRootLogin yes/' /etc/ssh/sshd_config"), {:pty => true} )
373
+ host.exec(Command.new("sudo perl -pi -e 's/^PermitRootLogin no/PermitRootLogin yes/' /etc/ssh/sshd_config"), { :pty => true })
452
374
  elsif host['platform'].include?('solaris-10')
453
- host.exec(Command.new("sudo gsed -i -e 's/#PermitRootLogin no/PermitRootLogin yes/g' /etc/ssh/sshd_config"), {:pty => true} )
375
+ host.exec(Command.new("sudo gsed -i -e 's/#PermitRootLogin no/PermitRootLogin yes/g' /etc/ssh/sshd_config"), { :pty => true })
454
376
  elsif host['platform'].include?('solaris-11')
455
- host.exec(Command.new("if grep \"root::::type=role\" /etc/user_attr; then sudo rolemod -K type=normal root; else echo \"root user already type=normal\"; fi"), {:pty => true} )
456
- host.exec(Command.new("sudo gsed -i -e 's/PermitRootLogin no/PermitRootLogin yes/g' /etc/ssh/sshd_config"), {:pty => true} )
377
+ host.exec(Command.new("if grep \"root::::type=role\" /etc/user_attr; then sudo rolemod -K type=normal root; else echo \"root user already type=normal\"; fi"), { :pty => true })
378
+ host.exec(Command.new("sudo gsed -i -e 's/PermitRootLogin no/PermitRootLogin yes/g' /etc/ssh/sshd_config"), { :pty => true })
457
379
  elsif host['platform'].include?('f5') || host.is_powershell?
458
- #interacting with f5 should using tmsh
380
+ # interacting with f5 should using tmsh
459
381
  logger.warn("Attempting to enable root login non-supported platform: #{host.name}: #{host['platform']}")
460
382
  elsif host.is_cygwin?
461
- host.exec(Command.new("sed -ri 's/^#?PermitRootLogin /PermitRootLogin yes/' /etc/sshd_config"), {:pty => true})
383
+ host.exec(Command.new("sed -ri 's/^#?PermitRootLogin /PermitRootLogin yes/' /etc/sshd_config"), { :pty => true })
462
384
  else
463
- host.exec(Command.new("sudo su -c \"sed -ri 's/^#?PermitRootLogin no|^#?PermitRootLogin yes/PermitRootLogin yes/' /etc/ssh/sshd_config\""), {:pty => true})
385
+ host.exec(Command.new("sudo su -c \"sed -ri 's/^#?PermitRootLogin no|^#?PermitRootLogin yes/PermitRootLogin yes/' /etc/ssh/sshd_config\""), { :pty => true })
464
386
  end
465
- #restart sshd
387
+ # restart sshd
466
388
  if /debian|ubuntu|cumulus/.match?(host['platform'])
467
389
  host.exec(Command.new("sudo su -c \"service ssh restart\""), { :pty => true })
468
- elsif /amazon|arch|(centos|el|redhat)-[789]|fedora-(1[4-9]|2[0-9]|3[0-9])/.match?(host['platform'])
390
+ elsif /arch|(centos|el|redhat)-[789]|fedora-(1[4-9]|2[0-9]|3[0-9])/.match?(host['platform'])
469
391
  host.exec(Command.new("sudo -E systemctl restart sshd.service"), { :pty => true })
470
392
  elsif /centos|el-|redhat|fedora|eos/.match?(host['platform'])
471
- host.exec(Command.new("sudo -E /sbin/service sshd reload"), {:pty => true})
393
+ host.exec(Command.new("sudo -E /sbin/service sshd reload"), { :pty => true })
472
394
  elsif /(free|open)bsd/.match?(host['platform'])
473
395
  host.exec(Command.new("sudo /etc/rc.d/sshd restart"))
474
396
  elsif host['platform'].include?('solaris')
475
- host.exec(Command.new("sudo -E svcadm restart network/ssh"), {:pty => true} )
397
+ host.exec(Command.new("sudo -E svcadm restart network/ssh"), { :pty => true })
476
398
  else
477
399
  logger.warn("Attempting to update ssh on non-supported platform: #{host.name}: #{host['platform']}")
478
400
  end
479
401
  end
480
402
  end
481
403
 
482
- #Disable SELinux on centos, does nothing on other platforms
404
+ # Disable SELinux on centos, does nothing on other platforms
483
405
  # @param [Host, Array<Host>] host One or more hosts to act upon
484
406
  # @param [Hash{Symbol=>String}] opts Options to alter execution.
485
407
  # @option opts [Beaker::Logger] :logger A {Beaker::Logger} object
@@ -488,29 +410,13 @@ module Beaker
488
410
  block_on host do |host|
489
411
  if /centos|el-|redhat|fedora|eos/.match?(host['platform'])
490
412
  logger.debug("Disabling se_linux on #{host.name}")
491
- host.exec(Command.new("sudo su -c \"setenforce 0\""), {:pty => true})
413
+ host.exec(Command.new("sudo su -c \"setenforce 0\""), { :pty => true })
492
414
  else
493
415
  logger.warn("Attempting to disable SELinux on non-supported platform: #{host.name}: #{host['platform']}")
494
416
  end
495
417
  end
496
418
  end
497
419
 
498
- #Disable iptables on centos, does nothing on other platforms
499
- # @param [Host, Array<Host>] host One or more hosts to act upon
500
- # @param [Hash{Symbol=>String}] opts Options to alter execution.
501
- # @option opts [Beaker::Logger] :logger A {Beaker::Logger} object
502
- def disable_iptables host, opts
503
- logger = opts[:logger]
504
- block_on host do |host|
505
- if /centos|el-|redhat|fedora|eos/.match?(host['platform'])
506
- logger.debug("Disabling iptables on #{host.name}")
507
- host.exec(Command.new("sudo su -c \"/etc/init.d/iptables stop\""), {:pty => true})
508
- else
509
- logger.warn("Attempting to disable iptables on non-supported platform: #{host.name}: #{host['platform']}")
510
- end
511
- end
512
- end
513
-
514
420
  # Setup files for enabling requests to pass to a proxy server
515
421
  # This works for the APT package manager on debian, ubuntu, and cumulus
516
422
  # and YUM package manager on el, centos, fedora and redhat.
@@ -525,15 +431,17 @@ module Beaker
525
431
  case host['platform']
526
432
  when /ubuntu/, /debian/, /cumulus/
527
433
  host.exec(Command.new("echo 'Acquire::http::Proxy \"#{opts[:package_proxy]}/\";' >> /etc/apt/apt.conf.d/10proxy"))
528
- when /amazon/, /^el-/, /centos/, /fedora/, /redhat/, /eos/
434
+ when /^el-/, /centos/, /fedora/, /redhat/, /eos/
529
435
  host.exec(Command.new("echo 'proxy=#{opts[:package_proxy]}/' >> /etc/yum.conf"))
436
+ when /solaris-11/
437
+ host.exec(Command.new("/usr/bin/pkg unset-publisher solaris || :"))
438
+ host.exec(Command.new("/usr/bin/pkg set-publisher -g %s solaris" % opts[:package_proxy]))
530
439
  else
531
440
  logger.debug("Attempting to enable package manager proxy support on non-supported platform: #{host.name}: #{host['platform']}")
532
441
  end
533
442
  end
534
443
  end
535
444
 
536
-
537
445
  # Merge the two provided hashes so that an array of values is created from collisions
538
446
  # @param [Hash] h1 The first hash
539
447
  # @param [Hash] h2 The second hash
@@ -545,12 +453,12 @@ module Beaker
545
453
  # => {:PATH=>["/1st/path", "/2nd/path"]}
546
454
  def additive_hash_merge h1, h2
547
455
  merged_hash = {}
548
- normalized_h2 = h2.inject({}) { |h, (k, v)| h[k.to_s.upcase] = v; h }
456
+ normalized_h2 = h2.each_with_object({}) { |(k, v), h| h[k.to_s.upcase] = v; }
549
457
  h1.each_pair do |key, _val|
550
458
  normalized_key = key.to_s.upcase
551
459
  if normalized_h2.has_key?(normalized_key)
552
460
  merged_hash[key] = [h1[key], normalized_h2[normalized_key]]
553
- merged_hash[key] = merged_hash[key].uniq #remove dupes
461
+ merged_hash[key] = merged_hash[key].uniq # remove dupes
554
462
  end
555
463
  end
556
464
  merged_hash
@@ -565,9 +473,7 @@ module Beaker
565
473
 
566
474
  env.each_key do |key|
567
475
  separator = host['pathseparator']
568
- if key == 'PATH' && (not host.is_powershell?)
569
- separator = ':'
570
- end
476
+ separator = ':' if key == 'PATH' && (not host.is_powershell?)
571
477
  env[key] = env[key].join(separator)
572
478
  end
573
479
  env
@@ -582,7 +488,7 @@ module Beaker
582
488
  block_on host do |host|
583
489
  skip_msg = host.skip_set_env?
584
490
  unless skip_msg.nil?
585
- logger.debug( skip_msg )
491
+ logger.debug(skip_msg)
586
492
  next
587
493
  end
588
494
 
@@ -590,14 +496,12 @@ module Beaker
590
496
 
591
497
  logger.debug("setting local environment on #{host.name}")
592
498
 
593
- if host['platform'].include?('windows') && host.is_cygwin?
594
- env['CYGWIN'] = 'nodosfilewarning'
595
- end
499
+ env['CYGWIN'] = 'nodosfilewarning' if host['platform'].include?('windows') && host.is_cygwin?
596
500
 
597
501
  host.ssh_permit_user_environment
598
502
  host.ssh_set_user_environment(env)
599
503
 
600
- #close the host to re-establish the connection with the new sshd settings
504
+ # close the host to re-establish the connection with the new sshd settings
601
505
  host.close
602
506
 
603
507
  # print out the working env
@@ -608,17 +512,5 @@ module Beaker
608
512
  end
609
513
  end
610
514
  end
611
-
612
- private
613
-
614
- # A helper to tell whether a host is el-based
615
- # @param [Host] host the host to act upon
616
- #
617
- # @return [Boolean] if the host is el_based
618
- def el_based? host
619
- ['centos','redhat','scientific','el','oracle'].include?(host['platform'].variant)
620
- end
621
-
622
515
  end
623
-
624
516
  end
@@ -1,10 +1,9 @@
1
1
  module Beaker
2
2
  class Noop < Beaker::Hypervisor
3
+ def initialize(hosts, options)
4
+ super
3
5
 
4
- def initialize(new_hosts, options)
5
- @options = options
6
6
  @logger = options[:logger]
7
- @hosts = new_hosts
8
7
  end
9
8
 
10
9
  def validate
@@ -26,6 +25,5 @@ module Beaker
26
25
  def cleanup
27
26
  # noop
28
27
  end
29
-
30
28
  end
31
29
  end