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
@@ -1,11 +1,11 @@
1
1
  module Unix::User
2
2
  include Beaker::CommandFactory
3
3
 
4
- def user_list(&block)
4
+ def user_list
5
5
  execute("getent passwd") do |result|
6
6
  users = []
7
7
  result.stdout.each_line do |line|
8
- users << (line.match( /^([^:]+)/) or next)[1]
8
+ users << (line.match(/^([^:]+)/) or next)[1]
9
9
  end
10
10
 
11
11
  yield result if block_given?
@@ -14,9 +14,9 @@ module Unix::User
14
14
  end
15
15
  end
16
16
 
17
- def user_get(name, &block)
17
+ def user_get(name)
18
18
  execute("getent passwd #{name}") do |result|
19
- fail_test "failed to get user #{name}" unless result.stdout =~ /^#{name}:/
19
+ fail_test "failed to get user #{name}" unless /^#{name}:/.match?(result.stdout)
20
20
 
21
21
  yield result if block_given?
22
22
  result
@@ -1,11 +1,11 @@
1
- [ 'host', 'command_factory', 'command', 'options' ].each do |lib|
2
- require "beaker/#{lib}"
1
+ %w[host command_factory command options].each do |lib|
2
+ require "beaker/#{lib}"
3
3
  end
4
4
 
5
5
  module Unix
6
6
  class Host < Beaker::Host
7
- [ 'user', 'group', 'exec', 'pkg', 'file' ].each do |lib|
8
- require "beaker/host/unix/#{lib}"
7
+ %w[user group exec pkg file].each do |lib|
8
+ require "beaker/host/unix/#{lib}"
9
9
  end
10
10
 
11
11
  include Unix::User
@@ -17,10 +17,10 @@ module Unix
17
17
  def platform_defaults
18
18
  h = Beaker::Options::OptionsHash.new
19
19
  h.merge({
20
- 'user' => 'root',
21
- 'group' => 'root',
22
- 'pathseparator' => ':',
23
- })
20
+ 'user' => 'root',
21
+ 'group' => 'root',
22
+ 'pathseparator' => ':',
23
+ })
24
24
  end
25
25
 
26
26
  # Determines which SSH Server is in use on this host
@@ -35,12 +35,14 @@ module Unix
35
35
  end
36
36
 
37
37
  def external_copy_base
38
- return @external_copy_base if @external_copy_base
39
- @external_copy_base = '/root'
40
- variant, version, arch, codename = self['platform'].to_array
41
- # Solaris 10 uses / as the root user directory. Solaris 11 uses /root (like most).
42
- @external_copy_base = '/' if variant == 'solaris' && version == '10'
43
- @external_copy_base
38
+ @external_copy_base ||= begin
39
+ if self['platform'].variant == 'solaris' && self['platform'].version == '10'
40
+ # Solaris 10 uses / as the root user directory. Solaris 11 uses /root (like most).
41
+ '/'
42
+ else
43
+ '/root'
44
+ end
45
+ end
44
46
  end
45
47
 
46
48
  # Tells you whether a host platform supports beaker's
@@ -49,12 +51,9 @@ module Unix
49
51
  # @return [String,nil] Reason message if set_env should be skipped,
50
52
  # nil if it should run.
51
53
  def skip_set_env?
52
- variant, version, arch, codename = self['platform'].to_array
53
- case variant
54
+ case self['platform'].variant
54
55
  when /^(f5|netscaler)$/
55
- "no puppet-agent package for network device platform '#{variant}'"
56
- else
57
- nil
56
+ "no puppet-agent package for network device platform '#{self['platform'].variant}'"
58
57
  end
59
58
  end
60
59
 
@@ -72,6 +71,5 @@ module Unix
72
71
 
73
72
  @external_copy_base = nil
74
73
  end
75
-
76
74
  end
77
75
  end
@@ -11,11 +11,11 @@ module Windows::Exec
11
11
  ABS_CMD = 'c:\\\\windows\\\\system32\\\\cmd.exe'
12
12
  CMD = 'cmd.exe'
13
13
 
14
- def echo(msg, abs=true)
14
+ def echo(msg, abs = true)
15
15
  (abs ? ABS_CMD : CMD) + " /c echo #{msg}"
16
16
  end
17
17
 
18
- def touch(file, abs=true)
18
+ def touch(file, abs = true)
19
19
  (abs ? ABS_CMD : CMD) + " /c echo. 2> #{file}"
20
20
  end
21
21
 
@@ -35,8 +35,10 @@ module Windows::Exec
35
35
  ips.each_line do |line|
36
36
  matches = line.split('=')
37
37
  next if matches.length <= 1
38
+
38
39
  matches = matches[1].match(/^{"(.*?)"/)
39
40
  next if matches.nil? || matches.captures.nil? || matches.captures.empty?
41
+
40
42
  ip = matches.captures[0] if matches && matches.captures
41
43
  break if ip != ''
42
44
  end
@@ -48,14 +50,13 @@ module Windows::Exec
48
50
  # @param [String] target The hostname to ping
49
51
  # @param [Integer] attempts Amount of times to attempt ping before giving up
50
52
  # @return [Boolean] true of ping successful, overwise false
51
- def ping target, attempts=5
53
+ def ping target, attempts = 5
52
54
  try = 0
53
- while try < attempts do
55
+ while try < attempts
54
56
  result = exec(Beaker::Command.new("ping -n 1 #{target}"), :accept_all_exit_codes => true)
55
- if result.exit_code == 0
56
- return true
57
- end
58
- try+=1
57
+ return true if result.exit_code == 0
58
+
59
+ try += 1
59
60
  end
60
61
  result.exit_code == 0
61
62
  end
@@ -67,10 +68,10 @@ module Windows::Exec
67
68
  command_result = nil
68
69
  # we get periodic failures to restart the service, so looping these with re-attempts
69
70
  repeat_fibonacci_style_for(5) do
70
- 0 == exec(Beaker::Command.new("cygrunsrv -E sshd"), :acceptable_exit_codes => [0, 1] ).exit_code
71
+ 0 == exec(Beaker::Command.new("cygrunsrv -E sshd"), :acceptable_exit_codes => [0, 1]).exit_code
71
72
  end
72
73
  repeat_fibonacci_style_for(5) do
73
- command_result = exec(Beaker::Command.new("cygrunsrv -S sshd"), :acceptable_exit_codes => [0, 1] )
74
+ command_result = exec(Beaker::Command.new("cygrunsrv -S sshd"), :acceptable_exit_codes => [0, 1])
74
75
  0 == command_result.exit_code
75
76
  end
76
77
  command_result
@@ -83,7 +84,7 @@ module Windows::Exec
83
84
  # (from {#ssh_service_restart}).
84
85
  def ssh_permit_user_environment
85
86
  exec(Beaker::Command.new("echo '\nPermitUserEnvironment yes' >> /etc/sshd_config"))
86
- ssh_service_restart()
87
+ ssh_service_restart
87
88
  end
88
89
 
89
90
  # Gets the specific prepend commands as needed for this host
@@ -94,9 +95,9 @@ module Windows::Exec
94
95
  # @option opts [Boolean] :cmd_exe whether cmd.exe should be used
95
96
  #
96
97
  # @return [String] Command string as needed for this host
97
- def prepend_commands(command = '', user_pc = nil, opts = {})
98
+ def prepend_commands(_command = '', user_pc = nil, opts = {})
98
99
  cygwin_prefix = (self.is_cygwin? and opts[:cmd_exe]) ? 'cmd.exe /c' : ''
99
- spacing = (user_pc && !cygwin_prefix.empty?) ? ' ' : ''
100
+ spacing = user_pc && !cygwin_prefix.empty? ? ' ' : ''
100
101
  "#{cygwin_prefix}#{spacing}#{user_pc}"
101
102
  end
102
103
 
@@ -107,15 +108,15 @@ module Windows::Exec
107
108
  # @param [Hash] opts optional parameters
108
109
  #
109
110
  # @return [String] Command string as needed for this host
110
- def append_commands(command = '', user_ac = '', opts = {})
111
+ def append_commands(_command = '', user_ac = '', _opts = {})
111
112
  user_ac
112
113
  end
113
114
 
114
- # Checks if selinux is enabled
115
+ #  Checks if selinux is enabled
115
116
  # selinux is not available on Windows
116
117
  #
117
118
  # @return [Boolean] false
118
- def selinux_enabled?()
119
+ def selinux_enabled?
119
120
  false
120
121
  end
121
122
 
@@ -138,20 +139,19 @@ module Windows::Exec
138
139
  # @param [String] orig The origin path
139
140
  # @param [String] dest the destination path
140
141
  # @param [Boolean] rm Remove the destination prior to move
141
- def mv orig, dest, rm=true
142
+ def mv orig, dest, rm = true
142
143
  rm_rf dest unless !rm
143
144
  execute("mv \"#{orig}\" \"#{dest}\"")
144
145
  end
145
146
 
146
-
147
147
  # Determine if cygwin is actually installed on the SUT. Differs from
148
148
  # is_cygwin?, which is just a type check for a Windows::Host.
149
149
  #
150
150
  # @return [Boolean]
151
151
  def cygwin_installed?
152
152
  output = exec(Beaker::Command.new('cygcheck --check-setup cygwin'), :accept_all_exit_codes => true).stdout
153
- return true if output.match(/cygwin/) && output.match(/OK/)
153
+ return true if output.include?('cygwin') && output.include?('OK')
154
+
154
155
  false
155
156
  end
156
-
157
157
  end
@@ -12,7 +12,7 @@ module Windows::File
12
12
  def system_temp_path
13
13
  # under CYGWIN %TEMP% may not be set
14
14
  tmp_path = execute('ECHO %SYSTEMROOT%', :cmdexe => true)
15
- tmp_path.gsub(/\n/, '') + '\\TEMP'
15
+ tmp_path.delete("\n") + '\\TEMP'
16
16
  end
17
17
 
18
18
  # (see {Beaker::Host::Unix::File#chown})
@@ -20,7 +20,7 @@ module Windows::File
20
20
  # windows-, DOS-, or mixed-style paths, only UNIX/POSIX-style.
21
21
  # This method simply wraps the normal Host#chown call with
22
22
  # a call to cygpath to sanitize input.
23
- def chown(user, path, recursive=false)
23
+ def chown(user, path, recursive = false)
24
24
  cygpath = execute("cygpath -u #{path}")
25
25
  super(user, cygpath, recursive)
26
26
  end
@@ -30,13 +30,13 @@ module Windows::File
30
30
  # windows-, DOS-, or mixed-style paths, only UNIX/POSIX-style.
31
31
  # This method simply wraps the normal Host#chgrp call with
32
32
  # a call to cygpath to sanitize input.
33
- def chgrp(group, path, recursive=false)
33
+ def chgrp(group, path, recursive = false)
34
34
  cygpath = execute("cygpath -u #{path}")
35
35
  super(group, cygpath, recursive)
36
36
  end
37
37
 
38
38
  # Not needed on windows
39
- def chmod(mod, path, recursive=false); end
39
+ def chmod(mod, path, recursive = false); end
40
40
 
41
41
  # (see {Beaker::Host::Unix::File#ls_ld})
42
42
  # @note Cygwin's `ls_ld` implementation does not support
@@ -63,7 +63,7 @@ module Windows::File
63
63
  when :openssh
64
64
  path
65
65
  when :win32_openssh
66
- path.gsub('\\', '/')
66
+ path.tr('\\', '/')
67
67
  else
68
68
  raise ArgumentError, "windows/file.rb:scp_path: ssh server not recognized: '#{determine_ssh_server}'"
69
69
  end
@@ -1,7 +1,7 @@
1
1
  module Windows::Group
2
2
  include Beaker::CommandFactory
3
3
 
4
- def group_list(&block)
4
+ def group_list
5
5
  execute('cmd /c echo "" | wmic group where localaccount="true" get name /format:value') do |result|
6
6
  groups = []
7
7
  result.stdout.each_line do |line|
@@ -14,7 +14,7 @@ module Windows::Group
14
14
  end
15
15
  end
16
16
 
17
- def group_get(name, &block)
17
+ def group_get(name)
18
18
  execute("net localgroup \"#{name}\"") do |result|
19
19
  fail_test "failed to get group #{name}" if result.exit_code != 0
20
20
 
@@ -23,15 +23,15 @@ module Windows::Group
23
23
  end
24
24
  end
25
25
 
26
- def group_gid(name)
26
+ def group_gid(_name)
27
27
  raise NotImplementedError, "Can't retrieve group gid on a Windows host"
28
28
  end
29
29
 
30
30
  def group_present(name, &block)
31
- execute("net localgroup /add \"#{name}\"", {:acceptable_exit_codes => [0,2]}, &block)
31
+ execute("net localgroup /add \"#{name}\"", { :acceptable_exit_codes => [0, 2] }, &block)
32
32
  end
33
33
 
34
34
  def group_absent(name, &block)
35
- execute("net localgroup /delete \"#{name}\"", {:acceptable_exit_codes => [0,2]}, &block)
35
+ execute("net localgroup /delete \"#{name}\"", { :acceptable_exit_codes => [0, 2] }, &block)
36
36
  end
37
37
  end
@@ -17,7 +17,7 @@ module Windows::Pkg
17
17
  if arch == '64'
18
18
  rootdir = "c:\\\\cygwin64"
19
19
  cygwin = "setup-x86_64.exe"
20
- else #32 bit version
20
+ else # 32 bit version
21
21
  rootdir = "c:\\\\cygwin"
22
22
  cygwin = "setup-x86.exe"
23
23
  end
@@ -25,71 +25,20 @@ module Windows::Pkg
25
25
  execute("#{cygwin} -q -n -N -d -R #{rootdir} -s http://cygwin.osuosl.org -P #{name} #{cmdline_args}")
26
26
  end
27
27
 
28
- def uninstall_package(name, cmdline_args = '')
28
+ def uninstall_package(name, _cmdline_args = '')
29
29
  raise "Package #{name} cannot be uninstalled on #{self}"
30
30
  end
31
31
 
32
- #Examine the host system to determine the architecture, overrides default host determine_if_x86_64 so that wmic is used
33
- #@return [Boolean] true if x86_64, false otherwise
32
+ # Examine the host system to determine the architecture, overrides default host determine_if_x86_64 so that wmic is used
33
+ # @return [Boolean] true if x86_64, false otherwise
34
34
  def determine_if_x86_64
35
- (identify_windows_architecture =~ /64/) == 0
36
- end
37
-
38
- # Gets the path & file name for the puppet agent dev package on Windows
39
- #
40
- # @param [String] puppet_collection Name of the puppet collection to use
41
- # @param [String] puppet_agent_version Version of puppet agent to get
42
- # @param [Hash{Symbol=>String}] opts Options hash to provide extra values
43
- #
44
- # @note Windows only uses the 'install_32' option of the opts hash at this
45
- # time. Note that it will not fail if not provided, however
46
- #
47
- # @return [String, String] Path to the directory and filename of the package, respectively
48
- def puppet_agent_dev_package_info( puppet_collection = nil, puppet_agent_version = nil, opts = {} )
49
- release_path_end = 'windows'
50
- is_config_32 = self['ruby_arch'] == 'x86' || self['install_32'] || opts['install_32']
51
- should_install_64bit = self.is_x86_64? && !is_config_32
52
- # only install 64bit builds if
53
- # - we do not have install_32 set on host
54
- # - we do not have install_32 set globally
55
- arch_suffix = should_install_64bit ? '64' : '86'
56
- # If a version was specified, use it; otherwise fall back to a default name.
57
- # Avoid when puppet_agent_version is set to a SHA, which isn't used in package names.
58
- if puppet_agent_version =~ /^\d+\.\d+\.\d+/
59
- release_file = "puppet-agent-#{puppet_agent_version}-x#{arch_suffix}.msi"
60
- else
61
- release_file = "puppet-agent-x#{arch_suffix}.msi"
62
- end
63
- return release_path_end, release_file
64
- end
65
-
66
- # Gets host-specific information for PE promoted puppet-agent packages
67
- #
68
- # @param [String] puppet_collection Name of the puppet collection to use
69
- # @param [Hash{Symbol=>String}] opts Options hash to provide extra values
70
- #
71
- # @return [String, String, String] Host-specific information for packages
72
- # 1. release_path_end Suffix for the release_path
73
- # 2. release_file Path to the file on release build servers
74
- # 3. download_file Filename for the package itself
75
- def pe_puppet_agent_promoted_package_info( puppet_collection = nil, opts = {} )
76
- is_config_32 = self['ruby_arch'] == 'x86' || self['install_32'] || self['install_32']
77
- should_install_64bit = self.is_x86_64? && !is_config_32
78
- # only install 64bit builds if
79
- # - we do not have install_32 set on host
80
- # - we do not have install_32 set globally
81
- arch_suffix = should_install_64bit ? '64' : '86'
82
- release_path_end = "/windows"
83
- release_file = "/puppet-agent-x#{arch_suffix}.msi"
84
- download_file = "puppet-agent-x#{arch_suffix}.msi"
85
- return release_path_end, release_file, download_file
35
+ identify_windows_architecture.include?('64')
86
36
  end
87
37
 
88
38
  private
89
39
 
90
40
  # @api private
91
41
  def identify_windows_architecture
92
- platform.arch =~ /64/ ? '64' : '32'
42
+ platform.arch.include?('64') ? '64' : '32'
93
43
  end
94
-
95
44
  end
@@ -1,7 +1,7 @@
1
1
  module Windows::User
2
2
  include Beaker::CommandFactory
3
3
 
4
- def user_list(&block)
4
+ def user_list
5
5
  execute('cmd /c echo "" | wmic useraccount where localaccount="true" get name /format:value') do |result|
6
6
  users = []
7
7
  result.stdout.each_line do |line|
@@ -14,7 +14,7 @@ module Windows::User
14
14
  end
15
15
  end
16
16
 
17
- def user_get(name, &block)
17
+ def user_get(name)
18
18
  execute("net user \"#{name}\"") do |result|
19
19
  fail_test "failed to get user #{name}" if result.exit_code != 0
20
20
 
@@ -24,10 +24,10 @@ module Windows::User
24
24
  end
25
25
 
26
26
  def user_present(name, &block)
27
- execute("net user /add \"#{name}\"", {:acceptable_exit_codes => [0,2]}, &block)
27
+ execute("net user /add \"#{name}\"", { :acceptable_exit_codes => [0, 2] }, &block)
28
28
  end
29
29
 
30
30
  def user_absent(name, &block)
31
- execute("net user /delete \"#{name}\"", {:acceptable_exit_codes => [0,2]}, &block)
31
+ execute("net user /delete \"#{name}\"", { :acceptable_exit_codes => [0, 2] }, &block)
32
32
  end
33
33
  end
@@ -1,12 +1,12 @@
1
- [ 'host', 'command_factory', 'command', 'options' ].each do |lib|
2
- require "beaker/#{lib}"
1
+ %w[host command_factory command options].each do |lib|
2
+ require "beaker/#{lib}"
3
3
  end
4
4
 
5
5
  module Windows
6
6
  # A windows host with cygwin tools installed
7
7
  class Host < Unix::Host
8
- [ 'user', 'group', 'exec', 'pkg', 'file' ].each do |lib|
9
- require "beaker/host/windows/#{lib}"
8
+ %w[user group exec pkg file].each do |lib|
9
+ require "beaker/host/windows/#{lib}"
10
10
  end
11
11
 
12
12
  include Windows::User
@@ -18,14 +18,15 @@ module Windows
18
18
  def platform_defaults
19
19
  h = Beaker::Options::OptionsHash.new
20
20
  h.merge({
21
- 'user' => 'Administrator',
22
- 'group' => 'Administrators',
23
- 'pathseparator' => ';',
24
- })
21
+ 'user' => 'Administrator',
22
+ 'group' => 'Administrators',
23
+ 'pathseparator' => ';',
24
+ })
25
25
  end
26
26
 
27
27
  def external_copy_base
28
28
  return @external_copy_base if @external_copy_base
29
+
29
30
  @external_copy_base = execute('echo `cygpath -smF 35`/')
30
31
  @external_copy_base
31
32
  end
@@ -36,20 +37,20 @@ module Windows
36
37
  # (:bitvise or :openssh at this point).
37
38
  def determine_ssh_server
38
39
  return @ssh_server if @ssh_server
40
+
39
41
  @ssh_server = :openssh
40
42
  status = execute('cmd.exe /c sc query BvSshServer', :accept_all_exit_codes => true)
41
- if status =~ /4 RUNNING/
43
+ if status&.include?('4 RUNNING')
42
44
  @ssh_server = :bitvise
43
45
  else
44
46
  status = execute('cmd.exe /c sc qc sshd', :accept_all_exit_codes => true)
45
- if status =~ /C:\\Windows\\System32\\OpenSSH\\sshd\.exe/
46
- @ssh_server = :win32_openssh
47
- end
47
+ @ssh_server = :win32_openssh if status&.include?('C:\\Windows\\System32\\OpenSSH\\sshd.exe')
48
48
  end
49
49
  @ssh_server
50
50
  end
51
51
 
52
52
  attr_reader :scp_separator
53
+
53
54
  def initialize name, host_hash, options
54
55
  super
55
56
 
@@ -57,6 +58,5 @@ module Windows
57
58
  @scp_separator = '\\'
58
59
  @external_copy_base = nil
59
60
  end
60
-
61
61
  end
62
62
  end