beaker 4.38.1 → 5.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (225) 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 +36 -11
  5. data/.rubocop.yml +75 -0
  6. data/.rubocop_todo.yml +239 -0
  7. data/CHANGELOG.md +88 -33
  8. data/Gemfile +16 -4
  9. data/HISTORY.md +103 -0
  10. data/Rakefile +101 -112
  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/Gemfile +1 -1
  16. data/acceptance/fixtures/module/Rakefile +3 -3
  17. data/acceptance/fixtures/module/spec/acceptance/demo_spec.rb +16 -23
  18. data/acceptance/fixtures/module/spec/classes/init_spec.rb +1 -2
  19. data/acceptance/fixtures/module/spec/spec_helper_acceptance.rb +3 -5
  20. data/acceptance/lib/helpers/test_helper.rb +7 -6
  21. data/acceptance/pre_suite/subcommands/05_install_ruby.rb +2 -3
  22. data/acceptance/pre_suite/subcommands/08_install_beaker.rb +1 -2
  23. data/acceptance/tests/base/dsl/helpers/configuration_test.rb +4 -4
  24. data/acceptance/tests/base/dsl/helpers/hocon_helpers_test.rb +7 -8
  25. data/acceptance/tests/base/dsl/helpers/host_helpers/add_system32_hosts_entry_test.rb +0 -3
  26. data/acceptance/tests/base/dsl/helpers/host_helpers/archive_file_from_test.rb +9 -7
  27. data/acceptance/tests/base/dsl/helpers/host_helpers/backup_the_file_test.rb +15 -21
  28. data/acceptance/tests/base/dsl/helpers/host_helpers/check_for_package_test.rb +0 -4
  29. data/acceptance/tests/base/dsl/helpers/host_helpers/create_remote_file_test.rb +23 -30
  30. data/acceptance/tests/base/dsl/helpers/host_helpers/curl_on_test.rb +3 -3
  31. data/acceptance/tests/base/dsl/helpers/host_helpers/curl_with_retries_test.rb +0 -1
  32. data/acceptance/tests/base/dsl/helpers/host_helpers/on_test.rb +21 -16
  33. data/acceptance/tests/base/dsl/helpers/host_helpers/retry_on_test.rb +7 -7
  34. data/acceptance/tests/base/dsl/helpers/host_helpers/rsync_to_test.rb +30 -38
  35. data/acceptance/tests/base/dsl/helpers/host_helpers/run_cron_on_test.rb +14 -18
  36. data/acceptance/tests/base/dsl/helpers/host_helpers/run_script_on_test.rb +8 -14
  37. data/acceptance/tests/base/dsl/helpers/host_helpers/run_script_test.rb +7 -11
  38. data/acceptance/tests/base/dsl/helpers/host_helpers/scp_from_test.rb +5 -5
  39. data/acceptance/tests/base/dsl/helpers/host_helpers/scp_to_test.rb +4 -5
  40. data/acceptance/tests/base/dsl/helpers/host_helpers/shell_test.rb +8 -8
  41. data/acceptance/tests/base/dsl/helpers/host_helpers/upgrade_package_test.rb +4 -6
  42. data/acceptance/tests/base/dsl/platform_tag_confiner_test.rb +14 -17
  43. data/acceptance/tests/base/dsl/structure_test.rb +9 -21
  44. data/acceptance/tests/base/host/file_test.rb +8 -8
  45. data/acceptance/tests/base/host/group_test.rb +2 -3
  46. data/acceptance/tests/base/host/host_test.rb +69 -66
  47. data/acceptance/tests/base/host/packages.rb +27 -30
  48. data/acceptance/tests/base/host/packages_unix.rb +0 -55
  49. data/acceptance/tests/base/host/user_test.rb +2 -3
  50. data/acceptance/tests/base/host_prebuilt_steps/ssh_environment_test.rb +1 -2
  51. data/acceptance/tests/base/test_suite/export.rb +6 -9
  52. data/acceptance/tests/install/from_file.rb +3 -5
  53. data/acceptance/tests/load_path_bootstrap.rb +1 -1
  54. data/acceptance/tests/subcommands/destroy.rb +19 -21
  55. data/acceptance/tests/subcommands/exec.rb +0 -1
  56. data/acceptance/tests/subcommands/init.rb +2 -3
  57. data/acceptance/tests/subcommands/provision.rb +0 -1
  58. data/beaker.gemspec +10 -14
  59. data/docs/concepts/argument_processing_and_precedence.md +1 -10
  60. data/docs/concepts/style_guide.md +1 -1
  61. data/docs/how_to/debug_beaker_tests.md +13 -13
  62. data/docs/how_to/hosts/eos.md +2 -12
  63. data/docs/how_to/install_puppet.md +0 -18
  64. data/docs/how_to/test_arbitrary_beaker_versions.md +2 -2
  65. data/docs/how_to/the_beaker_dsl.md +0 -2
  66. data/lib/beaker/cli.rb +63 -74
  67. data/lib/beaker/command.rb +22 -30
  68. data/lib/beaker/command_factory.rb +4 -3
  69. data/lib/beaker/dsl/assertions.rb +7 -19
  70. data/lib/beaker/dsl/helpers/hocon_helpers.rb +5 -9
  71. data/lib/beaker/dsl/helpers/host_helpers.rb +72 -133
  72. data/lib/beaker/dsl/helpers/test_helpers.rb +3 -5
  73. data/lib/beaker/dsl/helpers/web_helpers.rb +20 -28
  74. data/lib/beaker/dsl/helpers.rb +2 -4
  75. data/lib/beaker/dsl/outcomes.rb +17 -19
  76. data/lib/beaker/dsl/patterns.rb +1 -3
  77. data/lib/beaker/dsl/roles.rb +18 -21
  78. data/lib/beaker/dsl/structure.rb +55 -67
  79. data/lib/beaker/dsl/test_tagging.rb +7 -10
  80. data/lib/beaker/dsl/wrappers.rb +15 -16
  81. data/lib/beaker/dsl.rb +2 -3
  82. data/lib/beaker/host/aix/exec.rb +1 -1
  83. data/lib/beaker/host/aix/file.rb +0 -1
  84. data/lib/beaker/host/aix/group.rb +3 -3
  85. data/lib/beaker/host/aix/user.rb +3 -3
  86. data/lib/beaker/host/aix.rb +3 -4
  87. data/lib/beaker/host/cisco.rb +36 -48
  88. data/lib/beaker/host/eos.rb +4 -30
  89. data/lib/beaker/host/freebsd/exec.rb +1 -1
  90. data/lib/beaker/host/freebsd/pkg.rb +3 -3
  91. data/lib/beaker/host/freebsd.rb +9 -12
  92. data/lib/beaker/host/mac/exec.rb +5 -5
  93. data/lib/beaker/host/mac/group.rb +13 -13
  94. data/lib/beaker/host/mac/pkg.rb +6 -109
  95. data/lib/beaker/host/mac/user.rb +7 -7
  96. data/lib/beaker/host/mac.rb +8 -9
  97. data/lib/beaker/host/pswindows/exec.rb +70 -74
  98. data/lib/beaker/host/pswindows/file.rb +4 -6
  99. data/lib/beaker/host/pswindows/group.rb +5 -5
  100. data/lib/beaker/host/pswindows/pkg.rb +17 -17
  101. data/lib/beaker/host/pswindows/user.rb +4 -4
  102. data/lib/beaker/host/pswindows.rb +4 -3
  103. data/lib/beaker/host/unix/exec.rb +86 -88
  104. data/lib/beaker/host/unix/file.rb +41 -47
  105. data/lib/beaker/host/unix/group.rb +3 -3
  106. data/lib/beaker/host/unix/pkg.rb +158 -421
  107. data/lib/beaker/host/unix/user.rb +4 -4
  108. data/lib/beaker/host/unix.rb +18 -20
  109. data/lib/beaker/host/windows/exec.rb +20 -20
  110. data/lib/beaker/host/windows/file.rb +5 -5
  111. data/lib/beaker/host/windows/group.rb +5 -5
  112. data/lib/beaker/host/windows/pkg.rb +6 -57
  113. data/lib/beaker/host/windows/user.rb +4 -4
  114. data/lib/beaker/host/windows.rb +13 -13
  115. data/lib/beaker/host.rb +82 -139
  116. data/lib/beaker/host_prebuilt_steps.rb +121 -233
  117. data/lib/beaker/hypervisor/noop.rb +2 -4
  118. data/lib/beaker/hypervisor.rb +46 -63
  119. data/lib/beaker/local_connection.rb +4 -6
  120. data/lib/beaker/logger.rb +71 -85
  121. data/lib/beaker/logger_junit.rb +22 -26
  122. data/lib/beaker/network_manager.rb +40 -43
  123. data/lib/beaker/options/command_line_parser.rb +12 -23
  124. data/lib/beaker/options/hosts_file_parser.rb +34 -25
  125. data/lib/beaker/options/options_file_parser.rb +3 -6
  126. data/lib/beaker/options/options_hash.rb +3 -10
  127. data/lib/beaker/options/parser.rb +89 -105
  128. data/lib/beaker/options/presets.rb +114 -123
  129. data/lib/beaker/options/subcommand_options_file_parser.rb +3 -6
  130. data/lib/beaker/options/validator.rb +26 -31
  131. data/lib/beaker/perf.rb +29 -34
  132. data/lib/beaker/platform.rb +38 -46
  133. data/lib/beaker/result.rb +7 -6
  134. data/lib/beaker/shared/error_handler.rb +8 -10
  135. data/lib/beaker/shared/fog_credentials.rb +5 -9
  136. data/lib/beaker/shared/host_manager.rb +40 -46
  137. data/lib/beaker/shared/options_resolver.rb +3 -7
  138. data/lib/beaker/shared/repetition.rb +6 -8
  139. data/lib/beaker/shared/semvar.rb +39 -43
  140. data/lib/beaker/shared/timed.rb +2 -5
  141. data/lib/beaker/shared.rb +1 -1
  142. data/lib/beaker/ssh_connection.rb +46 -55
  143. data/lib/beaker/subcommand.rb +23 -30
  144. data/lib/beaker/subcommands/subcommand_util.rb +4 -4
  145. data/lib/beaker/tasks/quick_start.rb +5 -10
  146. data/lib/beaker/tasks/rake_task.rb +26 -28
  147. data/lib/beaker/tasks/test.rb +4 -4
  148. data/lib/beaker/test_case.rb +15 -27
  149. data/lib/beaker/test_suite.rb +35 -39
  150. data/lib/beaker/test_suite_result.rb +52 -57
  151. data/lib/beaker/version.rb +1 -1
  152. data/lib/beaker.rb +5 -6
  153. data/spec/beaker/cli_spec.rb +135 -153
  154. data/spec/beaker/command_spec.rb +64 -58
  155. data/spec/beaker/dsl/assertions_spec.rb +38 -47
  156. data/spec/beaker/dsl/helpers/host_helpers_spec.rb +114 -135
  157. data/spec/beaker/dsl/helpers/test_helpers_spec.rb +9 -10
  158. data/spec/beaker/dsl/helpers/web_helpers_spec.rb +30 -36
  159. data/spec/beaker/dsl/outcomes_spec.rb +15 -14
  160. data/spec/beaker/dsl/roles_spec.rb +170 -132
  161. data/spec/beaker/dsl/structure_spec.rb +181 -163
  162. data/spec/beaker/dsl/test_tagging_spec.rb +94 -95
  163. data/spec/beaker/dsl/wrappers_spec.rb +39 -40
  164. data/spec/beaker/host/aix_spec.rb +14 -14
  165. data/spec/beaker/host/cisco_spec.rb +92 -102
  166. data/spec/beaker/host/eos_spec.rb +15 -36
  167. data/spec/beaker/host/freebsd/exec_spec.rb +5 -8
  168. data/spec/beaker/host/freebsd/pkg_spec.rb +29 -29
  169. data/spec/beaker/host/mac/exec_spec.rb +4 -5
  170. data/spec/beaker/host/mac/group_spec.rb +47 -56
  171. data/spec/beaker/host/mac/user_spec.rb +53 -62
  172. data/spec/beaker/host/pswindows/exec_spec.rb +36 -35
  173. data/spec/beaker/host/pswindows/file_spec.rb +21 -18
  174. data/spec/beaker/host/pswindows/user_spec.rb +17 -23
  175. data/spec/beaker/host/pswindows_spec.rb +14 -14
  176. data/spec/beaker/host/unix/exec_spec.rb +87 -92
  177. data/spec/beaker/host/unix/file_spec.rb +76 -82
  178. data/spec/beaker/host/unix/pkg_spec.rb +165 -407
  179. data/spec/beaker/host/unix_spec.rb +11 -207
  180. data/spec/beaker/host/windows/exec_spec.rb +32 -34
  181. data/spec/beaker/host/windows/file_spec.rb +22 -23
  182. data/spec/beaker/host/windows/group_spec.rb +17 -19
  183. data/spec/beaker/host/windows/pkg_spec.rb +10 -13
  184. data/spec/beaker/host/windows/user_spec.rb +17 -23
  185. data/spec/beaker/host/windows_spec.rb +39 -39
  186. data/spec/beaker/host_prebuilt_steps_spec.rb +193 -341
  187. data/spec/beaker/host_spec.rb +241 -312
  188. data/spec/beaker/hypervisor/hypervisor_spec.rb +38 -63
  189. data/spec/beaker/localhost_connection_spec.rb +14 -13
  190. data/spec/beaker/logger_junit_spec.rb +22 -34
  191. data/spec/beaker/logger_spec.rb +174 -155
  192. data/spec/beaker/network_manager_spec.rb +27 -27
  193. data/spec/beaker/options/command_line_parser_spec.rb +20 -23
  194. data/spec/beaker/options/data/hosts_preserved.yml +395 -0
  195. data/spec/beaker/options/hosts_file_parser_spec.rb +36 -31
  196. data/spec/beaker/options/options_file_parser_spec.rb +4 -7
  197. data/spec/beaker/options/options_hash_spec.rb +7 -9
  198. data/spec/beaker/options/parser_spec.rb +187 -187
  199. data/spec/beaker/options/presets_spec.rb +8 -10
  200. data/spec/beaker/options/subcommand_options_parser_spec.rb +15 -15
  201. data/spec/beaker/options/validator_spec.rb +27 -28
  202. data/spec/beaker/perf_spec.rb +32 -34
  203. data/spec/beaker/platform_spec.rb +27 -37
  204. data/spec/beaker/shared/error_handler_spec.rb +8 -17
  205. data/spec/beaker/shared/fog_credentials_spec.rb +30 -30
  206. data/spec/beaker/shared/host_manager_spec.rb +55 -89
  207. data/spec/beaker/shared/options_resolver_spec.rb +9 -12
  208. data/spec/beaker/shared/repetition_spec.rb +24 -31
  209. data/spec/beaker/shared/semvar_spec.rb +21 -26
  210. data/spec/beaker/ssh_connection_spec.rb +85 -90
  211. data/spec/beaker/subcommand/subcommand_util_spec.rb +40 -37
  212. data/spec/beaker/subcommand_spec.rb +89 -89
  213. data/spec/beaker/test_case_spec.rb +33 -62
  214. data/spec/beaker/test_suite_spec.rb +153 -160
  215. data/spec/helpers.rb +48 -53
  216. data/spec/matchers.rb +9 -8
  217. data/spec/mocks.rb +6 -11
  218. data/spec/spec_helper.rb +0 -4
  219. metadata +60 -85
  220. data/acceptance/tests/base/dsl/helpers/host_helpers/deploy_package_repo_test.rb +0 -142
  221. data/acceptance/tests/base/external_resources_test.rb +0 -31
  222. data/spec/beaker/host/mac_spec.rb +0 -113
  223. data/spec/mock_fission.rb +0 -60
  224. data/spec/mock_vsphere.rb +0 -314
  225. data/spec/mock_vsphere_helper.rb +0 -183
@@ -11,7 +11,7 @@ module Unix::Exec
11
11
  # @param [Integer] uptime_retries How many times to check to see if the value of the uptime has reset.
12
12
  #
13
13
  # Will throw an exception RebootFailure if it fails
14
- def reboot(wait_time=10, max_connection_tries=9, uptime_retries=18)
14
+ def reboot(wait_time = 10, max_connection_tries = 9, uptime_retries = 18)
15
15
  require 'time'
16
16
 
17
17
  attempts = 0
@@ -30,7 +30,7 @@ module Unix::Exec
30
30
  # Number of seconds to sleep before rebooting.
31
31
  reboot_sleep = 1
32
32
 
33
- original_boot_time_str = exec(Beaker::Command.new(boot_time_cmd), {:max_connection_tries => max_connection_tries, :silent => true}).stdout
33
+ original_boot_time_str = exec(Beaker::Command.new(boot_time_cmd), { :max_connection_tries => max_connection_tries, :silent => true }).stdout
34
34
  original_boot_time_line = original_boot_time_str.lines.grep(/boot/).first
35
35
 
36
36
  raise Beaker::Host::RebootWarning, "Could not find system boot time using '#{boot_time_cmd}': '#{original_boot_time_str}'" unless original_boot_time_line
@@ -41,9 +41,7 @@ module Unix::Exec
41
41
 
42
42
  original_boot_time = Time.parse(original_boot_time_matches.first)
43
43
 
44
- unless original_boot_time_matches.last
45
- reboot_sleep = (61 - Time.now.strftime("%S").to_i)
46
- end
44
+ reboot_sleep = (61 - Time.now.strftime("%S").to_i) unless original_boot_time_matches.last
47
45
 
48
46
  @logger.notify("Sleeping #{reboot_sleep} seconds before rebooting")
49
47
 
@@ -54,14 +52,16 @@ module Unix::Exec
54
52
  raise Beaker::Host::RebootFailure, "Unable to parse time: #{e.message}"
55
53
  rescue Beaker::Host::RebootWarning => e
56
54
  raise if attempts > uptime_retries
55
+
57
56
  @logger.warn(e.message)
58
57
  @logger.warn("Retrying #{uptime_retries - attempts} more times.")
59
58
  retry
60
59
  rescue StandardError => e
61
60
  raise if attempts > uptime_retries
61
+
62
62
  @logger.warn("Unexpected Exception: #{e.message}")
63
63
  @logger.warn("Retrying #{uptime_retries - attempts} more times.")
64
- @logger.warn(e.backtrace[0,3].join("\n"))
64
+ @logger.warn(e.backtrace[0, 3].join("\n"))
65
65
  @logger.debug(e.backtrace.join("\n"))
66
66
  retry
67
67
  end
@@ -75,7 +75,7 @@ module Unix::Exec
75
75
  sleep wait_time
76
76
 
77
77
  # Accept all exit codes because this may fail due to the parallel nature of systemd
78
- current_boot_time_str = exec(Beaker::Command.new(boot_time_cmd), {:max_connection_tries => max_connection_tries, :silent => true, :accept_all_exit_codes => true}).stdout
78
+ current_boot_time_str = exec(Beaker::Command.new(boot_time_cmd), { :max_connection_tries => max_connection_tries, :silent => true, :accept_all_exit_codes => true }).stdout
79
79
  current_boot_time_line = current_boot_time_str.lines.grep(/boot/).first
80
80
 
81
81
  raise Beaker::Host::RebootWarning, "Could not find system boot time using '#{boot_time_cmd}': '#{current_boot_time_str}'" unless current_boot_time_line
@@ -90,33 +90,33 @@ module Unix::Exec
90
90
  @logger.debug("Current Boot Time: #{current_boot_time}")
91
91
 
92
92
  # If this is *exactly* the same then there is really no good way to detect a reboot
93
- if current_boot_time == original_boot_time
94
- raise Beaker::Host::RebootFailure, "Boot time did not reset. Reboot appears to have failed."
95
- end
93
+ raise Beaker::Host::RebootFailure, "Boot time did not reset. Reboot appears to have failed." if current_boot_time == original_boot_time
96
94
  rescue ArgumentError => e
97
95
  raise Beaker::Host::RebootFailure, "Unable to parse time: #{e.message}"
98
96
  rescue Beaker::Host::RebootFailure => e
99
97
  raise
100
98
  rescue Beaker::Host::RebootWarning => e
101
99
  raise if attempts > uptime_retries
100
+
102
101
  @logger.warn(e.message)
103
102
  @logger.warn("Retrying #{uptime_retries - attempts} more times.")
104
103
  retry
105
104
  rescue StandardError => e
106
105
  raise if attempts > uptime_retries
106
+
107
107
  @logger.warn("Unexpected Exception: #{e.message}")
108
108
  @logger.warn("Retrying #{uptime_retries - attempts} more times.")
109
- @logger.warn(e.backtrace[0,3].join("\n"))
109
+ @logger.warn(e.backtrace[0, 3].join("\n"))
110
110
  @logger.debug(e.backtrace.join("\n"))
111
111
  retry
112
112
  end
113
113
  end
114
114
 
115
- def echo(msg, abs=true)
115
+ def echo(msg, abs = true)
116
116
  (abs ? '/bin/echo' : 'echo') + " #{msg}"
117
117
  end
118
118
 
119
- def touch(file, abs=true)
119
+ def touch(file, abs = true)
120
120
  (abs ? '/bin/touch' : 'touch') + " #{file}"
121
121
  end
122
122
 
@@ -163,7 +163,7 @@ module Unix::Exec
163
163
  # @param [String] orig The origin path
164
164
  # @param [String] dest the destination path
165
165
  # @param [Boolean] rm Remove the destination prior to move
166
- def mv orig, dest, rm=true
166
+ def mv orig, dest, rm = true
167
167
  rm_rf dest unless !rm
168
168
  execute("mv #{orig} #{dest}")
169
169
  end
@@ -172,14 +172,13 @@ module Unix::Exec
172
172
  # @param [String] target The hostname to ping
173
173
  # @param [Integer] attempts Amount of times to attempt ping before giving up
174
174
  # @return [Boolean] true of ping successful, overwise false
175
- def ping target, attempts=5
175
+ def ping target, attempts = 5
176
176
  try = 0
177
- while try < attempts do
177
+ while try < attempts
178
178
  result = exec(Beaker::Command.new("ping -c 1 #{target}"), :accept_all_exit_codes => true)
179
- if result.exit_code == 0
180
- return true
181
- end
182
- try+=1
179
+ return true if result.exit_code == 0
180
+
181
+ try += 1
183
182
  end
184
183
  result.exit_code == 0
185
184
  end
@@ -188,88 +187,89 @@ module Unix::Exec
188
187
  # This is for sles based hosts.
189
188
  # @param [String] env_file The ssh environment file to read from
190
189
  def mirror_env_to_profile_d env_file
191
- if self[:platform] =~ /opensuse|sles-/
190
+ if /opensuse|sles-/.match?(self[:platform])
192
191
  @logger.debug("mirroring environment to /etc/profile.d on opensuse/sles platform host")
193
192
  cur_env = exec(Beaker::Command.new("cat #{env_file}")).stdout
194
193
  shell_env = ''
195
194
  cur_env.each_line do |env_line|
196
195
  shell_env << "export #{env_line}"
197
196
  end
198
- #here doc it over
197
+ # here doc it over
199
198
  exec(Beaker::Command.new("cat << EOF > #{self[:profile_d_env_file]}\n#{shell_env}EOF"))
200
- #set permissions
199
+ # set permissions
201
200
  exec(Beaker::Command.new("chmod +x #{self[:profile_d_env_file]}"))
202
- #keep it current
201
+ # keep it current
203
202
  exec(Beaker::Command.new("source #{self[:profile_d_env_file]}"))
204
203
  else
205
- #noop
204
+ # noop
206
205
  @logger.debug("will not mirror environment to /etc/profile.d on non-sles platform host")
207
206
  end
208
207
  end
209
208
 
210
- #Add the provided key/val to the current ssh environment
211
- #@param [String] key The key to add the value to
212
- #@param [String] val The value for the key
213
- #@example
209
+ # Add the provided key/val to the current ssh environment
210
+ # @param [String] key The key to add the value to
211
+ # @param [String] val The value for the key
212
+ # @example
214
213
  # host.add_env_var('PATH', '/usr/bin:PATH')
215
214
  def add_env_var key, val
216
215
  key = key.to_s
217
216
  env_file = self[:ssh_env_file]
218
217
  escaped_val = Regexp.escape(val).gsub('/', '\/').gsub(';', '\;')
219
- #see if the key/value pair already exists
220
- if exec(Beaker::Command.new("grep ^#{key}=.*#{escaped_val} #{env_file}"), :accept_all_exit_codes => true ).exit_code == 0
221
- return #nothing to do here, key value pair already exists
222
- #see if the key already exists
223
- elsif exec(Beaker::Command.new("grep ^#{key}= #{env_file}"), :accept_all_exit_codes => true ).exit_code == 0
218
+ # see if the key/value pair already exists
219
+ if exec(Beaker::Command.new("grep ^#{key}=.*#{escaped_val} #{env_file}"), :accept_all_exit_codes => true).exit_code == 0
220
+ return # nothing to do here, key value pair already exists
221
+ # see if the key already exists
222
+ elsif exec(Beaker::Command.new("grep ^#{key}= #{env_file}"), :accept_all_exit_codes => true).exit_code == 0
224
223
  exec(Beaker::SedCommand.new(self['platform'], "s/^#{key}=/#{key}=#{escaped_val}:/", env_file))
225
224
  else
226
225
  exec(Beaker::Command.new("echo \"#{key}=#{val}\" >> #{env_file}"))
227
226
  end
228
- #update the profile.d to current state
229
- #match it to the contents of ssh_env_file
227
+
228
+ # update the profile.d to current state
229
+ # match it to the contents of ssh_env_file
230
230
  mirror_env_to_profile_d(env_file)
231
231
  end
232
232
 
233
- #Delete the provided key/val from the current ssh environment
234
- #@param [String] key The key to delete the value from
235
- #@param [String] val The value to delete for the key
236
- #@example
233
+ # Delete the provided key/val from the current ssh environment
234
+ # @param [String] key The key to delete the value from
235
+ # @param [String] val The value to delete for the key
236
+ # @example
237
237
  # host.delete_env_var('PATH', '/usr/bin:PATH')
238
238
  def delete_env_var key, val
239
239
  key = key.to_s
240
240
  env_file = self[:ssh_env_file]
241
241
  val = Regexp.escape(val).gsub('/', '\/').gsub(';', '\;')
242
- #if the key only has that single value remove the entire line
242
+ # if the key only has that single value remove the entire line
243
243
  exec(Beaker::SedCommand.new(self['platform'], "/#{key}=#{val}$/d", env_file))
244
- #value in middle of list
244
+ # value in middle of list
245
245
  exec(Beaker::SedCommand.new(self['platform'], "s/#{key}=\\(.*\\)[;:]#{val}/#{key}=\\1/", env_file))
246
- #value in start of list
246
+ # value in start of list
247
247
  exec(Beaker::SedCommand.new(self['platform'], "s/#{key}=#{val}[;:]/#{key}=/", env_file))
248
- #update the profile.d to current state
249
- #match it to the contents of ssh_env_file
248
+ # update the profile.d to current state
249
+ # match it to the contents of ssh_env_file
250
250
  mirror_env_to_profile_d(env_file)
251
251
  end
252
252
 
253
- #Return the value of a specific env var
254
- #@param [String] key The key to look for
255
- #@example
253
+ # Return the value of a specific env var
254
+ # @param [String] key The key to look for
255
+ # @example
256
256
  # host.get_env_var('path')
257
257
  def get_env_var key
258
258
  key = key.to_s
259
259
  exec(Beaker::Command.new("env | grep ^#{key}="), :accept_all_exit_codes => true).stdout.chomp
260
260
  end
261
261
 
262
- #Delete the environment variable from the current ssh environment
263
- #@param [String] key The key to delete
264
- #@example
262
+ # Delete the environment variable from the current ssh environment
263
+ # @param [String] key The key to delete
264
+ # @example
265
265
  # host.clear_env_var('PATH')
266
266
  def clear_env_var key
267
267
  key = key.to_s
268
268
  env_file = self[:ssh_env_file]
269
- #remove entire line
269
+ # remove entire line
270
270
  exec(Beaker::SedCommand.new(self['platform'], "/^#{key}=.*$/d", env_file))
271
- #update the profile.d to current state
272
- #match it to the contents of ssh_env_file
271
+ # update the profile.d to current state
272
+ # match it to the contents of ssh_env_file
273
273
  mirror_env_to_profile_d(env_file)
274
274
  end
275
275
 
@@ -303,17 +303,17 @@ module Unix::Exec
303
303
  def ssh_permit_user_environment
304
304
  case self['platform']
305
305
  when /debian|ubuntu|cumulus|huaweios|archlinux|el-|centos|fedora|redhat|oracle|scientific|eos|opensuse|sles|solaris/
306
- directory = tmpdir()
306
+ directory = tmpdir
307
307
  exec(Beaker::Command.new("echo 'PermitUserEnvironment yes' | cat - /etc/ssh/sshd_config > #{directory}/sshd_config.permit"))
308
308
  exec(Beaker::Command.new("mv #{directory}/sshd_config.permit /etc/ssh/sshd_config"))
309
- exec(Beaker::Command.new("echo '' >/etc/environment")) if self['platform'] =~ /ubuntu-2(0|2).04/
309
+ exec(Beaker::Command.new("echo '' >/etc/environment")) if /ubuntu-2(0|2).04/.match?(self['platform'])
310
310
  when /(free|open)bsd/
311
- exec(Beaker::Command.new("sudo perl -pi -e 's/^#?PermitUserEnvironment no/PermitUserEnvironment yes/' /etc/ssh/sshd_config"), {:pty => true} )
311
+ exec(Beaker::Command.new("sudo perl -pi -e 's/^#?PermitUserEnvironment no/PermitUserEnvironment yes/' /etc/ssh/sshd_config"), { :pty => true })
312
312
  else
313
313
  raise ArgumentError, "Unsupported Platform: '#{self['platform']}'"
314
314
  end
315
315
 
316
- ssh_service_restart()
316
+ ssh_service_restart
317
317
  end
318
318
 
319
319
  # Construct the environment string for this command
@@ -329,7 +329,8 @@ module Unix::Exec
329
329
  # given host.
330
330
  def environment_string env
331
331
  return '' if env.empty?
332
- env_array = self.environment_variable_string_pair_array( env )
332
+
333
+ env_array = self.environment_variable_string_pair_array(env)
333
334
  environment_string = env_array.join(' ')
334
335
  "env #{environment_string}"
335
336
  end
@@ -338,11 +339,11 @@ module Unix::Exec
338
339
  env_array = []
339
340
  env.each_key do |key|
340
341
  val = env[key]
341
- if val.is_a?(Array)
342
- val = val.join(':')
343
- else
344
- val = val.to_s
345
- end
342
+ val = if val.is_a?(Array)
343
+ val.join(':')
344
+ else
345
+ val.to_s
346
+ end
346
347
  # doing this for the key itself & the upcase'd version allows us to remain
347
348
  # backwards compatible
348
349
  # TODO: (Next Major Version) get rid of upcase'd version
@@ -363,7 +364,7 @@ module Unix::Exec
363
364
  # @param [Hash] opts optional parameters
364
365
  #
365
366
  # @return [String] Command string as needed for this host
366
- def prepend_commands(command = '', user_pc = '', opts = {})
367
+ def prepend_commands(_command = '', user_pc = '', _opts = {})
367
368
  user_pc
368
369
  end
369
370
 
@@ -374,7 +375,7 @@ module Unix::Exec
374
375
  # @param [Hash] opts optional parameters
375
376
  #
376
377
  # @return [String] Command string as needed for this host
377
- def append_commands(command = '', user_ac = '', opts = {})
378
+ def append_commands(_command = '', user_ac = '', _opts = {})
378
379
  user_ac
379
380
  end
380
381
 
@@ -387,44 +388,42 @@ module Unix::Exec
387
388
  # @api private
388
389
  # @return nil
389
390
  def ssh_set_user_environment(env)
390
- #ensure that ~/.ssh/environment exists
391
+ # ensure that ~/.ssh/environment exists
391
392
  ssh_env_file_dir = Pathname.new(self[:ssh_env_file]).dirname
392
393
  mkdir_p(ssh_env_file_dir)
393
394
  exec(Beaker::Command.new("chmod 0600 #{ssh_env_file_dir}"))
394
395
  exec(Beaker::Command.new("touch #{self[:ssh_env_file]}"))
395
- #add the constructed env vars to this host
396
+ # add the constructed env vars to this host
396
397
  add_env_var('PATH', '$PATH')
397
- # FIXME
398
- if self['platform'] =~ /openbsd-(\d)\.?(\d)-(.+)/
399
- version = "#{$1}.#{$2}"
400
- arch = $3
401
- arch = 'amd64' if ['x64', 'x86_64'].include?(arch)
402
- add_env_var('PKG_PATH', "http://ftp.openbsd.org/pub/OpenBSD/#{version}/packages/#{arch}/")
403
- elsif self['platform'] =~ /solaris-10/
398
+ if self['platform'].variant == 'openbsd'
399
+ arch = self['platform'].arch
400
+ arch = 'amd64' if %w[x64 x86_64].include?(arch)
401
+ add_env_var('PKG_PATH', "http://ftp.openbsd.org/pub/OpenBSD/#{self['platform'].version}/packages/#{arch}/")
402
+ elsif self['platform'].include?('solaris-10')
404
403
  add_env_var('PATH', '/opt/csw/bin')
405
404
  end
406
405
 
407
- #add the env var set to this test host
406
+ # add the env var set to this test host
408
407
  env.each_pair do |var, value|
409
408
  add_env_var(var, value)
410
409
  end
411
410
  end
412
411
 
413
- # Checks if selinux is enabled
412
+ #  Checks if selinux is enabled
414
413
  #
415
414
  # @return [Boolean] true if selinux is enabled, false otherwise
416
- def selinux_enabled?()
415
+ def selinux_enabled?
417
416
  exec(Beaker::Command.new("sudo selinuxenabled"), :accept_all_exit_codes => true).exit_code == 0
418
417
  end
419
418
 
420
419
  def enable_remote_rsyslog(server = 'rsyslog.ops.puppetlabs.net', port = 514)
421
- if self['platform'] !~ /ubuntu/
420
+ if !self['platform'].include?('ubuntu')
422
421
  @logger.warn "Enabling rsyslog is only implemented for ubuntu hosts"
423
422
  return
424
423
  end
425
424
  commands = [
426
425
  "echo '*.* @#{server}:#{port}' >> /etc/rsyslog.d/51-sendrsyslogs.conf",
427
- 'systemctl restart rsyslog'
426
+ 'systemctl restart rsyslog',
428
427
  ]
429
428
  commands.each do |command|
430
429
  exec(Beaker::Command.new(command))
@@ -432,21 +431,20 @@ module Unix::Exec
432
431
  true
433
432
  end
434
433
 
435
- #First path it finds for the command executable
436
- #@param [String] command The command executable to search for
434
+ # First path it finds for the command executable
435
+ # @param [String] command The command executable to search for
437
436
  #
438
437
  # @return [String] Path to the searched executable or empty string if not found
439
438
  #
440
- #@example
439
+ # @example
441
440
  # host.which('ruby')
442
441
  def which(command)
443
442
  unless @which_command
444
443
  if execute('type -P true', :accept_all_exit_codes => true).empty?
445
- if execute('which true', :accept_all_exit_codes => true).empty?
446
- raise ArgumentError, "Could not find suitable 'which' command"
447
- else
448
- @which_command = 'which'
449
- end
444
+ raise ArgumentError, "Could not find suitable 'which' command" if execute('which true', :accept_all_exit_codes => true).empty?
445
+
446
+ @which_command = 'which'
447
+
450
448
  else
451
449
  @which_command = 'type -P'
452
450
  end
@@ -26,11 +26,11 @@ module Unix::File
26
26
  # @param [Boolean] recursive Whether to pass the recursive flag
27
27
  #
28
28
  # @return [Beaker::Result] result of command execution
29
- def chown(user, path, recursive=false)
29
+ def chown(user, path, recursive = false)
30
30
  execute("chown #{recursive ? '-R ' : ''}#{user} #{path}")
31
31
  end
32
32
 
33
- def chmod(mod, path, recursive=false)
33
+ def chmod(mod, path, recursive = false)
34
34
  execute("chmod #{recursive ? '-R ' : ''}#{mod} #{path}")
35
35
  end
36
36
 
@@ -43,7 +43,7 @@ module Unix::File
43
43
  # @param [Boolean] recursive Whether to pass the recursive flag
44
44
  #
45
45
  # @return [Beaker::Result] result of command execution
46
- def chgrp(group, path, recursive=false)
46
+ def chgrp(group, path, recursive = false)
47
47
  execute("chgrp #{recursive ? '-R ' : ''}#{group} #{path}")
48
48
  end
49
49
 
@@ -110,13 +110,13 @@ module Unix::File
110
110
  # @return [String] Filename of the repo
111
111
  def repo_filename(package_name, build_version)
112
112
  variant, version, arch, codename = self['platform'].to_array
113
- repo_filename = "pl-%s-%s-" % [ package_name, build_version ]
113
+ repo_filename = format("pl-%s-%s-", package_name, build_version)
114
114
 
115
115
  case variant
116
116
  when /fedora|el|redhat|centos|cisco_nexus|cisco_ios_xr|opensuse|sles/
117
- variant = 'el' if ['centos', 'redhat'].include?(variant)
117
+ variant = 'el' if %w[centos redhat].include?(variant)
118
118
 
119
- variant = 'redhatfips' if self['packaging_platform'] =~ /redhatfips/
119
+ variant = 'redhatfips' if self['packaging_platform']&.include?('redhatfips')
120
120
 
121
121
  if variant == 'cisco_nexus'
122
122
  variant = 'cisco-wrlinux'
@@ -126,19 +126,14 @@ module Unix::File
126
126
  variant = 'cisco-wrlinux'
127
127
  version = '7'
128
128
  end
129
- fedora_prefix = ((variant == 'fedora') ? 'f' : '')
129
+ fedora_prefix = (variant == 'fedora' ? 'f' : '')
130
130
 
131
131
  pattern = "%s-%s%s-%s.repo"
132
132
 
133
- repo_filename << pattern % [
134
- variant,
135
- fedora_prefix,
136
- version,
137
- arch
138
- ]
133
+ repo_filename << (format(pattern, variant, fedora_prefix, version, arch))
139
134
  when /debian|ubuntu|cumulus|huaweios/
140
135
  codename = variant if variant == 'cumulus' || variant == 'huaweios'
141
- repo_filename << "%s.list" % [ codename ]
136
+ repo_filename << (format("%s.list", codename))
142
137
  else
143
138
  msg = "#repo_filename: repo filename pattern not known for platform '#{self['platform']}'"
144
139
  raise ArgumentError, msg
@@ -170,38 +165,37 @@ module Unix::File
170
165
  #
171
166
  # @return [String] the text of the noask file
172
167
  def noask_file_text
173
- variant, version, arch, codename = self['platform'].to_array
174
- if variant == 'solaris' && version == '10'
175
- noask = <<NOASK
176
- # Write the noask file to a temporary directory
177
- # please see man -s 4 admin for details about this file:
178
- # http://www.opensolarisforum.org/man/man4/admin.html
179
- #
180
- # The key thing we don't want to prompt for are conflicting files.
181
- # The other nocheck settings are mostly defensive to prevent prompts
182
- # We _do_ want to check for available free space and abort if there is
183
- # not enough
184
- mail=
185
- # Overwrite already installed instances
186
- instance=overwrite
187
- # Do not bother checking for partially installed packages
188
- partial=nocheck
189
- # Do not bother checking the runlevel
190
- runlevel=nocheck
191
- # Do not bother checking package dependencies (We take care of this)
192
- idepend=nocheck
193
- rdepend=nocheck
194
- # DO check for available free space and abort if there isn't enough
195
- space=quit
196
- # Do not check for setuid files.
197
- setuid=nocheck
198
- # Do not check if files conflict with other packages
199
- conflict=nocheck
200
- # We have no action scripts. Do not check for them.
201
- action=nocheck
202
- # Install to the default base directory.
203
- basedir=default
204
- NOASK
168
+ if self['platform'].variant == 'solaris' && self['platform'].version == '10'
169
+ noask = <<~NOASK
170
+ # Write the noask file to a temporary directory
171
+ # please see man -s 4 admin for details about this file:
172
+ # http://www.opensolarisforum.org/man/man4/admin.html
173
+ #
174
+ # The key thing we don't want to prompt for are conflicting files.
175
+ # The other nocheck settings are mostly defensive to prevent prompts
176
+ # We _do_ want to check for available free space and abort if there is
177
+ # not enough
178
+ mail=
179
+ # Overwrite already installed instances
180
+ instance=overwrite
181
+ # Do not bother checking for partially installed packages
182
+ partial=nocheck
183
+ # Do not bother checking the runlevel
184
+ runlevel=nocheck
185
+ # Do not bother checking package dependencies (We take care of this)
186
+ idepend=nocheck
187
+ rdepend=nocheck
188
+ # DO check for available free space and abort if there isn't enough
189
+ space=quit
190
+ # Do not check for setuid files.
191
+ setuid=nocheck
192
+ # Do not check if files conflict with other packages
193
+ conflict=nocheck
194
+ # We have no action scripts. Do not check for them.
195
+ action=nocheck
196
+ # Install to the default base directory.
197
+ basedir=default
198
+ NOASK
205
199
  else
206
200
  msg = "noask file text unknown for platform '#{self['platform']}'"
207
201
  raise ArgumentError, msg
@@ -217,7 +211,7 @@ NOASK
217
211
  # @param [String] scp_file_target File path to target SCP location on host
218
212
  #
219
213
  # @return nil
220
- def scp_post_operations(scp_file_actual, scp_file_target)
214
+ def scp_post_operations(_scp_file_actual, _scp_file_target)
221
215
  nil
222
216
  end
223
217
  end
@@ -1,7 +1,7 @@
1
1
  module Unix::Group
2
2
  include Beaker::CommandFactory
3
3
 
4
- def group_list(&block)
4
+ def group_list
5
5
  execute("getent group") do |result|
6
6
  groups = []
7
7
  result.stdout.each_line do |line|
@@ -14,9 +14,9 @@ module Unix::Group
14
14
  end
15
15
  end
16
16
 
17
- def group_get(name, &block)
17
+ def group_get(name)
18
18
  execute("getent group #{name}") do |result|
19
- fail_test "failed to get group #{name}" unless result.stdout =~ /^#{name}:.*:[0-9]+:/
19
+ fail_test "failed to get group #{name}" unless /^#{name}:.*:[0-9]+:/.match?(result.stdout)
20
20
 
21
21
  yield result if block_given?
22
22
  result