beaker 4.40.1 → 5.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (217) hide show
  1. checksums.yaml +4 -4
  2. data/.github/dependabot.yml +9 -0
  3. data/.github/workflows/release.yml +2 -2
  4. data/.github/workflows/test.yml +26 -13
  5. data/.rubocop.yml +23 -10
  6. data/.rubocop_todo.yml +34 -10
  7. data/CHANGELOG.md +13 -11
  8. data/Gemfile +12 -7
  9. data/Rakefile +99 -111
  10. data/acceptance/config/acceptance-options.rb +1 -1
  11. data/acceptance/config/base/acceptance-options.rb +2 -2
  12. data/acceptance/config/hypervisor/acceptance-options.rb +2 -2
  13. data/acceptance/config/subcommands/acceptance-options.rb +2 -2
  14. data/acceptance/fixtures/module/Rakefile +1 -1
  15. data/acceptance/fixtures/module/spec/acceptance/demo_spec.rb +8 -12
  16. data/acceptance/fixtures/module/spec/classes/init_spec.rb +0 -1
  17. data/acceptance/fixtures/module/spec/spec_helper_acceptance.rb +3 -5
  18. data/acceptance/lib/helpers/test_helper.rb +4 -3
  19. data/acceptance/pre_suite/subcommands/05_install_ruby.rb +2 -3
  20. data/acceptance/pre_suite/subcommands/08_install_beaker.rb +1 -2
  21. data/acceptance/tests/base/dsl/helpers/configuration_test.rb +4 -4
  22. data/acceptance/tests/base/dsl/helpers/hocon_helpers_test.rb +1 -2
  23. data/acceptance/tests/base/dsl/helpers/host_helpers/add_system32_hosts_entry_test.rb +0 -3
  24. data/acceptance/tests/base/dsl/helpers/host_helpers/archive_file_from_test.rb +3 -1
  25. data/acceptance/tests/base/dsl/helpers/host_helpers/backup_the_file_test.rb +9 -9
  26. data/acceptance/tests/base/dsl/helpers/host_helpers/check_for_package_test.rb +0 -4
  27. data/acceptance/tests/base/dsl/helpers/host_helpers/create_remote_file_test.rb +19 -26
  28. data/acceptance/tests/base/dsl/helpers/host_helpers/curl_on_test.rb +2 -2
  29. data/acceptance/tests/base/dsl/helpers/host_helpers/curl_with_retries_test.rb +0 -1
  30. data/acceptance/tests/base/dsl/helpers/host_helpers/on_test.rb +18 -13
  31. data/acceptance/tests/base/dsl/helpers/host_helpers/retry_on_test.rb +3 -3
  32. data/acceptance/tests/base/dsl/helpers/host_helpers/rsync_to_test.rb +22 -27
  33. data/acceptance/tests/base/dsl/helpers/host_helpers/run_cron_on_test.rb +12 -16
  34. data/acceptance/tests/base/dsl/helpers/host_helpers/run_script_on_test.rb +3 -4
  35. data/acceptance/tests/base/dsl/helpers/host_helpers/run_script_test.rb +3 -3
  36. data/acceptance/tests/base/dsl/helpers/host_helpers/scp_from_test.rb +4 -4
  37. data/acceptance/tests/base/dsl/helpers/host_helpers/scp_to_test.rb +3 -4
  38. data/acceptance/tests/base/dsl/helpers/host_helpers/shell_test.rb +5 -5
  39. data/acceptance/tests/base/dsl/helpers/host_helpers/upgrade_package_test.rb +3 -5
  40. data/acceptance/tests/base/dsl/platform_tag_confiner_test.rb +14 -17
  41. data/acceptance/tests/base/dsl/structure_test.rb +5 -11
  42. data/acceptance/tests/base/host/file_test.rb +2 -2
  43. data/acceptance/tests/base/host/group_test.rb +0 -1
  44. data/acceptance/tests/base/host/host_test.rb +66 -63
  45. data/acceptance/tests/base/host/packages.rb +1 -2
  46. data/acceptance/tests/base/host/packages_unix.rb +0 -55
  47. data/acceptance/tests/base/host/user_test.rb +0 -1
  48. data/acceptance/tests/base/host_prebuilt_steps/ssh_environment_test.rb +1 -2
  49. data/acceptance/tests/base/test_suite/export.rb +6 -9
  50. data/acceptance/tests/install/from_file.rb +2 -4
  51. data/acceptance/tests/load_path_bootstrap.rb +1 -1
  52. data/acceptance/tests/subcommands/destroy.rb +19 -21
  53. data/acceptance/tests/subcommands/exec.rb +0 -1
  54. data/acceptance/tests/subcommands/init.rb +2 -3
  55. data/acceptance/tests/subcommands/provision.rb +0 -1
  56. data/beaker.gemspec +4 -7
  57. data/docs/concepts/argument_processing_and_precedence.md +1 -10
  58. data/docs/how_to/debug_beaker_tests.md +12 -12
  59. data/docs/how_to/hosts/eos.md +2 -12
  60. data/docs/how_to/install_puppet.md +0 -18
  61. data/docs/how_to/the_beaker_dsl.md +0 -2
  62. data/lib/beaker/cli.rb +59 -68
  63. data/lib/beaker/command.rb +20 -28
  64. data/lib/beaker/command_factory.rb +3 -2
  65. data/lib/beaker/dsl/assertions.rb +6 -18
  66. data/lib/beaker/dsl/helpers/hocon_helpers.rb +3 -7
  67. data/lib/beaker/dsl/helpers/host_helpers.rb +62 -123
  68. data/lib/beaker/dsl/helpers/test_helpers.rb +3 -5
  69. data/lib/beaker/dsl/helpers/web_helpers.rb +19 -39
  70. data/lib/beaker/dsl/helpers.rb +2 -4
  71. data/lib/beaker/dsl/outcomes.rb +13 -15
  72. data/lib/beaker/dsl/patterns.rb +1 -3
  73. data/lib/beaker/dsl/roles.rb +17 -20
  74. data/lib/beaker/dsl/structure.rb +53 -65
  75. data/lib/beaker/dsl/test_tagging.rb +7 -10
  76. data/lib/beaker/dsl/wrappers.rb +15 -16
  77. data/lib/beaker/dsl.rb +2 -3
  78. data/lib/beaker/host/aix/exec.rb +1 -1
  79. data/lib/beaker/host/aix/file.rb +0 -1
  80. data/lib/beaker/host/aix/group.rb +1 -1
  81. data/lib/beaker/host/aix/user.rb +1 -1
  82. data/lib/beaker/host/aix.rb +3 -4
  83. data/lib/beaker/host/cisco.rb +27 -39
  84. data/lib/beaker/host/eos.rb +4 -30
  85. data/lib/beaker/host/freebsd/exec.rb +1 -1
  86. data/lib/beaker/host/freebsd/pkg.rb +3 -3
  87. data/lib/beaker/host/freebsd.rb +9 -12
  88. data/lib/beaker/host/mac/exec.rb +4 -4
  89. data/lib/beaker/host/mac/group.rb +7 -7
  90. data/lib/beaker/host/mac/pkg.rb +3 -106
  91. data/lib/beaker/host/mac/user.rb +2 -2
  92. data/lib/beaker/host/mac.rb +8 -9
  93. data/lib/beaker/host/pswindows/exec.rb +66 -70
  94. data/lib/beaker/host/pswindows/file.rb +3 -5
  95. data/lib/beaker/host/pswindows/group.rb +3 -3
  96. data/lib/beaker/host/pswindows/pkg.rb +12 -12
  97. data/lib/beaker/host/pswindows/user.rb +3 -3
  98. data/lib/beaker/host/pswindows.rb +4 -3
  99. data/lib/beaker/host/unix/exec.rb +80 -82
  100. data/lib/beaker/host/unix/file.rb +38 -43
  101. data/lib/beaker/host/unix/group.rb +1 -1
  102. data/lib/beaker/host/unix/pkg.rb +154 -417
  103. data/lib/beaker/host/unix/user.rb +2 -2
  104. data/lib/beaker/host/unix.rb +8 -11
  105. data/lib/beaker/host/windows/exec.rb +17 -17
  106. data/lib/beaker/host/windows/file.rb +3 -3
  107. data/lib/beaker/host/windows/group.rb +3 -3
  108. data/lib/beaker/host/windows/pkg.rb +3 -54
  109. data/lib/beaker/host/windows/user.rb +3 -3
  110. data/lib/beaker/host/windows.rb +12 -12
  111. data/lib/beaker/host.rb +76 -133
  112. data/lib/beaker/host_prebuilt_steps.rb +93 -198
  113. data/lib/beaker/hypervisor/noop.rb +2 -4
  114. data/lib/beaker/hypervisor.rb +44 -61
  115. data/lib/beaker/local_connection.rb +2 -4
  116. data/lib/beaker/logger.rb +68 -76
  117. data/lib/beaker/logger_junit.rb +21 -25
  118. data/lib/beaker/network_manager.rb +39 -42
  119. data/lib/beaker/options/command_line_parser.rb +12 -23
  120. data/lib/beaker/options/hosts_file_parser.rb +16 -24
  121. data/lib/beaker/options/options_file_parser.rb +3 -6
  122. data/lib/beaker/options/options_hash.rb +2 -7
  123. data/lib/beaker/options/parser.rb +86 -102
  124. data/lib/beaker/options/presets.rb +114 -123
  125. data/lib/beaker/options/subcommand_options_file_parser.rb +3 -6
  126. data/lib/beaker/options/validator.rb +26 -31
  127. data/lib/beaker/perf.rb +22 -27
  128. data/lib/beaker/platform.rb +38 -46
  129. data/lib/beaker/result.rb +7 -6
  130. data/lib/beaker/shared/error_handler.rb +8 -10
  131. data/lib/beaker/shared/fog_credentials.rb +5 -9
  132. data/lib/beaker/shared/host_manager.rb +36 -41
  133. data/lib/beaker/shared/options_resolver.rb +3 -7
  134. data/lib/beaker/shared/repetition.rb +2 -4
  135. data/lib/beaker/shared/semvar.rb +37 -41
  136. data/lib/beaker/shared/timed.rb +0 -3
  137. data/lib/beaker/shared.rb +1 -1
  138. data/lib/beaker/ssh_connection.rb +38 -47
  139. data/lib/beaker/subcommand.rb +17 -24
  140. data/lib/beaker/subcommands/subcommand_util.rb +4 -4
  141. data/lib/beaker/tasks/quick_start.rb +4 -9
  142. data/lib/beaker/tasks/rake_task.rb +25 -27
  143. data/lib/beaker/tasks/test.rb +4 -4
  144. data/lib/beaker/test_case.rb +15 -27
  145. data/lib/beaker/test_suite.rb +35 -39
  146. data/lib/beaker/test_suite_result.rb +45 -47
  147. data/lib/beaker/version.rb +1 -1
  148. data/lib/beaker.rb +5 -6
  149. data/spec/beaker/cli_spec.rb +121 -142
  150. data/spec/beaker/command_spec.rb +55 -59
  151. data/spec/beaker/dsl/assertions_spec.rb +36 -36
  152. data/spec/beaker/dsl/helpers/host_helpers_spec.rb +110 -131
  153. data/spec/beaker/dsl/helpers/test_helpers_spec.rb +9 -10
  154. data/spec/beaker/dsl/helpers/web_helpers_spec.rb +22 -31
  155. data/spec/beaker/dsl/outcomes_spec.rb +14 -14
  156. data/spec/beaker/dsl/roles_spec.rb +125 -130
  157. data/spec/beaker/dsl/structure_spec.rb +169 -158
  158. data/spec/beaker/dsl/test_tagging_spec.rb +89 -90
  159. data/spec/beaker/dsl/wrappers_spec.rb +32 -33
  160. data/spec/beaker/host/aix_spec.rb +14 -14
  161. data/spec/beaker/host/cisco_spec.rb +84 -94
  162. data/spec/beaker/host/eos_spec.rb +15 -36
  163. data/spec/beaker/host/freebsd/exec_spec.rb +3 -6
  164. data/spec/beaker/host/freebsd/pkg_spec.rb +24 -27
  165. data/spec/beaker/host/mac/exec_spec.rb +2 -3
  166. data/spec/beaker/host/mac/group_spec.rb +47 -56
  167. data/spec/beaker/host/mac/user_spec.rb +53 -62
  168. data/spec/beaker/host/pswindows/exec_spec.rb +30 -32
  169. data/spec/beaker/host/pswindows/file_spec.rb +16 -16
  170. data/spec/beaker/host/pswindows/user_spec.rb +17 -23
  171. data/spec/beaker/host/pswindows_spec.rb +13 -13
  172. data/spec/beaker/host/unix/exec_spec.rb +75 -80
  173. data/spec/beaker/host/unix/file_spec.rb +66 -73
  174. data/spec/beaker/host/unix/pkg_spec.rb +155 -401
  175. data/spec/beaker/host/unix_spec.rb +11 -207
  176. data/spec/beaker/host/windows/exec_spec.rb +30 -32
  177. data/spec/beaker/host/windows/file_spec.rb +18 -19
  178. data/spec/beaker/host/windows/group_spec.rb +10 -12
  179. data/spec/beaker/host/windows/pkg_spec.rb +6 -9
  180. data/spec/beaker/host/windows/user_spec.rb +17 -23
  181. data/spec/beaker/host/windows_spec.rb +39 -39
  182. data/spec/beaker/host_prebuilt_steps_spec.rb +172 -326
  183. data/spec/beaker/host_spec.rb +204 -284
  184. data/spec/beaker/hypervisor/hypervisor_spec.rb +36 -61
  185. data/spec/beaker/localhost_connection_spec.rb +10 -11
  186. data/spec/beaker/logger_junit_spec.rb +19 -30
  187. data/spec/beaker/logger_spec.rb +153 -136
  188. data/spec/beaker/network_manager_spec.rb +23 -23
  189. data/spec/beaker/options/command_line_parser_spec.rb +20 -23
  190. data/spec/beaker/options/hosts_file_parser_spec.rb +30 -32
  191. data/spec/beaker/options/options_file_parser_spec.rb +4 -7
  192. data/spec/beaker/options/options_hash_spec.rb +4 -6
  193. data/spec/beaker/options/parser_spec.rb +167 -167
  194. data/spec/beaker/options/presets_spec.rb +7 -9
  195. data/spec/beaker/options/subcommand_options_parser_spec.rb +13 -14
  196. data/spec/beaker/options/validator_spec.rb +10 -11
  197. data/spec/beaker/perf_spec.rb +18 -21
  198. data/spec/beaker/platform_spec.rb +25 -36
  199. data/spec/beaker/shared/error_handler_spec.rb +7 -16
  200. data/spec/beaker/shared/fog_credentials_spec.rb +29 -29
  201. data/spec/beaker/shared/host_manager_spec.rb +50 -84
  202. data/spec/beaker/shared/options_resolver_spec.rb +9 -12
  203. data/spec/beaker/shared/repetition_spec.rb +17 -24
  204. data/spec/beaker/shared/semvar_spec.rb +21 -26
  205. data/spec/beaker/ssh_connection_spec.rb +76 -83
  206. data/spec/beaker/subcommand/subcommand_util_spec.rb +31 -33
  207. data/spec/beaker/subcommand_spec.rb +75 -77
  208. data/spec/beaker/test_case_spec.rb +25 -50
  209. data/spec/beaker/test_suite_spec.rb +147 -154
  210. data/spec/helpers.rb +48 -53
  211. data/spec/matchers.rb +8 -7
  212. data/spec/mocks.rb +1 -6
  213. data/spec/spec_helper.rb +0 -1
  214. metadata +7 -24
  215. data/acceptance/tests/base/dsl/helpers/host_helpers/deploy_package_repo_test.rb +0 -142
  216. data/acceptance/tests/base/external_resources_test.rb +0 -31
  217. data/spec/beaker/host/mac_spec.rb +0 -113
@@ -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
@@ -195,81 +194,82 @@ module Unix::Exec
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
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
@@ -387,33 +388,31 @@ 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}/")
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}/")
403
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
 
@@ -424,7 +423,7 @@ module Unix::Exec
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,11 +110,11 @@ 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
119
  variant = 'redhatfips' if self['packaging_platform']&.include?('redhatfips')
120
120
 
@@ -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
@@ -171,36 +166,36 @@ module Unix::File
171
166
  # @return [String] the text of the noask file
172
167
  def noask_file_text
173
168
  if self['platform'].variant == 'solaris' && self['platform'].version == '10'
174
- noask = <<NOASK
175
- # Write the noask file to a temporary directory
176
- # please see man -s 4 admin for details about this file:
177
- # http://www.opensolarisforum.org/man/man4/admin.html
178
- #
179
- # The key thing we don't want to prompt for are conflicting files.
180
- # The other nocheck settings are mostly defensive to prevent prompts
181
- # We _do_ want to check for available free space and abort if there is
182
- # not enough
183
- mail=
184
- # Overwrite already installed instances
185
- instance=overwrite
186
- # Do not bother checking for partially installed packages
187
- partial=nocheck
188
- # Do not bother checking the runlevel
189
- runlevel=nocheck
190
- # Do not bother checking package dependencies (We take care of this)
191
- idepend=nocheck
192
- rdepend=nocheck
193
- # DO check for available free space and abort if there isn't enough
194
- space=quit
195
- # Do not check for setuid files.
196
- setuid=nocheck
197
- # Do not check if files conflict with other packages
198
- conflict=nocheck
199
- # We have no action scripts. Do not check for them.
200
- action=nocheck
201
- # Install to the default base directory.
202
- basedir=default
203
- NOASK
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
204
199
  else
205
200
  msg = "noask file text unknown for platform '#{self['platform']}'"
206
201
  raise ArgumentError, msg
@@ -1,7 +1,7 @@
1
1
  module Unix::Group
2
2
  include Beaker::CommandFactory
3
3
 
4
- def group_list()
4
+ def group_list
5
5
  execute("getent group") do |result|
6
6
  groups = []
7
7
  result.stdout.each_line do |line|