beaker 4.41.2 → 5.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (218) hide show
  1. checksums.yaml +4 -4
  2. data/.github/dependabot.yml +9 -0
  3. data/.github/workflows/release.yml +2 -2
  4. data/.github/workflows/test.yml +26 -13
  5. data/.rubocop.yml +23 -10
  6. data/.rubocop_todo.yml +34 -10
  7. data/CHANGELOG.md +16 -52
  8. data/Gemfile +12 -7
  9. data/HISTORY.md +605 -0
  10. data/Rakefile +99 -111
  11. data/acceptance/config/acceptance-options.rb +1 -1
  12. data/acceptance/config/base/acceptance-options.rb +2 -2
  13. data/acceptance/config/hypervisor/acceptance-options.rb +2 -2
  14. data/acceptance/config/subcommands/acceptance-options.rb +2 -2
  15. data/acceptance/fixtures/module/Rakefile +1 -1
  16. data/acceptance/fixtures/module/spec/acceptance/demo_spec.rb +8 -12
  17. data/acceptance/fixtures/module/spec/classes/init_spec.rb +0 -1
  18. data/acceptance/fixtures/module/spec/spec_helper_acceptance.rb +3 -5
  19. data/acceptance/lib/helpers/test_helper.rb +6 -5
  20. data/acceptance/pre_suite/subcommands/05_install_ruby.rb +2 -3
  21. data/acceptance/pre_suite/subcommands/08_install_beaker.rb +1 -2
  22. data/acceptance/tests/base/dsl/helpers/configuration_test.rb +4 -4
  23. data/acceptance/tests/base/dsl/helpers/hocon_helpers_test.rb +1 -2
  24. data/acceptance/tests/base/dsl/helpers/host_helpers/add_system32_hosts_entry_test.rb +0 -3
  25. data/acceptance/tests/base/dsl/helpers/host_helpers/archive_file_from_test.rb +3 -1
  26. data/acceptance/tests/base/dsl/helpers/host_helpers/backup_the_file_test.rb +9 -9
  27. data/acceptance/tests/base/dsl/helpers/host_helpers/check_for_package_test.rb +0 -4
  28. data/acceptance/tests/base/dsl/helpers/host_helpers/create_remote_file_test.rb +19 -26
  29. data/acceptance/tests/base/dsl/helpers/host_helpers/curl_on_test.rb +2 -2
  30. data/acceptance/tests/base/dsl/helpers/host_helpers/curl_with_retries_test.rb +0 -1
  31. data/acceptance/tests/base/dsl/helpers/host_helpers/on_test.rb +18 -13
  32. data/acceptance/tests/base/dsl/helpers/host_helpers/retry_on_test.rb +3 -3
  33. data/acceptance/tests/base/dsl/helpers/host_helpers/rsync_to_test.rb +22 -27
  34. data/acceptance/tests/base/dsl/helpers/host_helpers/run_cron_on_test.rb +12 -16
  35. data/acceptance/tests/base/dsl/helpers/host_helpers/run_script_on_test.rb +3 -4
  36. data/acceptance/tests/base/dsl/helpers/host_helpers/run_script_test.rb +3 -3
  37. data/acceptance/tests/base/dsl/helpers/host_helpers/scp_from_test.rb +4 -4
  38. data/acceptance/tests/base/dsl/helpers/host_helpers/scp_to_test.rb +3 -4
  39. data/acceptance/tests/base/dsl/helpers/host_helpers/shell_test.rb +5 -5
  40. data/acceptance/tests/base/dsl/helpers/host_helpers/upgrade_package_test.rb +3 -5
  41. data/acceptance/tests/base/dsl/platform_tag_confiner_test.rb +14 -17
  42. data/acceptance/tests/base/dsl/structure_test.rb +5 -11
  43. data/acceptance/tests/base/host/file_test.rb +2 -2
  44. data/acceptance/tests/base/host/group_test.rb +0 -1
  45. data/acceptance/tests/base/host/host_test.rb +66 -63
  46. data/acceptance/tests/base/host/packages.rb +1 -2
  47. data/acceptance/tests/base/host/packages_unix.rb +0 -55
  48. data/acceptance/tests/base/host/user_test.rb +0 -1
  49. data/acceptance/tests/base/host_prebuilt_steps/ssh_environment_test.rb +1 -2
  50. data/acceptance/tests/base/test_suite/export.rb +6 -9
  51. data/acceptance/tests/install/from_file.rb +2 -4
  52. data/acceptance/tests/load_path_bootstrap.rb +1 -1
  53. data/acceptance/tests/subcommands/destroy.rb +19 -21
  54. data/acceptance/tests/subcommands/exec.rb +0 -1
  55. data/acceptance/tests/subcommands/init.rb +2 -3
  56. data/acceptance/tests/subcommands/provision.rb +0 -1
  57. data/beaker.gemspec +4 -7
  58. data/docs/concepts/argument_processing_and_precedence.md +1 -10
  59. data/docs/how_to/debug_beaker_tests.md +12 -12
  60. data/docs/how_to/hosts/eos.md +2 -12
  61. data/docs/how_to/install_puppet.md +0 -18
  62. data/docs/how_to/the_beaker_dsl.md +0 -2
  63. data/lib/beaker/cli.rb +59 -68
  64. data/lib/beaker/command.rb +20 -28
  65. data/lib/beaker/command_factory.rb +3 -2
  66. data/lib/beaker/dsl/assertions.rb +6 -18
  67. data/lib/beaker/dsl/helpers/hocon_helpers.rb +3 -7
  68. data/lib/beaker/dsl/helpers/host_helpers.rb +62 -123
  69. data/lib/beaker/dsl/helpers/test_helpers.rb +3 -5
  70. data/lib/beaker/dsl/helpers/web_helpers.rb +19 -39
  71. data/lib/beaker/dsl/helpers.rb +2 -4
  72. data/lib/beaker/dsl/outcomes.rb +13 -15
  73. data/lib/beaker/dsl/patterns.rb +1 -3
  74. data/lib/beaker/dsl/roles.rb +17 -20
  75. data/lib/beaker/dsl/structure.rb +53 -65
  76. data/lib/beaker/dsl/test_tagging.rb +7 -10
  77. data/lib/beaker/dsl/wrappers.rb +15 -16
  78. data/lib/beaker/dsl.rb +2 -3
  79. data/lib/beaker/host/aix/exec.rb +1 -1
  80. data/lib/beaker/host/aix/file.rb +0 -1
  81. data/lib/beaker/host/aix/group.rb +1 -1
  82. data/lib/beaker/host/aix/user.rb +1 -1
  83. data/lib/beaker/host/aix.rb +3 -4
  84. data/lib/beaker/host/cisco.rb +27 -39
  85. data/lib/beaker/host/eos.rb +4 -30
  86. data/lib/beaker/host/freebsd/exec.rb +1 -1
  87. data/lib/beaker/host/freebsd/pkg.rb +3 -3
  88. data/lib/beaker/host/freebsd.rb +9 -12
  89. data/lib/beaker/host/mac/exec.rb +4 -4
  90. data/lib/beaker/host/mac/group.rb +7 -7
  91. data/lib/beaker/host/mac/pkg.rb +3 -106
  92. data/lib/beaker/host/mac/user.rb +2 -2
  93. data/lib/beaker/host/mac.rb +8 -9
  94. data/lib/beaker/host/pswindows/exec.rb +66 -70
  95. data/lib/beaker/host/pswindows/file.rb +3 -5
  96. data/lib/beaker/host/pswindows/group.rb +3 -3
  97. data/lib/beaker/host/pswindows/pkg.rb +12 -12
  98. data/lib/beaker/host/pswindows/user.rb +3 -3
  99. data/lib/beaker/host/pswindows.rb +4 -3
  100. data/lib/beaker/host/unix/exec.rb +81 -83
  101. data/lib/beaker/host/unix/file.rb +40 -45
  102. data/lib/beaker/host/unix/group.rb +1 -1
  103. data/lib/beaker/host/unix/pkg.rb +138 -401
  104. data/lib/beaker/host/unix/user.rb +2 -2
  105. data/lib/beaker/host/unix.rb +8 -11
  106. data/lib/beaker/host/windows/exec.rb +17 -17
  107. data/lib/beaker/host/windows/file.rb +3 -3
  108. data/lib/beaker/host/windows/group.rb +3 -3
  109. data/lib/beaker/host/windows/pkg.rb +3 -54
  110. data/lib/beaker/host/windows/user.rb +3 -3
  111. data/lib/beaker/host/windows.rb +12 -12
  112. data/lib/beaker/host.rb +76 -133
  113. data/lib/beaker/host_prebuilt_steps.rb +88 -196
  114. data/lib/beaker/hypervisor/noop.rb +2 -4
  115. data/lib/beaker/hypervisor.rb +44 -61
  116. data/lib/beaker/local_connection.rb +2 -4
  117. data/lib/beaker/logger.rb +68 -76
  118. data/lib/beaker/logger_junit.rb +21 -25
  119. data/lib/beaker/network_manager.rb +39 -42
  120. data/lib/beaker/options/command_line_parser.rb +12 -23
  121. data/lib/beaker/options/hosts_file_parser.rb +16 -25
  122. data/lib/beaker/options/options_file_parser.rb +3 -6
  123. data/lib/beaker/options/options_hash.rb +2 -7
  124. data/lib/beaker/options/parser.rb +86 -102
  125. data/lib/beaker/options/presets.rb +114 -123
  126. data/lib/beaker/options/subcommand_options_file_parser.rb +3 -6
  127. data/lib/beaker/options/validator.rb +26 -31
  128. data/lib/beaker/perf.rb +25 -30
  129. data/lib/beaker/platform.rb +26 -37
  130. data/lib/beaker/result.rb +7 -6
  131. data/lib/beaker/shared/error_handler.rb +8 -10
  132. data/lib/beaker/shared/fog_credentials.rb +5 -9
  133. data/lib/beaker/shared/host_manager.rb +36 -41
  134. data/lib/beaker/shared/options_resolver.rb +3 -7
  135. data/lib/beaker/shared/repetition.rb +2 -4
  136. data/lib/beaker/shared/semvar.rb +37 -41
  137. data/lib/beaker/shared/timed.rb +0 -3
  138. data/lib/beaker/shared.rb +1 -1
  139. data/lib/beaker/ssh_connection.rb +38 -47
  140. data/lib/beaker/subcommand.rb +17 -24
  141. data/lib/beaker/subcommands/subcommand_util.rb +4 -4
  142. data/lib/beaker/tasks/quick_start.rb +4 -9
  143. data/lib/beaker/tasks/rake_task.rb +25 -27
  144. data/lib/beaker/tasks/test.rb +4 -4
  145. data/lib/beaker/test_case.rb +16 -28
  146. data/lib/beaker/test_suite.rb +35 -39
  147. data/lib/beaker/test_suite_result.rb +45 -47
  148. data/lib/beaker/version.rb +1 -1
  149. data/lib/beaker.rb +6 -7
  150. data/spec/beaker/cli_spec.rb +121 -142
  151. data/spec/beaker/command_spec.rb +55 -59
  152. data/spec/beaker/dsl/assertions_spec.rb +36 -36
  153. data/spec/beaker/dsl/helpers/host_helpers_spec.rb +110 -131
  154. data/spec/beaker/dsl/helpers/test_helpers_spec.rb +9 -10
  155. data/spec/beaker/dsl/helpers/web_helpers_spec.rb +22 -31
  156. data/spec/beaker/dsl/outcomes_spec.rb +14 -14
  157. data/spec/beaker/dsl/roles_spec.rb +125 -130
  158. data/spec/beaker/dsl/structure_spec.rb +172 -161
  159. data/spec/beaker/dsl/test_tagging_spec.rb +89 -90
  160. data/spec/beaker/dsl/wrappers_spec.rb +32 -33
  161. data/spec/beaker/host/aix_spec.rb +14 -14
  162. data/spec/beaker/host/cisco_spec.rb +84 -94
  163. data/spec/beaker/host/eos_spec.rb +15 -36
  164. data/spec/beaker/host/freebsd/exec_spec.rb +3 -6
  165. data/spec/beaker/host/freebsd/pkg_spec.rb +24 -27
  166. data/spec/beaker/host/mac/exec_spec.rb +2 -3
  167. data/spec/beaker/host/mac/group_spec.rb +48 -57
  168. data/spec/beaker/host/mac/user_spec.rb +54 -63
  169. data/spec/beaker/host/pswindows/exec_spec.rb +30 -32
  170. data/spec/beaker/host/pswindows/file_spec.rb +16 -16
  171. data/spec/beaker/host/pswindows/user_spec.rb +17 -23
  172. data/spec/beaker/host/pswindows_spec.rb +13 -13
  173. data/spec/beaker/host/unix/exec_spec.rb +75 -80
  174. data/spec/beaker/host/unix/file_spec.rb +66 -71
  175. data/spec/beaker/host/unix/pkg_spec.rb +150 -411
  176. data/spec/beaker/host/unix_spec.rb +11 -207
  177. data/spec/beaker/host/windows/exec_spec.rb +30 -32
  178. data/spec/beaker/host/windows/file_spec.rb +18 -19
  179. data/spec/beaker/host/windows/group_spec.rb +10 -12
  180. data/spec/beaker/host/windows/pkg_spec.rb +6 -9
  181. data/spec/beaker/host/windows/user_spec.rb +17 -23
  182. data/spec/beaker/host/windows_spec.rb +39 -39
  183. data/spec/beaker/host_prebuilt_steps_spec.rb +168 -349
  184. data/spec/beaker/host_spec.rb +204 -284
  185. data/spec/beaker/hypervisor/hypervisor_spec.rb +36 -61
  186. data/spec/beaker/localhost_connection_spec.rb +10 -11
  187. data/spec/beaker/logger_junit_spec.rb +19 -30
  188. data/spec/beaker/logger_spec.rb +153 -136
  189. data/spec/beaker/network_manager_spec.rb +23 -23
  190. data/spec/beaker/options/command_line_parser_spec.rb +20 -23
  191. data/spec/beaker/options/hosts_file_parser_spec.rb +30 -32
  192. data/spec/beaker/options/options_file_parser_spec.rb +4 -7
  193. data/spec/beaker/options/options_hash_spec.rb +4 -6
  194. data/spec/beaker/options/parser_spec.rb +167 -167
  195. data/spec/beaker/options/presets_spec.rb +7 -9
  196. data/spec/beaker/options/subcommand_options_parser_spec.rb +13 -14
  197. data/spec/beaker/options/validator_spec.rb +10 -11
  198. data/spec/beaker/perf_spec.rb +18 -21
  199. data/spec/beaker/platform_spec.rb +25 -50
  200. data/spec/beaker/shared/error_handler_spec.rb +7 -16
  201. data/spec/beaker/shared/fog_credentials_spec.rb +29 -29
  202. data/spec/beaker/shared/host_manager_spec.rb +50 -84
  203. data/spec/beaker/shared/options_resolver_spec.rb +9 -12
  204. data/spec/beaker/shared/repetition_spec.rb +17 -24
  205. data/spec/beaker/shared/semvar_spec.rb +21 -26
  206. data/spec/beaker/ssh_connection_spec.rb +76 -83
  207. data/spec/beaker/subcommand/subcommand_util_spec.rb +31 -33
  208. data/spec/beaker/subcommand_spec.rb +75 -77
  209. data/spec/beaker/test_case_spec.rb +25 -50
  210. data/spec/beaker/test_suite_spec.rb +147 -154
  211. data/spec/helpers.rb +39 -45
  212. data/spec/matchers.rb +8 -7
  213. data/spec/mocks.rb +1 -6
  214. data/spec/spec_helper.rb +0 -1
  215. metadata +8 -24
  216. data/acceptance/tests/base/dsl/helpers/host_helpers/deploy_package_repo_test.rb +0 -142
  217. data/acceptance/tests/base/external_resources_test.rb +0 -31
  218. data/spec/beaker/host/mac_spec.rb +0 -113
@@ -17,7 +17,7 @@ module Beaker
17
17
  module Assertions
18
18
  include Minitest::Assertions
19
19
 
20
- #Why do we need this accessor?
20
+ # Why do we need this accessor?
21
21
  # https://github.com/seattlerb/minitest/blob/master/lib/minitest/assertions.rb#L8-L12
22
22
  # Protocol: Nearly everything here boils up to +assert+, which
23
23
  # expects to be able to increment an instance accessor named
@@ -25,6 +25,7 @@ module Beaker
25
25
  # provided by the thing including Assertions. See Minitest::Runnable
26
26
  # for an example.
27
27
  attr_writer :assertions
28
+
28
29
  def assertions
29
30
  @assertions || 0
30
31
  end
@@ -71,7 +72,7 @@ module Beaker
71
72
  # annotated with stream markers.
72
73
  # @param [String] msg An explanatory message about why the test
73
74
  # failure is relevant.
74
- def assert_output(exp_out, msg='Output lines did not match')
75
+ def assert_output(exp_out, msg = 'Output lines did not match')
75
76
  # Remove the minimal consistent indentation from the input;
76
77
  # useful for clean HEREDOCs.
77
78
  indentation = exp_out.lines.map { |line| line[/^ */].length }.min
@@ -82,7 +83,7 @@ module Beaker
82
83
  line !~ /^((STD)?ERR|2)> /
83
84
  end
84
85
  our_out, our_err, our_output = [
85
- out.join, err.join, cleaned_exp
86
+ out.join, err.join, cleaned_exp,
86
87
  ].map do |str|
87
88
  str.gsub(/^((STD)?(ERR|OUT)|[12])> /, '')
88
89
  end
@@ -90,23 +91,10 @@ module Beaker
90
91
  # Exercise assertions about output
91
92
  assert_equal our_output, (result.nil? ? '' : result.output), msg
92
93
  assert_equal our_out, (result.nil? ? '' : result.stdout),
93
- 'The contents of STDOUT did not match expectations'
94
+ 'The contents of STDOUT did not match expectations'
94
95
  assert_equal our_err, (result.nil? ? '' : result.stderr),
95
- 'The contents of STDERR did not match expectations'
96
- end
97
-
98
- # Assert that the provided string does not match the provided regular expression, can pass optional message
99
- # @deprecated This is placed her for backwards compatability for tests that used Test::Unit::Assertions,
100
- # http://apidock.com/ruby/Test/Unit/Assertions/assert_no_match
101
- #
102
- def assert_no_match(regexp, string, msg=nil)
103
- assert_instance_of(Regexp, regexp, "The first argument to assert_no_match should be a Regexp.")
104
- msg = message(msg) { "<#{mu_pp(regexp)}> expected to not match\n<#{mu_pp(string)}>" }
105
- assert(regexp !~ string, msg)
96
+ 'The contents of STDERR did not match expectations'
106
97
  end
107
-
108
- alias_method :assert_not_match, :assert_no_match
109
-
110
98
  end
111
99
  end
112
100
  end
@@ -1,4 +1,3 @@
1
- # -*- coding: utf-8 -*-
2
1
  require 'hocon/parser/config_document_factory'
3
2
  require 'hocon/config_value_factory'
4
3
 
@@ -11,7 +10,6 @@ module Beaker
11
10
  # - {https://github.com/puppetlabs/beaker/tree/master/docs/how_to/use_hocon_helpers.md Beaker docs}.
12
11
  # - Beaker acceptance tests in +acceptance/tests/base/dsl/helpers/hocon_helpers_test.rb+
13
12
  module HoconHelpers
14
-
15
13
  # Reads the given hocon file from a SUT
16
14
  #
17
15
  # @param [Host] host Host to get hocon file from.
@@ -20,9 +18,8 @@ module Beaker
20
18
  # @raise ArgumentError if arguments are missing or incorrect
21
19
  # @return [Hocon::ConfigValueFactory] parsed hocon file
22
20
  def hocon_file_read_on(host, filename)
23
- if filename.nil? || filename.empty?
24
- raise ArgumentError, '#hocon_file_edit_on requires a filename'
25
- end
21
+ raise ArgumentError, '#hocon_file_edit_on requires a filename' if filename.nil? || filename.empty?
22
+
26
23
  file_contents = on(host, "cat #{filename}").stdout
27
24
  Hocon::Parser::ConfigDocumentFactory.parse_string(file_contents)
28
25
  end
@@ -59,7 +56,7 @@ module Beaker
59
56
  msg << ' a hocon file to edit. No block was provided.'
60
57
  raise ArgumentError, msg
61
58
  end
62
- block_on hosts, {} do | host |
59
+ block_on hosts, {} do |host|
63
60
  doc = hocon_file_read_on(host, filename)
64
61
  yield host, doc
65
62
  end
@@ -86,7 +83,6 @@ module Beaker
86
83
  create_remote_file(host, filename, content_doc.render)
87
84
  end
88
85
  end
89
-
90
86
  end
91
87
  end
92
88
  end
@@ -4,7 +4,6 @@ module Beaker
4
4
  # Methods that help you interact and manage the state of your Beaker SUTs, these
5
5
  # methods do not require puppet to be installed to execute correctly
6
6
  module HostHelpers
7
-
8
7
  # @!macro [new] common_opts
9
8
  # @param [Hash{Symbol=>String}] opts Options to alter execution.
10
9
  # @option opts [Boolean] :silent (false) Do not produce log output
@@ -60,13 +59,11 @@ module Beaker
60
59
  # @return [Result] An object representing the outcome of *command*.
61
60
  # @raise [FailTest] Raises an exception if *command* obviously fails.
62
61
  def on(host, command, opts = {}, &block)
63
- block_on host, opts do | host |
62
+ block_on host, opts do |host|
64
63
  if command.is_a? String
65
64
  cmd_opts = {}
66
- #add any additional environment variables to the command
67
- if opts[:environment]
68
- cmd_opts['ENV'] = opts[:environment]
69
- end
65
+ # add any additional environment variables to the command
66
+ cmd_opts['ENV'] = opts[:environment] if opts[:environment]
70
67
  command_object = Command.new(command.to_s, [], cmd_opts)
71
68
  elsif command.is_a? Command
72
69
  if opts[:environment]
@@ -80,20 +77,20 @@ module Beaker
80
77
  msg << " object as the command parameter, not #{command.class}."
81
78
  raise ArgumentError, msg
82
79
  end
83
- @result = host.exec(command_object, opts)
80
+ result = host.exec(command_object, opts)
84
81
 
85
82
  # Also, let additional checking be performed by the caller.
86
83
  if block
87
84
  case block.arity
88
- #block with arity of 0, just hand back yourself
89
- when 0
90
- yield self
91
- #block with arity of 1 or greater, hand back the result object
92
- else
93
- yield @result
85
+ # block with arity of 0, just hand back yourself
86
+ when 0
87
+ yield self
88
+ # block with arity of 1 or greater, hand back the result object
89
+ else
90
+ yield result
94
91
  end
95
92
  end
96
- @result
93
+ result
97
94
  end
98
95
  end
99
96
 
@@ -125,36 +122,6 @@ module Beaker
125
122
  on(default, command, opts, &block)
126
123
  end
127
124
 
128
- # @deprecated
129
- # An proxy for the last {Beaker::Result#stdout} returned by
130
- # a method that makes remote calls. Use the {Beaker::Result}
131
- # object returned by the method directly instead. For Usage see
132
- # {Beaker::Result}.
133
- def stdout
134
- return nil if @result.nil?
135
- @result.stdout
136
- end
137
-
138
- # @deprecated
139
- # An proxy for the last {Beaker::Result#stderr} returned by
140
- # a method that makes remote calls. Use the {Beaker::Result}
141
- # object returned by the method directly instead. For Usage see
142
- # {Beaker::Result}.
143
- def stderr
144
- return nil if @result.nil?
145
- @result.stderr
146
- end
147
-
148
- # @deprecated
149
- # An proxy for the last {Beaker::Result#exit_code} returned by
150
- # a method that makes remote calls. Use the {Beaker::Result}
151
- # object returned by the method directly instead. For Usage see
152
- # {Beaker::Result}.
153
- def exit_code
154
- return nil if @result.nil?
155
- @result.exit_code
156
- end
157
-
158
125
  # Move a file from a remote to a local path
159
126
  # @note If using {Beaker::Host} for the hosts *scp* is not
160
127
  # required on the system as it uses Ruby's net/scp library. The
@@ -169,10 +136,10 @@ module Beaker
169
136
  #
170
137
  # @return [Result] Returns the result of the SCP operation
171
138
  def scp_from host, from_path, to_path, opts = {}
172
- block_on host do | host |
173
- @result = host.do_scp_from(from_path, to_path, opts)
174
- @result.log logger
175
- @result
139
+ block_on host do |host|
140
+ result = host.do_scp_from(from_path, to_path, opts)
141
+ result.log logger
142
+ result
176
143
  end
177
144
  end
178
145
 
@@ -192,14 +159,14 @@ module Beaker
192
159
  #
193
160
  # @return [Result] Returns the result of the SCP operation
194
161
  def scp_to host, from_path, to_path, opts = {}
195
- block_on host do | host |
162
+ block_on host do |host|
196
163
  if host['platform'].include?('windows') && to_path.match('`cygpath')
197
164
  result = on host, "echo #{to_path}"
198
165
  to_path = result.raw_output.chomp
199
166
  end
200
- @result = host.do_scp_to(from_path, to_path, opts)
201
- @result.log logger
202
- @result
167
+ result = host.do_scp_to(from_path, to_path, opts)
168
+ result.log logger
169
+ result
203
170
  end
204
171
  end
205
172
 
@@ -214,13 +181,12 @@ module Beaker
214
181
  #
215
182
  # @return [Result] Returns the result of the rsync operation
216
183
  def rsync_to host, from_path, to_path, opts = {}
217
- block_on host do | host |
184
+ block_on host do |host|
218
185
  if host['platform'].include?('windows') && to_path.match('`cygpath')
219
186
  result = host.echo "#{to_path}"
220
187
  to_path = result.raw_output.chomp
221
188
  end
222
- @result = host.do_rsync_to(from_path, to_path, opts)
223
- @result
189
+ host.do_rsync_to(from_path, to_path, opts)
224
190
  end
225
191
  end
226
192
 
@@ -268,9 +234,8 @@ module Beaker
268
234
  FileUtils.mkdir_p(targetdir)
269
235
  scp_from(host, from_path, targetdir, opts)
270
236
  # scp_from does succeed on a non-existant file, checking if the file/folder actually exists
271
- if not File.exist?(filename)
272
- raise IOError, "No such file or directory - #{filename}"
273
- end
237
+ raise IOError, "No such file or directory - #{filename}" if not File.exist?(filename)
238
+
274
239
  create_tarball(archive_root, archive_name)
275
240
  end
276
241
 
@@ -281,28 +246,6 @@ module Beaker
281
246
  end
282
247
  private :create_tarball
283
248
 
284
-
285
- # Deploy packaging configurations generated by
286
- # https://github.com/puppetlabs/packaging to a host.
287
- #
288
- # @note To ensure the repo configs are available for deployment,
289
- # you should run `rake pl:jenkins:deb_repo_configs` and
290
- # `rake pl:jenkins:rpm_repo_configs` on your project checkout
291
- #
292
- # @param [Host] host
293
- # @param [String] path The path to the generated repository config
294
- # files. ex: /myproject/pkg/repo_configs
295
- # @param [String] name A human-readable name for the repository
296
- # @param [String] version The version of the project, as used by the
297
- # packaging tools. This can be determined with
298
- # `rake pl:print_build_params` from the packaging
299
- # repo.
300
- # @deprecated no longer used in beaker, beaker-puppet, or beaker-pe
301
- # @visibility private
302
- def deploy_package_repo host, path, name, version
303
- host.deploy_package_repo path, name, version
304
- end
305
-
306
249
  # Create a remote file out of a string
307
250
  # @note This method uses Tempfile in Ruby's STDLIB as well as {#scp_to}.
308
251
  #
@@ -318,17 +261,17 @@ module Beaker
318
261
  # @return [Result] Returns the result of the underlying SCP operation.
319
262
  def create_remote_file(hosts, file_path, file_content, opts = {})
320
263
  Tempfile.open 'beaker' do |tempfile|
321
- File.open(tempfile.path, 'w') {|file| file.puts file_content }
264
+ File.open(tempfile.path, 'w') { |file| file.puts file_content }
322
265
 
323
266
  opts[:protocol] ||= 'scp'
324
267
  case opts[:protocol]
325
- when 'scp'
326
- scp_to hosts, tempfile.path, file_path, opts
327
- when 'rsync'
328
- rsync_to hosts, tempfile.path, file_path, opts
329
- else
330
- logger.debug "Unsupported transfer protocol, returning nil"
331
- nil
268
+ when 'scp'
269
+ scp_to hosts, tempfile.path, file_path, opts
270
+ when 'rsync'
271
+ rsync_to hosts, tempfile.path, file_path, opts
272
+ else
273
+ logger.debug "Unsupported transfer protocol, returning nil"
274
+ nil
332
275
  end
333
276
  end
334
277
  end
@@ -349,9 +292,8 @@ module Beaker
349
292
  script_path = "beaker_powershell_script_#{Time.now.to_i}.ps1"
350
293
  create_remote_file(host, script_path, powershell_script, opts)
351
294
  native_path = script_path.tr('/', "\\")
352
- on host, powershell("", {"File" => native_path }), opts
295
+ on host, powershell("", { "File" => native_path }), opts
353
296
  end
354
-
355
297
  end
356
298
 
357
299
  # Move a local script to a remote host and execute it
@@ -430,13 +372,11 @@ module Beaker
430
372
  #
431
373
  # @return nil
432
374
  def add_system32_hosts_entry(host, opts = {})
433
- if host.is_powershell?
434
- hosts_file = 'C:\Windows\System32\Drivers\etc\hosts'
435
- host_entry = "#{opts['ip']}`t`t#{opts['name']}"
436
- on host, powershell("\$text = \\\"#{host_entry}\\\"; Add-Content -path '#{hosts_file}' -value \$text")
437
- else
438
- raise "nothing to do for #{host.name} on #{host['platform']}"
439
- end
375
+ raise "nothing to do for #{host.name} on #{host['platform']}" unless host.is_powershell?
376
+
377
+ hosts_file = 'C:\Windows\System32\Drivers\etc\hosts'
378
+ host_entry = "#{opts['ip']}`t`t#{opts['name']}"
379
+ on host, powershell("\$text = \\\"#{host_entry}\\\"; Add-Content -path '#{hosts_file}' -value \$text")
440
380
  end
441
381
 
442
382
  # Back up the given file in the current_dir to the new_dir
@@ -449,12 +389,11 @@ module Beaker
449
389
  # @return [String, nil] The path to the file if the file exists, nil if it
450
390
  # doesn't exist.
451
391
  def backup_the_file host, current_dir, new_dir, filename = 'puppet.conf'
452
-
453
392
  old_location = current_dir + '/' + filename
454
393
  new_location = new_dir + '/' + filename + '.bak'
455
394
 
456
395
  if host.file_exist? old_location
457
- host.exec( Command.new( "cp #{old_location} #{new_location}" ) )
396
+ host.exec(Command.new("cp #{old_location} #{new_location}"))
458
397
  return new_location
459
398
  else
460
399
  logger.warn "Could not backup file '#{old_location}': no such file"
@@ -471,7 +410,7 @@ module Beaker
471
410
  def win_ads_path(file_path)
472
411
  ads_path = {
473
412
  path: file_path,
474
- ads: nil
413
+ ads: nil,
475
414
  }
476
415
 
477
416
  split_path = file_path.split(':')
@@ -506,7 +445,7 @@ module Beaker
506
445
  command = %(test -f "#{file_path}")
507
446
  end
508
447
 
509
- return on(host, command, { :accept_all_exit_codes => true}).exit_code.zero?
448
+ return on(host, command, { :accept_all_exit_codes => true }).exit_code.zero?
510
449
  end
511
450
 
512
451
  # Check whether a directory exists on the host
@@ -584,7 +523,7 @@ module Beaker
584
523
  opts = {
585
524
  :desired_exit_codes => desired_exit_codes,
586
525
  :max_retries => max_retries,
587
- :retry_interval => retry_interval
526
+ :retry_interval => retry_interval,
588
527
  }
589
528
  retry_on(host, "curl -m 1 #{url}", opts)
590
529
  end
@@ -614,22 +553,22 @@ module Beaker
614
553
  option_retry_interval = opts[:retry_interval].to_f
615
554
  desired_exit_codes = option_exit_codes ? [option_exit_codes].flatten : [0]
616
555
  desired_exit_codes = [0] if desired_exit_codes.empty?
617
- max_retries = option_max_retries == 0 ? 60 : option_max_retries # nil & "" both return 0
556
+ max_retries = option_max_retries == 0 ? 60 : option_max_retries # nil & "" both return 0
618
557
  retry_interval = option_retry_interval == 0 ? 1 : option_retry_interval
619
558
  verbose = true.to_s == opts[:verbose]
620
559
 
621
560
  log_prefix = host.log_prefix
622
561
  logger.debug "\n#{log_prefix} #{Time.new.strftime('%H:%M:%S')}$ #{command}"
623
562
  logger.debug " Trying command #{max_retries} times."
624
- logger.debug ".", add_newline=false
563
+ logger.debug ".", add_newline = false
625
564
 
626
- result = on host, command, {:accept_all_exit_codes => true, :silent => !verbose}, &block
565
+ result = on host, command, { :accept_all_exit_codes => true, :silent => !verbose }, &block
627
566
  num_retries = 0
628
567
  until desired_exit_codes.include?(result.exit_code)
629
568
  sleep retry_interval
630
- result = on host, command, {:accept_all_exit_codes => true, :silent => !verbose}, &block
569
+ result = on host, command, { :accept_all_exit_codes => true, :silent => !verbose }, &block
631
570
  num_retries += 1
632
- logger.debug ".", add_newline=false
571
+ logger.debug ".", add_newline = false
633
572
  if (num_retries > max_retries)
634
573
  logger.debug " Command \`#{command}\` failed."
635
574
  fail("Command \`#{command}\` failed.")
@@ -641,34 +580,34 @@ module Beaker
641
580
 
642
581
  # FIX: this should be moved into host/platform
643
582
  # @visibility private
644
- def run_cron_on(host, action, user, entry="", &block)
645
- block_on host do | host |
583
+ def run_cron_on(host, action, user, entry = "", &block)
584
+ block_on host do |host|
646
585
  platform = host['platform']
647
586
  if platform.include?('solaris') || platform.include?('aix') then
648
587
  case action
649
- when :list then args = '-l'
650
- when :remove then args = '-r'
651
- when :add
652
- on( host,
653
- "echo '#{entry}' > /var/spool/cron/crontabs/#{user}",
654
- &block )
588
+ when :list then args = '-l'
589
+ when :remove then args = '-r'
590
+ when :add
591
+ on(host,
592
+ "echo '#{entry}' > /var/spool/cron/crontabs/#{user}",
593
+ &block)
655
594
  end
656
595
 
657
596
  else # default for GNU/Linux platforms
658
597
  case action
659
- when :list then args = '-l -u'
660
- when :remove then args = '-r -u'
661
- when :add
662
- on( host,
663
- "echo '#{entry}' > /tmp/#{user}.cron && " +
664
- "crontab -u #{user} /tmp/#{user}.cron",
665
- &block )
598
+ when :list then args = '-l -u'
599
+ when :remove then args = '-r -u'
600
+ when :add
601
+ on(host,
602
+ "echo '#{entry}' > /tmp/#{user}.cron && " +
603
+ "crontab -u #{user} /tmp/#{user}.cron",
604
+ &block)
666
605
  end
667
606
  end
668
607
 
669
608
  if args
670
609
  case action
671
- when :list, :remove then on(host, "crontab #{args} #{user}", &block)
610
+ when :list, :remove then on(host, "crontab #{args} #{user}", &block)
672
611
  end
673
612
  end
674
613
  end
@@ -4,12 +4,11 @@ module Beaker
4
4
  # Methods that help you query the state of your tests, these
5
5
  # methods do not require puppet to be installed to execute correctly
6
6
  module TestHelpers
7
-
8
7
  # Gets the currently executing test's name, which is set in a test
9
8
  # using the {Beaker::DSL::Structure#test_name} method.
10
9
  #
11
10
  # @return [String] Test name, or nil if it hasn't been set
12
- def current_test_name()
11
+ def current_test_name
13
12
  metadata[:case] && metadata[:case][:name] ? metadata[:case][:name] : nil
14
13
  end
15
14
 
@@ -21,7 +20,7 @@ module Beaker
21
20
  # canal
22
21
  #
23
22
  # @return [String] Test filename, or nil if it hasn't been set
24
- def current_test_filename()
23
+ def current_test_filename
25
24
  metadata[:case] && metadata[:case][:file_name] ? metadata[:case][:file_name] : nil
26
25
  end
27
26
 
@@ -29,7 +28,7 @@ module Beaker
29
28
  # This is set using the {Beaker::DSL::Structure#step} method.
30
29
  #
31
30
  # @return [String] Step name, or nil if it hasn't been set
32
- def current_step_name()
31
+ def current_step_name
33
32
  metadata[:step] && metadata[:step][:name] ? metadata[:step][:name] : nil
34
33
  end
35
34
 
@@ -65,7 +64,6 @@ module Beaker
65
64
  metadata[:step] ||= {}
66
65
  metadata[:step][:name] = name
67
66
  end
68
-
69
67
  end
70
68
  end
71
69
  end
@@ -3,22 +3,21 @@ module Beaker
3
3
  module Helpers
4
4
  # Convenience methods for checking links and moving web content to hosts
5
5
  module WebHelpers
6
-
7
6
  # Blocks until the port is open on the host specified, returns false
8
7
  # on failure
9
- def port_open_within?( host, port = 8140, seconds = 120 )
10
- repeat_for( seconds ) do
11
- host.port_open?( port )
8
+ def port_open_within?(host, port = 8140, seconds = 120)
9
+ repeat_for(seconds) do
10
+ host.port_open?(port)
12
11
  end
13
12
  end
14
13
 
15
- #Determine is a given URL is accessible
16
- #@param [String] link The URL to examine
17
- #@param [Integer] limit redirect limit, will follow redirects that many times
18
- #@return [Boolean] true if the ultimate URL after following redirects (301&302) has a '200' HTTP response code, false otherwise
19
- #@example
14
+ # Determine is a given URL is accessible
15
+ # @param [String] link The URL to examine
16
+ # @param [Integer] limit redirect limit, will follow redirects that many times
17
+ # @return [Boolean] true if the ultimate URL after following redirects (301&302) has a '200' HTTP response code, false otherwise
18
+ # @example
20
19
  # extension = link_exists?("#{URL}.tar.gz") ? ".tar.gz" : ".tar"
21
- def link_exists?(link, limit=10)
20
+ def link_exists?(link, limit = 10)
22
21
  begin
23
22
  require "net/http"
24
23
  require "net/https"
@@ -28,7 +27,7 @@ module Beaker
28
27
  http.use_ssl = (url.scheme == 'https')
29
28
  http.verify_mode = (OpenSSL::SSL::VERIFY_NONE)
30
29
  response = http.start { |http| http.head(url.request_uri) }
31
- if (['301', '302'].include? response.code) && limit > 0
30
+ if (%w[301 302].include? response.code) && limit > 0
32
31
  logger.debug("#{__method__} following #{response.code} to #{response['location']}")
33
32
  link_exists?(response['location'], limit - 1)
34
33
  else
@@ -62,34 +61,19 @@ module Beaker
62
61
  logger.notify "Fetching: #{src}"
63
62
  logger.notify " and saving to #{dst}"
64
63
  begin
65
- uri_open(src) do |remote|
64
+ URI.open(src) do |remote|
66
65
  File.open(dst, "w") do |file|
67
66
  FileUtils.copy_stream(remote, file)
68
67
  end
69
68
  end
70
69
  rescue OpenURI::HTTPError => e
71
- if /404.*/.match?(e.message)
72
- raise "Failed to fetch_remote_file '#{src}' (#{e.message})"
73
- else
74
- raise e
75
- end
76
- end
77
- end
78
- return dst
79
- end
70
+ raise "Failed to fetch_remote_file '#{src}' (#{e.message})" if /404.*/.match?(e.message)
80
71
 
81
- def uri_open(src)
82
- if RUBY_VERSION.to_f < 2.5
83
- URI.send(:open, src) do |remote|
84
- yield remote
85
- end
86
- else
87
- URI.open(src) do |remote|
88
- yield remote
72
+ raise e
89
73
  end
90
74
  end
75
+ return dst
91
76
  end
92
- private :uri_open
93
77
 
94
78
  # Recursively fetch the contents of the given http url, ignoring
95
79
  # `index.html` and `*.gif` files.
@@ -104,14 +88,12 @@ module Beaker
104
88
  # @!visibility private
105
89
  def fetch_http_dir(url, dst_dir)
106
90
  logger.notify "fetch_http_dir (url: #{url}, dst_dir #{dst_dir})"
107
- if !url.end_with?('/')
108
- url += '/'
109
- end
91
+ url += '/' if !url.end_with?('/')
110
92
  url = URI.parse(url)
111
93
  chunks = url.path.split('/')
112
94
  dst = File.join(dst_dir, chunks.last)
113
- #determine directory structure to cut
114
- #only want to keep the last directory, thus cut total number of dirs - 2 (hostname + last dir name)
95
+ # determine directory structure to cut
96
+ # only want to keep the last directory, thus cut total number of dirs - 2 (hostname + last dir name)
115
97
  cut = chunks.length - 2
116
98
  wget_command = "wget -nv -P #{dst_dir} --reject \"index.html*\",\"*.gif\" --cut-dirs=#{cut} -np -nH --no-check-certificate -r #{url}"
117
99
 
@@ -123,12 +105,10 @@ module Beaker
123
105
  stdout_and_stderr_str.each_line do |line|
124
106
  logger.debug(line)
125
107
  end
126
- unless status.success?
127
- raise "Failed to fetch_remote_dir '#{url}' (exit code #{$?})"
128
- end
108
+ raise "Failed to fetch_remote_dir '#{url}' (exit code #{$?})" unless status.success?
109
+
129
110
  dst
130
111
  end
131
-
132
112
  end
133
113
  end
134
114
  end
@@ -1,11 +1,9 @@
1
- # -*- coding: utf-8 -*-
2
- [ 'host', 'test', 'web', 'hocon' ].each do |lib|
3
- require "beaker/dsl/helpers/#{lib}_helpers"
1
+ %w[host test web hocon].each do |lib|
2
+ require "beaker/dsl/helpers/#{lib}_helpers"
4
3
  end
5
4
 
6
5
  module Beaker
7
6
  module DSL
8
-
9
7
  # Contains methods to help you manage and configure your SUTs.
10
8
 
11
9
  # Extensions, available in separate modules, enable you to configure and interact with puppet, facter