beaker 4.40.2 → 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 +17 -28
  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 +6 -5
  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 +16 -28
  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 +6 -7
  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 +172 -161
  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 +48 -57
  167. data/spec/beaker/host/mac/user_spec.rb +54 -63
  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
@@ -1,41 +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
- RHEL8_PACKAGES = ['curl', 'chrony']
13
+ RHEL8_PACKAGES = %w[curl chrony]
16
14
  RHEL9_PACKAGES = ['chrony']
17
- FEDORA_PACKAGES = ['curl', 'chrony']
18
- UNIX_PACKAGES = ['curl', 'ntpdate']
15
+ FEDORA_PACKAGES = %w[curl chrony]
16
+ UNIX_PACKAGES = %w[curl ntpdate]
19
17
  FREEBSD_PACKAGES = ['curl', 'perl5|perl']
20
18
  OPENBSD_PACKAGES = ['curl']
21
- ARCHLINUX_PACKAGES = ['curl', 'ntp', 'net-tools', 'openssh']
19
+ ARCHLINUX_PACKAGES = %w[curl ntp net-tools openssh]
22
20
  WINDOWS_PACKAGES = ['curl']
23
21
  PSWINDOWS_PACKAGES = []
24
22
  SLES10_PACKAGES = ['curl']
25
- SLES_PACKAGES = ['curl', 'ntp']
26
- DEBIAN_PACKAGES = ['curl', 'ntpdate', 'lsb-release', 'apt-transport-https']
27
- CUMULUS_PACKAGES = ['curl', 'ntpdate']
28
- SOLARIS10_PACKAGES = ['CSWcurl', 'CSWntp', 'wget']
29
- 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]
30
28
  ETC_HOSTS_PATH = "/etc/hosts"
31
29
  ETC_HOSTS_PATH_SOLARIS = "/etc/inet/hosts"
32
30
  ROOT_KEYS_SCRIPT = "https://raw.githubusercontent.com/puppetlabs/puppetlabs-sshkeys/master/templates/scripts/manage_root_authorized_keys"
33
31
  ROOT_KEYS_SYNC_CMD = "curl -k -o - -L #{ROOT_KEYS_SCRIPT} | %s"
34
32
  ROOT_KEYS_SYNC_CMD_AIX = "curl --tlsv1 -o - -L #{ROOT_KEYS_SCRIPT} | %s"
35
- APT_CFG = %q{ Acquire::http::Proxy "http://proxy.puppetlabs.net:3128/"; }
36
- IPS_PKG_REPO="http://solaris-11-internal-repo.delivery.puppetlabs.net"
37
33
 
38
- #Run timesync on the provided hosts
34
+ # Run timesync on the provided hosts
39
35
  # @param [Host, Array<Host>] host One or more hosts to act upon
40
36
  # @param [Hash{Symbol=>String}] opts Options to alter execution.
41
37
  # @option opts [Beaker::Logger] :logger A {Beaker::Logger} object
@@ -47,38 +43,36 @@ module Beaker
47
43
  if host['platform'].include? 'windows'
48
44
  # The exit code of 5 is for Windows 2008 systems where the w32tm /register command
49
45
  # is not actually necessary.
50
- host.exec(Command.new("w32tm /register"), :acceptable_exit_codes => [0,5])
51
- 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])
52
48
  host.exec(Command.new("w32tm /config /manualpeerlist:#{ntp_server} /syncfromflags:manual /update"))
53
49
  host.exec(Command.new("w32tm /resync"))
54
50
  logger.notify "NTP date succeeded on #{host}"
55
51
  else
56
- case
57
- when /el-[89]|fedora/.match?(host['platform'])
52
+ if /el-[89]|fedora/.match?(host['platform'])
58
53
  ntp_command = "chronyc add server #{ntp_server} prefer trust;chronyc makestep;chronyc burst 1/2"
59
- when /opensuse-|sles-/.match?(host['platform'])
54
+ elsif /opensuse-|sles-/.match?(host['platform'])
60
55
  ntp_command = "sntp #{ntp_server}"
61
- when host['platform'].include?('cisco_nexus')
56
+ elsif host['platform'].include?('cisco_nexus')
62
57
  ntp_server = host.exec(Command.new("getent hosts #{NTPSERVER} | head -n1 |cut -d \" \" -f1"), :acceptable_exit_codes => [0]).stdout
63
58
  ntp_command = "sudo -E sh -c 'export DCOS_CONTEXT=2;/isan/bin/ntpdate -u -t 20 #{ntp_server}'"
64
59
  else
65
60
  ntp_command = "ntpdate -u -t 20 #{ntp_server}"
66
61
  end
67
- success=false
62
+ success = false
68
63
  try = 0
69
- until try >= TRIES do
64
+ until try >= TRIES
70
65
  try += 1
71
66
  if host.exec(Command.new(ntp_command), :accept_all_exit_codes => true).exit_code == 0
72
- success=true
67
+ success = true
73
68
  break
74
69
  end
75
70
  sleep SLEEPWAIT
76
71
  end
77
- if success
78
- logger.notify "NTP date succeeded on #{host} after #{try} tries"
79
- else
80
- raise "NTP date was not successful after #{try} tries"
81
- 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
+
82
76
  end
83
77
  end
84
78
  nil
@@ -129,6 +123,7 @@ module Beaker
129
123
  when /windows/
130
124
  if host.is_cygwin?
131
125
  raise RuntimeError, "cygwin is not installed on #{host}" if !host.cygwin_installed?
126
+
132
127
  WINDOWS_PACKAGES
133
128
  else
134
129
  PSWINDOWS_PACKAGES
@@ -162,6 +157,7 @@ module Beaker
162
157
  package_list.each do |string|
163
158
  alternatives = string.split('|')
164
159
  next if alternatives.any? { |pkg| host.check_for_package pkg }
160
+
165
161
  install_one_of_packages host, alternatives
166
162
  end
167
163
  end
@@ -182,9 +178,9 @@ module Beaker
182
178
  raise error
183
179
  end
184
180
 
185
- #Install a set of authorized keys using {HostPrebuiltSteps::ROOT_KEYS_SCRIPT}. This is a
186
- #convenience method to allow for easy login to hosts after they have been provisioned with
187
- #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.
188
184
  # @param [Host, Array<Host>] host One or more hosts to act upon
189
185
  # @param [Hash{Symbol=>String}] opts Options to alter execution.
190
186
  # @option opts [Beaker::Logger] :logger A {Beaker::Logger} object
@@ -195,7 +191,7 @@ module Beaker
195
191
  # when reality dictates otherwise"
196
192
  logger = opts[:logger]
197
193
  block_on host do |host|
198
- logger.notify "Sync root authorized_keys from github on #{host.name}"
194
+ logger.notify "Sync root authorized_keys from github on #{host.name}"
199
195
  # Allow all exit code, as this operation is unlikely to cause problems if it fails.
200
196
  if /solaris|eos/.match?(host['platform'])
201
197
  host.exec(Command.new(ROOT_KEYS_SYNC_CMD % "bash"), :accept_all_exit_codes => true)
@@ -215,124 +211,54 @@ module Beaker
215
211
  # @param [Host, Array<Host>] hosts One or more hosts to act upon
216
212
  def apt_get_update hosts
217
213
  block_on hosts do |host|
218
- if /ubuntu|debian|cumulus/.match?(host[:platform])
219
- host.exec(Command.new("apt-get update"))
220
- end
214
+ host.exec(Command.new("apt-get update")) if /ubuntu|debian|cumulus/.match?(host[:platform])
221
215
  end
222
216
  end
223
217
 
224
- #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.
225
219
  # @param [Host, Array<Host>] host One or more hosts to act upon
226
220
  # @param [String] file_path The path at which the new file will be created on the host or hosts.
227
221
  # @param [String] file_content The contents of the file to be created on the host or hosts.
228
222
  def copy_file_to_remote(host, file_path, file_content)
229
223
  block_on host do |host|
230
224
  Tempfile.open 'beaker' do |tempfile|
231
- File.open(tempfile.path, 'w') {|file| file.puts file_content }
225
+ File.open(tempfile.path, 'w') { |file| file.puts file_content }
232
226
 
233
227
  host.do_scp_to(tempfile.path, file_path, @options)
234
228
  end
235
229
  end
236
230
  end
237
231
 
238
- # On ubuntu, debian, or cumulus host or hosts: alter apt configuration to use
239
- # the internal Puppet Labs proxy {HostPrebuiltSteps::APT_CFG} proxy.
240
- # On solaris-11 host or hosts: alter pkg to point to
241
- # the internal Puppet Labs proxy {HostPrebuiltSteps::IPS_PKG_REPO}.
242
- #
243
- # Do nothing for other platform host or hosts.
244
- #
245
- # @param [Host, Array<Host>] host One or more hosts to act upon
246
- # @param [Hash{Symbol=>String}] opts Options to alter execution.
247
- # @option opts [Beaker::Logger] :logger A {Beaker::Logger} object
248
- def proxy_config( host, opts )
249
- logger = opts[:logger]
250
- block_on host do |host|
251
- case
252
- when /ubuntu|debian|cumulus/.match?(host['platform'])
253
- host.exec(Command.new("if test -f /etc/apt/apt.conf; then mv /etc/apt/apt.conf /etc/apt/apt.conf.bk; fi"))
254
- copy_file_to_remote(host, '/etc/apt/apt.conf', APT_CFG)
255
- apt_get_update(host)
256
- when host['platform'].include?('solaris-11')
257
- host.exec(Command.new("/usr/bin/pkg unset-publisher solaris || :"))
258
- host.exec(Command.new("/usr/bin/pkg set-publisher -g %s solaris" % IPS_PKG_REPO))
259
- else
260
- logger.debug "#{host}: repo proxy configuration not modified"
261
- end
262
- end
263
- rescue => e
264
- report_and_raise(logger, e, "proxy_config")
265
- end
266
-
267
- #Install EPEL on host or hosts with platform = /el-(6|7)/. Do nothing on host or hosts of other platforms.
268
- # @param [Host, Array<Host>] host One or more hosts to act upon. Will use individual host epel_url, epel_arch
269
- # and epel_pkg before using defaults provided in opts.
270
- # @param [Hash{Symbol=>String}] opts Options to alter execution.
271
- # @option opts [Boolean] :debug If true, print verbose rpm information when installing EPEL
272
- # @option opts [Beaker::Logger] :logger A {Beaker::Logger} object
273
- # @option opts [String] :epel_url Link to download from
274
- def add_el_extras( host, opts )
275
- #add_el_extras
276
- #only supports el-* platforms
277
- logger = opts[:logger]
278
- block_on host do |host|
279
- case
280
- when el_based?(host) && ['6','7'].include?(host['platform'].version)
281
- result = host.exec(Command.new('rpm -qa | grep epel-release'), :acceptable_exit_codes => [0,1])
282
- if result.exit_code == 1
283
- url_base = opts[:epel_url]
284
- host.install_package_with_rpm("#{url_base}/epel-release-latest-#{host['platform'].version}.noarch.rpm", '--replacepkgs', { :package_proxy => opts[:package_proxy] })
285
- #update /etc/yum.repos.d/epel.repo for new baseurl
286
- host.exec(Command.new("sed -i -e 's;#baseurl.*$;baseurl=#{Regexp.escape("#{url_base}/#{host['platform'].version}")}/\$basearch;' /etc/yum.repos.d/epel.repo"))
287
- #remove mirrorlist
288
- host.exec(Command.new("sed -i -e '/mirrorlist/d' /etc/yum.repos.d/epel.repo"))
289
- host.exec(Command.new('yum clean all && yum makecache'))
290
- end
291
- else
292
- logger.debug "#{host}: package repo configuration not modified"
293
- end
294
- end
295
- rescue => e
296
- report_and_raise(logger, e, "add_repos")
297
- end
298
-
299
- #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
300
233
  # @param [Host] host the host to act upon
301
234
  def get_domain_name(host)
302
235
  domain = nil
303
236
  search = nil
304
- if host['platform'].include?('windows')
305
- if host.is_cygwin?
306
- resolv_conf = host.exec(Command.new("cat /cygdrive/c/Windows/System32/drivers/etc/hosts")).stdout
307
- else
308
- 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]
309
251
  end
310
- else
311
- resolv_conf = host.exec(Command.new("cat /etc/resolv.conf")).stdout
312
252
  end
313
- resolv_conf.each_line { |line|
314
- if line =~ /^\s*domain\s+(\S+)/
315
- domain = $1
316
- elsif line =~ /^\s*search\s+(\S+)/
317
- search = $1
318
- end
319
- }
320
253
  return_value ||= domain
321
254
  return_value ||= search
322
255
 
323
- if return_value
324
- return_value.gsub(/\.$/, '')
325
- end
326
- end
256
+ return unless return_value
327
257
 
328
- #Determine the ip address of the provided host
329
- # @param [Host] host the host to act upon
330
- # @deprecated use {Host#get_ip}
331
- def get_ip(host)
332
- host.get_ip
258
+ return_value.gsub(/\.$/, '')
333
259
  end
334
260
 
335
- #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
336
262
  # @param [Host] host the host to act upon
337
263
  # @param [String] etc_hosts The string to append to the /etc/hosts file
338
264
  def set_etc_hosts(host, etc_hosts)
@@ -344,16 +270,16 @@ module Beaker
344
270
  host.exec(Command.new("echo '#{etc_hosts}' >> /etc/hosts"))
345
271
  end
346
272
  # AIX must be configured to prefer local DNS over external
347
- if host['platform'].include?('aix')
348
- aix_netsvc = '/etc/netsvc.conf'
349
- aix_local_resolv = 'hosts = local, bind'
350
- unless host.exec(Command.new("grep '#{aix_local_resolv}' #{aix_netsvc}"), :accept_all_exit_codes => true).exit_code == 0
351
- host.exec(Command.new("echo '#{aix_local_resolv}' >> #{aix_netsvc}"))
352
- end
353
- 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}"))
354
280
  end
355
281
 
356
- #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
357
283
  # @param [Host, Array<Host>] host One or more hosts to act upon
358
284
  # @param [Hash{Symbol=>String}] opts Options to alter execution.
359
285
  # @option opts [Beaker::Logger] :logger A {Beaker::Logger} object
@@ -376,18 +302,16 @@ module Beaker
376
302
  # existing destination file.
377
303
  host.exec(Command.new("if exist .ssh (xcopy .ssh C:\\Users\\Administrator\\.ssh /s /e /y /i)"))
378
304
  elsif host['platform'].include?('osx')
379
- 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 })
380
306
  elsif /(free|open)bsd/.match?(host['platform']) || host['platform'].include?('solaris-11')
381
- host.exec(Command.new('sudo cp -r .ssh /root/.'), {:pty => true})
307
+ host.exec(Command.new('sudo cp -r .ssh /root/.'), { :pty => true })
382
308
  elsif host['platform'].include?('solaris-10')
383
- host.exec(Command.new('sudo cp -r .ssh /.'), {:pty => true})
309
+ host.exec(Command.new('sudo cp -r .ssh /.'), { :pty => true })
384
310
  else
385
- 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 })
386
312
  end
387
313
 
388
- if host.selinux_enabled?
389
- host.exec(Command.new('sudo fixfiles restore /root'))
390
- end
314
+ host.exec(Command.new('sudo fixfiles restore /root')) if host.selinux_enabled?
391
315
  end
392
316
  end
393
317
 
@@ -419,6 +343,7 @@ module Beaker
419
343
  logger = opts[:logger]
420
344
  hosts.each do |host|
421
345
  next if host['platform'].include?('netscaler')
346
+
422
347
  logger.notify "Disabling updates.puppetlabs.com by modifying hosts file to resolve updates to 127.0.0.1 on #{host}"
423
348
  set_etc_hosts(host, "127.0.0.1\tupdates.puppetlabs.com\n")
424
349
  end
@@ -443,40 +368,40 @@ module Beaker
443
368
  host.exec(Command.new("sudo sed -i '' 's/#PermitRootLogin no/PermitRootLogin Yes/g' #{ssh_config_file}"))
444
369
  host.exec(Command.new("sudo sed -i '' 's/#PermitRootLogin yes/PermitRootLogin Yes/g' #{ssh_config_file}"))
445
370
  elsif host['platform'].include?('freebsd')
446
- 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 })
447
372
  elsif host['platform'].include?('openbsd')
448
- 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 })
449
374
  elsif host['platform'].include?('solaris-10')
450
- 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 })
451
376
  elsif host['platform'].include?('solaris-11')
452
- 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} )
453
- 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 })
454
379
  elsif host['platform'].include?('f5') || host.is_powershell?
455
- #interacting with f5 should using tmsh
380
+ # interacting with f5 should using tmsh
456
381
  logger.warn("Attempting to enable root login non-supported platform: #{host.name}: #{host['platform']}")
457
382
  elsif host.is_cygwin?
458
- 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 })
459
384
  else
460
- 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 })
461
386
  end
462
- #restart sshd
387
+ # restart sshd
463
388
  if /debian|ubuntu|cumulus/.match?(host['platform'])
464
- host.exec(Command.new("sudo su -c \"service ssh restart\""), {:pty => true})
389
+ host.exec(Command.new("sudo su -c \"service ssh restart\""), { :pty => true })
465
390
  elsif /arch|(centos|el|redhat)-[789]|fedora-(1[4-9]|2[0-9]|3[0-9])/.match?(host['platform'])
466
- host.exec(Command.new("sudo -E systemctl restart sshd.service"), {:pty => true})
391
+ host.exec(Command.new("sudo -E systemctl restart sshd.service"), { :pty => true })
467
392
  elsif /centos|el-|redhat|fedora|eos/.match?(host['platform'])
468
- 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 })
469
394
  elsif /(free|open)bsd/.match?(host['platform'])
470
395
  host.exec(Command.new("sudo /etc/rc.d/sshd restart"))
471
396
  elsif host['platform'].include?('solaris')
472
- 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 })
473
398
  else
474
399
  logger.warn("Attempting to update ssh on non-supported platform: #{host.name}: #{host['platform']}")
475
400
  end
476
401
  end
477
402
  end
478
403
 
479
- #Disable SELinux on centos, does nothing on other platforms
404
+ # Disable SELinux on centos, does nothing on other platforms
480
405
  # @param [Host, Array<Host>] host One or more hosts to act upon
481
406
  # @param [Hash{Symbol=>String}] opts Options to alter execution.
482
407
  # @option opts [Beaker::Logger] :logger A {Beaker::Logger} object
@@ -485,29 +410,13 @@ module Beaker
485
410
  block_on host do |host|
486
411
  if /centos|el-|redhat|fedora|eos/.match?(host['platform'])
487
412
  logger.debug("Disabling se_linux on #{host.name}")
488
- host.exec(Command.new("sudo su -c \"setenforce 0\""), {:pty => true})
413
+ host.exec(Command.new("sudo su -c \"setenforce 0\""), { :pty => true })
489
414
  else
490
415
  logger.warn("Attempting to disable SELinux on non-supported platform: #{host.name}: #{host['platform']}")
491
416
  end
492
417
  end
493
418
  end
494
419
 
495
- #Disable iptables on centos, does nothing on other platforms
496
- # @param [Host, Array<Host>] host One or more hosts to act upon
497
- # @param [Hash{Symbol=>String}] opts Options to alter execution.
498
- # @option opts [Beaker::Logger] :logger A {Beaker::Logger} object
499
- def disable_iptables host, opts
500
- logger = opts[:logger]
501
- block_on host do |host|
502
- if /centos|el-|redhat|fedora|eos/.match?(host['platform'])
503
- logger.debug("Disabling iptables on #{host.name}")
504
- host.exec(Command.new("sudo su -c \"/etc/init.d/iptables stop\""), {:pty => true})
505
- else
506
- logger.warn("Attempting to disable iptables on non-supported platform: #{host.name}: #{host['platform']}")
507
- end
508
- end
509
- end
510
-
511
420
  # Setup files for enabling requests to pass to a proxy server
512
421
  # This works for the APT package manager on debian, ubuntu, and cumulus
513
422
  # and YUM package manager on el, centos, fedora and redhat.
@@ -520,17 +429,19 @@ module Beaker
520
429
  block_on host do |host|
521
430
  logger.debug("enabling proxy support on #{host.name}")
522
431
  case host['platform']
523
- when /ubuntu/, /debian/, /cumulus/
524
- host.exec(Command.new("echo 'Acquire::http::Proxy \"#{opts[:package_proxy]}/\";' >> /etc/apt/apt.conf.d/10proxy"))
525
- when /^el-/, /centos/, /fedora/, /redhat/, /eos/
526
- host.exec(Command.new("echo 'proxy=#{opts[:package_proxy]}/' >> /etc/yum.conf"))
432
+ when /ubuntu/, /debian/, /cumulus/
433
+ host.exec(Command.new("echo 'Acquire::http::Proxy \"#{opts[:package_proxy]}/\";' >> /etc/apt/apt.conf.d/10proxy"))
434
+ when /^el-/, /centos/, /fedora/, /redhat/, /eos/
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]))
527
439
  else
528
440
  logger.debug("Attempting to enable package manager proxy support on non-supported platform: #{host.name}: #{host['platform']}")
529
441
  end
530
442
  end
531
443
  end
532
444
 
533
-
534
445
  # Merge the two provided hashes so that an array of values is created from collisions
535
446
  # @param [Hash] h1 The first hash
536
447
  # @param [Hash] h2 The second hash
@@ -542,12 +453,12 @@ module Beaker
542
453
  # => {:PATH=>["/1st/path", "/2nd/path"]}
543
454
  def additive_hash_merge h1, h2
544
455
  merged_hash = {}
545
- 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; }
546
457
  h1.each_pair do |key, _val|
547
458
  normalized_key = key.to_s.upcase
548
459
  if normalized_h2.has_key?(normalized_key)
549
460
  merged_hash[key] = [h1[key], normalized_h2[normalized_key]]
550
- merged_hash[key] = merged_hash[key].uniq #remove dupes
461
+ merged_hash[key] = merged_hash[key].uniq # remove dupes
551
462
  end
552
463
  end
553
464
  merged_hash
@@ -562,9 +473,7 @@ module Beaker
562
473
 
563
474
  env.each_key do |key|
564
475
  separator = host['pathseparator']
565
- if key == 'PATH' && (not host.is_powershell?)
566
- separator = ':'
567
- end
476
+ separator = ':' if key == 'PATH' && (not host.is_powershell?)
568
477
  env[key] = env[key].join(separator)
569
478
  end
570
479
  env
@@ -579,7 +488,7 @@ module Beaker
579
488
  block_on host do |host|
580
489
  skip_msg = host.skip_set_env?
581
490
  unless skip_msg.nil?
582
- logger.debug( skip_msg )
491
+ logger.debug(skip_msg)
583
492
  next
584
493
  end
585
494
 
@@ -587,14 +496,12 @@ module Beaker
587
496
 
588
497
  logger.debug("setting local environment on #{host.name}")
589
498
 
590
- if host['platform'].include?('windows') && host.is_cygwin?
591
- env['CYGWIN'] = 'nodosfilewarning'
592
- end
499
+ env['CYGWIN'] = 'nodosfilewarning' if host['platform'].include?('windows') && host.is_cygwin?
593
500
 
594
501
  host.ssh_permit_user_environment
595
502
  host.ssh_set_user_environment(env)
596
503
 
597
- #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
598
505
  host.close
599
506
 
600
507
  # print out the working env
@@ -605,17 +512,5 @@ module Beaker
605
512
  end
606
513
  end
607
514
  end
608
-
609
- private
610
-
611
- # A helper to tell whether a host is el-based
612
- # @param [Host] host the host to act upon
613
- #
614
- # @return [Boolean] if the host is el_based
615
- def el_based? host
616
- ['centos','redhat','scientific','el','oracle'].include?(host['platform'].variant)
617
- end
618
-
619
515
  end
620
-
621
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