beaker 4.40.2 → 5.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (217) hide show
  1. checksums.yaml +4 -4
  2. data/.github/dependabot.yml +9 -0
  3. data/.github/workflows/release.yml +2 -2
  4. data/.github/workflows/test.yml +26 -13
  5. data/.rubocop.yml +23 -10
  6. data/.rubocop_todo.yml +34 -10
  7. data/CHANGELOG.md +17 -28
  8. data/Gemfile +12 -7
  9. data/Rakefile +99 -111
  10. data/acceptance/config/acceptance-options.rb +1 -1
  11. data/acceptance/config/base/acceptance-options.rb +2 -2
  12. data/acceptance/config/hypervisor/acceptance-options.rb +2 -2
  13. data/acceptance/config/subcommands/acceptance-options.rb +2 -2
  14. data/acceptance/fixtures/module/Rakefile +1 -1
  15. data/acceptance/fixtures/module/spec/acceptance/demo_spec.rb +8 -12
  16. data/acceptance/fixtures/module/spec/classes/init_spec.rb +0 -1
  17. data/acceptance/fixtures/module/spec/spec_helper_acceptance.rb +3 -5
  18. data/acceptance/lib/helpers/test_helper.rb +6 -5
  19. data/acceptance/pre_suite/subcommands/05_install_ruby.rb +2 -3
  20. data/acceptance/pre_suite/subcommands/08_install_beaker.rb +1 -2
  21. data/acceptance/tests/base/dsl/helpers/configuration_test.rb +4 -4
  22. data/acceptance/tests/base/dsl/helpers/hocon_helpers_test.rb +1 -2
  23. data/acceptance/tests/base/dsl/helpers/host_helpers/add_system32_hosts_entry_test.rb +0 -3
  24. data/acceptance/tests/base/dsl/helpers/host_helpers/archive_file_from_test.rb +3 -1
  25. data/acceptance/tests/base/dsl/helpers/host_helpers/backup_the_file_test.rb +9 -9
  26. data/acceptance/tests/base/dsl/helpers/host_helpers/check_for_package_test.rb +0 -4
  27. data/acceptance/tests/base/dsl/helpers/host_helpers/create_remote_file_test.rb +19 -26
  28. data/acceptance/tests/base/dsl/helpers/host_helpers/curl_on_test.rb +2 -2
  29. data/acceptance/tests/base/dsl/helpers/host_helpers/curl_with_retries_test.rb +0 -1
  30. data/acceptance/tests/base/dsl/helpers/host_helpers/on_test.rb +18 -13
  31. data/acceptance/tests/base/dsl/helpers/host_helpers/retry_on_test.rb +3 -3
  32. data/acceptance/tests/base/dsl/helpers/host_helpers/rsync_to_test.rb +22 -27
  33. data/acceptance/tests/base/dsl/helpers/host_helpers/run_cron_on_test.rb +12 -16
  34. data/acceptance/tests/base/dsl/helpers/host_helpers/run_script_on_test.rb +3 -4
  35. data/acceptance/tests/base/dsl/helpers/host_helpers/run_script_test.rb +3 -3
  36. data/acceptance/tests/base/dsl/helpers/host_helpers/scp_from_test.rb +4 -4
  37. data/acceptance/tests/base/dsl/helpers/host_helpers/scp_to_test.rb +3 -4
  38. data/acceptance/tests/base/dsl/helpers/host_helpers/shell_test.rb +5 -5
  39. data/acceptance/tests/base/dsl/helpers/host_helpers/upgrade_package_test.rb +3 -5
  40. data/acceptance/tests/base/dsl/platform_tag_confiner_test.rb +14 -17
  41. data/acceptance/tests/base/dsl/structure_test.rb +5 -11
  42. data/acceptance/tests/base/host/file_test.rb +2 -2
  43. data/acceptance/tests/base/host/group_test.rb +0 -1
  44. data/acceptance/tests/base/host/host_test.rb +66 -63
  45. data/acceptance/tests/base/host/packages.rb +1 -2
  46. data/acceptance/tests/base/host/packages_unix.rb +0 -55
  47. data/acceptance/tests/base/host/user_test.rb +0 -1
  48. data/acceptance/tests/base/host_prebuilt_steps/ssh_environment_test.rb +1 -2
  49. data/acceptance/tests/base/test_suite/export.rb +6 -9
  50. data/acceptance/tests/install/from_file.rb +2 -4
  51. data/acceptance/tests/load_path_bootstrap.rb +1 -1
  52. data/acceptance/tests/subcommands/destroy.rb +19 -21
  53. data/acceptance/tests/subcommands/exec.rb +0 -1
  54. data/acceptance/tests/subcommands/init.rb +2 -3
  55. data/acceptance/tests/subcommands/provision.rb +0 -1
  56. data/beaker.gemspec +4 -7
  57. data/docs/concepts/argument_processing_and_precedence.md +1 -10
  58. data/docs/how_to/debug_beaker_tests.md +12 -12
  59. data/docs/how_to/hosts/eos.md +2 -12
  60. data/docs/how_to/install_puppet.md +0 -18
  61. data/docs/how_to/the_beaker_dsl.md +0 -2
  62. data/lib/beaker/cli.rb +59 -68
  63. data/lib/beaker/command.rb +20 -28
  64. data/lib/beaker/command_factory.rb +3 -2
  65. data/lib/beaker/dsl/assertions.rb +6 -18
  66. data/lib/beaker/dsl/helpers/hocon_helpers.rb +3 -7
  67. data/lib/beaker/dsl/helpers/host_helpers.rb +62 -123
  68. data/lib/beaker/dsl/helpers/test_helpers.rb +3 -5
  69. data/lib/beaker/dsl/helpers/web_helpers.rb +19 -39
  70. data/lib/beaker/dsl/helpers.rb +2 -4
  71. data/lib/beaker/dsl/outcomes.rb +13 -15
  72. data/lib/beaker/dsl/patterns.rb +1 -3
  73. data/lib/beaker/dsl/roles.rb +17 -20
  74. data/lib/beaker/dsl/structure.rb +53 -65
  75. data/lib/beaker/dsl/test_tagging.rb +7 -10
  76. data/lib/beaker/dsl/wrappers.rb +15 -16
  77. data/lib/beaker/dsl.rb +2 -3
  78. data/lib/beaker/host/aix/exec.rb +1 -1
  79. data/lib/beaker/host/aix/file.rb +0 -1
  80. data/lib/beaker/host/aix/group.rb +1 -1
  81. data/lib/beaker/host/aix/user.rb +1 -1
  82. data/lib/beaker/host/aix.rb +3 -4
  83. data/lib/beaker/host/cisco.rb +27 -39
  84. data/lib/beaker/host/eos.rb +4 -30
  85. data/lib/beaker/host/freebsd/exec.rb +1 -1
  86. data/lib/beaker/host/freebsd/pkg.rb +3 -3
  87. data/lib/beaker/host/freebsd.rb +9 -12
  88. data/lib/beaker/host/mac/exec.rb +4 -4
  89. data/lib/beaker/host/mac/group.rb +7 -7
  90. data/lib/beaker/host/mac/pkg.rb +3 -106
  91. data/lib/beaker/host/mac/user.rb +2 -2
  92. data/lib/beaker/host/mac.rb +8 -9
  93. data/lib/beaker/host/pswindows/exec.rb +66 -70
  94. data/lib/beaker/host/pswindows/file.rb +3 -5
  95. data/lib/beaker/host/pswindows/group.rb +3 -3
  96. data/lib/beaker/host/pswindows/pkg.rb +12 -12
  97. data/lib/beaker/host/pswindows/user.rb +3 -3
  98. data/lib/beaker/host/pswindows.rb +4 -3
  99. data/lib/beaker/host/unix/exec.rb +80 -82
  100. data/lib/beaker/host/unix/file.rb +38 -43
  101. data/lib/beaker/host/unix/group.rb +1 -1
  102. data/lib/beaker/host/unix/pkg.rb +154 -417
  103. data/lib/beaker/host/unix/user.rb +2 -2
  104. data/lib/beaker/host/unix.rb +8 -11
  105. data/lib/beaker/host/windows/exec.rb +17 -17
  106. data/lib/beaker/host/windows/file.rb +3 -3
  107. data/lib/beaker/host/windows/group.rb +3 -3
  108. data/lib/beaker/host/windows/pkg.rb +3 -54
  109. data/lib/beaker/host/windows/user.rb +3 -3
  110. data/lib/beaker/host/windows.rb +12 -12
  111. data/lib/beaker/host.rb +76 -133
  112. data/lib/beaker/host_prebuilt_steps.rb +93 -198
  113. data/lib/beaker/hypervisor/noop.rb +2 -4
  114. data/lib/beaker/hypervisor.rb +44 -61
  115. data/lib/beaker/local_connection.rb +2 -4
  116. data/lib/beaker/logger.rb +68 -76
  117. data/lib/beaker/logger_junit.rb +21 -25
  118. data/lib/beaker/network_manager.rb +39 -42
  119. data/lib/beaker/options/command_line_parser.rb +12 -23
  120. data/lib/beaker/options/hosts_file_parser.rb +16 -24
  121. data/lib/beaker/options/options_file_parser.rb +3 -6
  122. data/lib/beaker/options/options_hash.rb +2 -7
  123. data/lib/beaker/options/parser.rb +86 -102
  124. data/lib/beaker/options/presets.rb +114 -123
  125. data/lib/beaker/options/subcommand_options_file_parser.rb +3 -6
  126. data/lib/beaker/options/validator.rb +26 -31
  127. data/lib/beaker/perf.rb +22 -27
  128. data/lib/beaker/platform.rb +38 -46
  129. data/lib/beaker/result.rb +7 -6
  130. data/lib/beaker/shared/error_handler.rb +8 -10
  131. data/lib/beaker/shared/fog_credentials.rb +5 -9
  132. data/lib/beaker/shared/host_manager.rb +36 -41
  133. data/lib/beaker/shared/options_resolver.rb +3 -7
  134. data/lib/beaker/shared/repetition.rb +2 -4
  135. data/lib/beaker/shared/semvar.rb +37 -41
  136. data/lib/beaker/shared/timed.rb +0 -3
  137. data/lib/beaker/shared.rb +1 -1
  138. data/lib/beaker/ssh_connection.rb +38 -47
  139. data/lib/beaker/subcommand.rb +17 -24
  140. data/lib/beaker/subcommands/subcommand_util.rb +4 -4
  141. data/lib/beaker/tasks/quick_start.rb +4 -9
  142. data/lib/beaker/tasks/rake_task.rb +25 -27
  143. data/lib/beaker/tasks/test.rb +4 -4
  144. data/lib/beaker/test_case.rb +16 -28
  145. data/lib/beaker/test_suite.rb +35 -39
  146. data/lib/beaker/test_suite_result.rb +45 -47
  147. data/lib/beaker/version.rb +1 -1
  148. data/lib/beaker.rb +6 -7
  149. data/spec/beaker/cli_spec.rb +121 -142
  150. data/spec/beaker/command_spec.rb +55 -59
  151. data/spec/beaker/dsl/assertions_spec.rb +36 -36
  152. data/spec/beaker/dsl/helpers/host_helpers_spec.rb +110 -131
  153. data/spec/beaker/dsl/helpers/test_helpers_spec.rb +9 -10
  154. data/spec/beaker/dsl/helpers/web_helpers_spec.rb +22 -31
  155. data/spec/beaker/dsl/outcomes_spec.rb +14 -14
  156. data/spec/beaker/dsl/roles_spec.rb +125 -130
  157. data/spec/beaker/dsl/structure_spec.rb +172 -161
  158. data/spec/beaker/dsl/test_tagging_spec.rb +89 -90
  159. data/spec/beaker/dsl/wrappers_spec.rb +32 -33
  160. data/spec/beaker/host/aix_spec.rb +14 -14
  161. data/spec/beaker/host/cisco_spec.rb +84 -94
  162. data/spec/beaker/host/eos_spec.rb +15 -36
  163. data/spec/beaker/host/freebsd/exec_spec.rb +3 -6
  164. data/spec/beaker/host/freebsd/pkg_spec.rb +24 -27
  165. data/spec/beaker/host/mac/exec_spec.rb +2 -3
  166. data/spec/beaker/host/mac/group_spec.rb +48 -57
  167. data/spec/beaker/host/mac/user_spec.rb +54 -63
  168. data/spec/beaker/host/pswindows/exec_spec.rb +30 -32
  169. data/spec/beaker/host/pswindows/file_spec.rb +16 -16
  170. data/spec/beaker/host/pswindows/user_spec.rb +17 -23
  171. data/spec/beaker/host/pswindows_spec.rb +13 -13
  172. data/spec/beaker/host/unix/exec_spec.rb +75 -80
  173. data/spec/beaker/host/unix/file_spec.rb +66 -73
  174. data/spec/beaker/host/unix/pkg_spec.rb +155 -401
  175. data/spec/beaker/host/unix_spec.rb +11 -207
  176. data/spec/beaker/host/windows/exec_spec.rb +30 -32
  177. data/spec/beaker/host/windows/file_spec.rb +18 -19
  178. data/spec/beaker/host/windows/group_spec.rb +10 -12
  179. data/spec/beaker/host/windows/pkg_spec.rb +6 -9
  180. data/spec/beaker/host/windows/user_spec.rb +17 -23
  181. data/spec/beaker/host/windows_spec.rb +39 -39
  182. data/spec/beaker/host_prebuilt_steps_spec.rb +172 -326
  183. data/spec/beaker/host_spec.rb +204 -284
  184. data/spec/beaker/hypervisor/hypervisor_spec.rb +36 -61
  185. data/spec/beaker/localhost_connection_spec.rb +10 -11
  186. data/spec/beaker/logger_junit_spec.rb +19 -30
  187. data/spec/beaker/logger_spec.rb +153 -136
  188. data/spec/beaker/network_manager_spec.rb +23 -23
  189. data/spec/beaker/options/command_line_parser_spec.rb +20 -23
  190. data/spec/beaker/options/hosts_file_parser_spec.rb +30 -32
  191. data/spec/beaker/options/options_file_parser_spec.rb +4 -7
  192. data/spec/beaker/options/options_hash_spec.rb +4 -6
  193. data/spec/beaker/options/parser_spec.rb +167 -167
  194. data/spec/beaker/options/presets_spec.rb +7 -9
  195. data/spec/beaker/options/subcommand_options_parser_spec.rb +13 -14
  196. data/spec/beaker/options/validator_spec.rb +10 -11
  197. data/spec/beaker/perf_spec.rb +18 -21
  198. data/spec/beaker/platform_spec.rb +25 -36
  199. data/spec/beaker/shared/error_handler_spec.rb +7 -16
  200. data/spec/beaker/shared/fog_credentials_spec.rb +29 -29
  201. data/spec/beaker/shared/host_manager_spec.rb +50 -84
  202. data/spec/beaker/shared/options_resolver_spec.rb +9 -12
  203. data/spec/beaker/shared/repetition_spec.rb +17 -24
  204. data/spec/beaker/shared/semvar_spec.rb +21 -26
  205. data/spec/beaker/ssh_connection_spec.rb +76 -83
  206. data/spec/beaker/subcommand/subcommand_util_spec.rb +31 -33
  207. data/spec/beaker/subcommand_spec.rb +75 -77
  208. data/spec/beaker/test_case_spec.rb +25 -50
  209. data/spec/beaker/test_suite_spec.rb +147 -154
  210. data/spec/helpers.rb +48 -53
  211. data/spec/matchers.rb +8 -7
  212. data/spec/mocks.rb +1 -6
  213. data/spec/spec_helper.rb +0 -1
  214. metadata +7 -24
  215. data/acceptance/tests/base/dsl/helpers/host_helpers/deploy_package_repo_test.rb +0 -142
  216. data/acceptance/tests/base/external_resources_test.rb +0 -31
  217. data/spec/beaker/host/mac_spec.rb +0 -113
@@ -1,9 +1,8 @@
1
1
  module Beaker
2
2
  module Options
3
- #A class representing the environment variables and preset argument values to be incorporated
4
- #into the Beaker options Object.
3
+ # A class representing the environment variables and preset argument values to be incorporated
4
+ # into the Beaker options Object.
5
5
  class Presets
6
-
7
6
  # This is a constant that describes the variables we want to collect
8
7
  # from the environment. The keys correspond to the keys in
9
8
  # `presets` (flattened) The values are an optional array of
@@ -15,39 +14,37 @@ module Beaker
15
14
  # 'JOB_NAME' and 'BUILD_URL' envs are supplied by Jenkins
16
15
  # https://wiki.jenkins-ci.org/display/JENKINS/Building+a+software+project
17
16
  ENVIRONMENT_SPEC = {
18
- :home => 'HOME',
19
- :project => ['BEAKER_PROJECT', 'BEAKER_project', 'JOB_NAME'],
20
- :department => ['BEAKER_DEPARTMENT', 'BEAKER_department'],
21
- :jenkins_build_url => ['BEAKER_BUILD_URL', 'BUILD_URL'],
22
- :created_by => ['BEAKER_CREATED_BY'],
23
- :consoleport => ['BEAKER_CONSOLEPORT', 'consoleport'],
24
- :is_pe => ['BEAKER_IS_PE', 'IS_PE'],
25
- :pe_dir => ['BEAKER_PE_DIR', 'pe_dist_dir'],
17
+ :home => 'HOME',
18
+ :project => %w[BEAKER_PROJECT BEAKER_project JOB_NAME],
19
+ :department => %w[BEAKER_DEPARTMENT BEAKER_department],
20
+ :jenkins_build_url => %w[BEAKER_BUILD_URL BUILD_URL],
21
+ :created_by => ['BEAKER_CREATED_BY'],
22
+ :consoleport => %w[BEAKER_CONSOLEPORT consoleport],
23
+ :is_pe => %w[BEAKER_IS_PE IS_PE],
24
+ :pe_dir => %w[BEAKER_PE_DIR pe_dist_dir],
26
25
  :puppet_agent_version => ['BEAKER_PUPPET_AGENT_VERSION'],
27
- :puppet_agent_sha => ['BEAKER_PUPPET_AGENT_SHA'],
28
- :puppet_collection => ['BEAKER_PUPPET_COLLECTION'],
29
- :pe_version_file => ['BEAKER_PE_VERSION_FILE', 'pe_version_file'],
30
- :pe_ver => ['BEAKER_PE_VER', 'pe_ver'],
31
- :forge_host => ['BEAKER_FORGE_HOST', 'forge_host'],
32
- :package_proxy => ['BEAKER_PACKAGE_PROXY'],
33
- :release_apt_repo_url => ['BEAKER_RELEASE_APT_REPO', 'RELEASE_APT_REPO'],
34
- :release_yum_repo_url => ['BEAKER_RELEASE_YUM_REPO', 'RELEASE_YUM_REPO'],
35
- :dev_builds_url => ['BEAKER_DEV_BUILDS_URL', 'DEV_BUILDS_URL'],
36
- :vbguest_plugin => ['BEAKER_VB_GUEST_PLUGIN', 'BEAKER_vb_guest_plugin'],
37
- :test_tag_and => ['BEAKER_TAG', 'BEAKER_TEST_TAG_AND'],
38
- :test_tag_or => ['BEAKER_TEST_TAG_OR'],
39
- :test_tag_exclude => ['BEAKER_EXCLUDE_TAG', 'BEAKER_TEST_TAG_EXCLUDE'],
40
- :run_in_parallel => ['BEAKER_RUN_IN_PARALLEL'],
26
+ :puppet_agent_sha => ['BEAKER_PUPPET_AGENT_SHA'],
27
+ :puppet_collection => ['BEAKER_PUPPET_COLLECTION'],
28
+ :pe_version_file => %w[BEAKER_PE_VERSION_FILE pe_version_file],
29
+ :pe_ver => %w[BEAKER_PE_VER pe_ver],
30
+ :forge_host => %w[BEAKER_FORGE_HOST forge_host],
31
+ :package_proxy => ['BEAKER_PACKAGE_PROXY'],
32
+ :release_apt_repo_url => %w[BEAKER_RELEASE_APT_REPO RELEASE_APT_REPO],
33
+ :release_yum_repo_url => %w[BEAKER_RELEASE_YUM_REPO RELEASE_YUM_REPO],
34
+ :dev_builds_url => %w[BEAKER_DEV_BUILDS_URL DEV_BUILDS_URL],
35
+ :vbguest_plugin => %w[BEAKER_VB_GUEST_PLUGIN BEAKER_vb_guest_plugin],
36
+ :test_tag_and => %w[BEAKER_TAG BEAKER_TEST_TAG_AND],
37
+ :test_tag_or => ['BEAKER_TEST_TAG_OR'],
38
+ :test_tag_exclude => %w[BEAKER_EXCLUDE_TAG BEAKER_TEST_TAG_EXCLUDE],
39
+ :run_in_parallel => ['BEAKER_RUN_IN_PARALLEL'],
41
40
  }
42
41
 
43
42
  # Select all environment variables whose name matches provided regex
44
43
  # @return [Hash] Hash of environment variables
45
44
  def select_env_by_regex regex
46
45
  envs = Beaker::Options::OptionsHash.new
47
- ENV.each_pair do | k, v |
48
- if /#{regex}/.match?(k.to_s)
49
- envs[k] = v
50
- end
46
+ ENV.each_pair do |k, v|
47
+ envs[k] = v if /#{regex}/.match?(k.to_s)
51
48
  end
52
49
  envs
53
50
  end
@@ -57,14 +54,12 @@ module Beaker
57
54
  # @param [Hash{Symbol=>Array,String}] env_var_spec the spec of what env vars to search for
58
55
  #
59
56
  # @return [Hash] Found environment values
60
- def collect_env_vars( env_var_spec )
61
- env_var_spec.inject({}) do |memo, key_value|
57
+ def collect_env_vars(env_var_spec)
58
+ env_var_spec.each_with_object({}) do |key_value, memo|
62
59
  key, value = key_value[0], key_value[1]
63
60
 
64
- set_env_var = Array(value).detect {|possible_variable| ENV[possible_variable] }
65
- memo[key] = ENV[set_env_var] if set_env_var
66
-
67
- memo
61
+ set_env_var = Array(value).detect { |possible_variable| ENV.fetch(possible_variable, nil) }
62
+ memo[key] = ENV.fetch(set_env_var, nil) if set_env_var
68
63
  end
69
64
  end
70
65
 
@@ -74,7 +69,7 @@ module Beaker
74
69
  # @param [Hash{Symbol=>String}] found_env_vars Environment variables to munge
75
70
  #
76
71
  # @return [Hash] Environment config values formatted appropriately
77
- def format_found_env_vars( found_env_vars )
72
+ def format_found_env_vars(found_env_vars)
78
73
  found_env_vars[:consoleport] &&= found_env_vars[:consoleport].to_i
79
74
 
80
75
  if found_env_vars[:is_pe]
@@ -88,9 +83,7 @@ module Beaker
88
83
 
89
84
  found_env_vars[:type] = type
90
85
  end
91
- if found_env_vars[:run_in_parallel]
92
- found_env_vars[:run_in_parallel] = found_env_vars[:run_in_parallel].split(',')
93
- end
86
+ found_env_vars[:run_in_parallel] = found_env_vars[:run_in_parallel].split(',') if found_env_vars[:run_in_parallel]
94
87
 
95
88
  found_env_vars[:pe_version_file_win] = found_env_vars[:pe_version_file]
96
89
  found_env_vars
@@ -102,10 +95,10 @@ module Beaker
102
95
  # empty or nil environment variables are removed from the OptionsHash
103
96
  def calculate_env_vars
104
97
  found = Beaker::Options::OptionsHash.new
105
- found = found.merge(format_found_env_vars( collect_env_vars( ENVIRONMENT_SPEC )))
98
+ found = found.merge(format_found_env_vars(collect_env_vars(ENVIRONMENT_SPEC)))
106
99
  found[:answers] = select_env_by_regex('\\Aq_')
107
100
 
108
- found.delete_if {|_key, value| value.nil? or value.empty? }
101
+ found.delete_if { |_key, value| value.nil? or value.empty? }
109
102
  found
110
103
  end
111
104
 
@@ -123,88 +116,86 @@ module Beaker
123
116
  def presets
124
117
  h = Beaker::Options::OptionsHash.new
125
118
  h.merge({
126
- :project => 'Beaker',
127
- :department => 'unknown',
128
- :created_by => ENV['USER'] || ENV['USERNAME'] || 'unknown',
129
- :host_tags => {},
130
- :openstack_api_key => ENV['OS_PASSWORD'],
131
- :openstack_username => ENV['OS_USERNAME'],
132
- :openstack_auth_url => "#{ENV['OS_AUTH_URL']}/tokens",
133
- :openstack_tenant => ENV['OS_TENANT_NAME'],
134
- :openstack_keyname => ENV['OS_KEYNAME'],
135
- :openstack_network => ENV['OS_NETWORK'],
136
- :openstack_region => ENV['OS_REGION'],
137
- :openstack_volume_support => ENV['OS_VOLUME_SUPPORT'] || true,
138
- :jenkins_build_url => nil,
139
- :validate => true,
140
- :configure => true,
141
- :log_level => 'info',
142
- :trace_limit => 10,
143
- :"master-start-curl-retries" => 120,
144
- :masterless => false,
145
- :options_file => nil,
146
- :type => 'pe',
147
- :provision => true,
148
- :preserve_hosts => 'never',
149
- :root_keys => false,
150
- :quiet => false,
151
- :project_root => File.expand_path(File.join(File.dirname(__FILE__), "../")),
152
- :xml_dir => 'junit',
153
- :xml_file => 'beaker_junit.xml',
154
- :xml_time => 'beaker_times.xml',
155
- :xml_time_enabled => false,
156
- :xml_stylesheet => 'junit.xsl',
157
- :default_log_prefix => 'beaker_logs',
158
- :log_dir => 'log',
159
- :log_sut_event => 'sut.log',
160
- :color => true,
161
- :dry_run => false,
162
- :test_tag_and => '',
163
- :test_tag_or => '',
164
- :test_tag_exclude => '',
165
- :timeout => 900, # 15 minutes
166
- :fail_mode => 'slow',
167
- :test_results_file => '',
168
- :accept_all_exit_codes => false,
169
- :timesync => false,
170
- :disable_iptables => false,
171
- :set_env => true,
172
- :disable_updates => true,
173
- :repo_proxy => false,
174
- :package_proxy => false,
175
- :add_el_extras => false,
176
- :epel_url => "http://dl.fedoraproject.org/pub/epel",
177
- :consoleport => 443,
178
- :pe_dir => '/opt/enterprise/dists',
179
- :pe_version_file => 'LATEST',
180
- :pe_version_file_win => 'LATEST-win',
181
- :host_env => {},
182
- :host_name_prefix => nil,
183
- :ssh_env_file => '~/.ssh/environment',
184
- :profile_d_env_file => '/etc/profile.d/beaker_env.sh',
185
- :dot_fog => File.join(ENV['HOME'], '.fog'),
186
- :ec2_yaml => 'config/image_templates/ec2.yaml',
187
- :help => false,
188
- :collect_perf_data => 'none',
189
- :puppetdb_port_ssl => 8081,
190
- :puppetdb_port_nonssl => 8080,
191
- :puppetserver_port => 8140,
192
- :nodeclassifier_port => 4433,
193
- :cache_files_locally => false,
194
- :aws_keyname_modifier => rand(10 ** 10).to_s.rjust(10,'0'), # 10 digit random number string
195
- :run_in_parallel => [],
196
- :use_fog_credentials => true,
197
- :ssh => {
198
- :config => false,
199
- :verify_host_key => false,
200
- :auth_methods => ["publickey"],
201
- :port => 22,
202
- :forward_agent => true,
203
- :keys => ["#{ENV['HOME']}/.ssh/id_rsa"],
204
- :user_known_hosts_file => "#{ENV['HOME']}/.ssh/known_hosts",
205
- :keepalive => true
206
- }
207
- })
119
+ :project => 'Beaker',
120
+ :department => 'unknown',
121
+ :created_by => ENV['USER'] || ENV['USERNAME'] || 'unknown',
122
+ :host_tags => {},
123
+ :openstack_api_key => ENV.fetch('OS_PASSWORD', nil),
124
+ :openstack_username => ENV.fetch('OS_USERNAME', nil),
125
+ :openstack_auth_url => "#{ENV.fetch('OS_AUTH_URL', nil)}/tokens",
126
+ :openstack_tenant => ENV.fetch('OS_TENANT_NAME', nil),
127
+ :openstack_keyname => ENV.fetch('OS_KEYNAME', nil),
128
+ :openstack_network => ENV.fetch('OS_NETWORK', nil),
129
+ :openstack_region => ENV.fetch('OS_REGION', nil),
130
+ :openstack_volume_support => ENV['OS_VOLUME_SUPPORT'] || true,
131
+ :jenkins_build_url => nil,
132
+ :validate => true,
133
+ :configure => true,
134
+ :log_level => 'info',
135
+ :trace_limit => 10,
136
+ :"master-start-curl-retries" => 120,
137
+ :masterless => false,
138
+ :options_file => nil,
139
+ :type => 'pe',
140
+ :provision => true,
141
+ :preserve_hosts => 'never',
142
+ :root_keys => false,
143
+ :quiet => false,
144
+ :project_root => File.expand_path(File.join(__dir__, "../")),
145
+ :xml_dir => 'junit',
146
+ :xml_file => 'beaker_junit.xml',
147
+ :xml_time => 'beaker_times.xml',
148
+ :xml_time_enabled => false,
149
+ :xml_stylesheet => 'junit.xsl',
150
+ :default_log_prefix => 'beaker_logs',
151
+ :log_dir => 'log',
152
+ :log_sut_event => 'sut.log',
153
+ :color => true,
154
+ :dry_run => false,
155
+ :test_tag_and => '',
156
+ :test_tag_or => '',
157
+ :test_tag_exclude => '',
158
+ :timeout => 900, # 15 minutes
159
+ :fail_mode => 'slow',
160
+ :test_results_file => '',
161
+ :accept_all_exit_codes => false,
162
+ :timesync => false,
163
+ :set_env => true,
164
+ :disable_updates => true,
165
+ :repo_proxy => false,
166
+ :package_proxy => false,
167
+ :add_el_extras => false,
168
+ :consoleport => 443,
169
+ :pe_dir => '/opt/enterprise/dists',
170
+ :pe_version_file => 'LATEST',
171
+ :pe_version_file_win => 'LATEST-win',
172
+ :host_env => {},
173
+ :host_name_prefix => nil,
174
+ :ssh_env_file => '~/.ssh/environment',
175
+ :profile_d_env_file => '/etc/profile.d/beaker_env.sh',
176
+ :dot_fog => File.join(ENV.fetch('HOME', nil), '.fog'),
177
+ :ec2_yaml => 'config/image_templates/ec2.yaml',
178
+ :help => false,
179
+ :collect_perf_data => 'none',
180
+ :puppetdb_port_ssl => 8081,
181
+ :puppetdb_port_nonssl => 8080,
182
+ :puppetserver_port => 8140,
183
+ :nodeclassifier_port => 4433,
184
+ :cache_files_locally => false,
185
+ :aws_keyname_modifier => rand(10**10).to_s.rjust(10, '0'), # 10 digit random number string
186
+ :run_in_parallel => [],
187
+ :use_fog_credentials => true,
188
+ :ssh => {
189
+ :config => false,
190
+ :verify_host_key => false,
191
+ :auth_methods => ["publickey"],
192
+ :port => 22,
193
+ :forward_agent => true,
194
+ :keys => ["#{ENV.fetch('HOME', nil)}/.ssh/id_rsa"],
195
+ :user_known_hosts_file => "#{ENV.fetch('HOME', nil)}/.ssh/known_hosts",
196
+ :keepalive => true,
197
+ },
198
+ })
208
199
  end
209
200
  end
210
201
  end
@@ -1,13 +1,10 @@
1
1
  module Beaker
2
2
  module Options
3
- #A set of functions to read options files
3
+ # A set of functions to read options files
4
4
  module SubcommandOptionsParser
5
-
6
5
  def self.parse_options_file(options_file_path)
7
6
  result = OptionsHash.new
8
- if File.exist?(options_file_path)
9
- result = YAML.load_file(options_file_path)
10
- end
7
+ result = YAML.load_file(options_file_path) if File.exist?(options_file_path)
11
8
  result
12
9
  end
13
10
 
@@ -17,11 +14,11 @@ module Beaker
17
14
  result = OptionsHash.new
18
15
  if Beaker::Subcommands::SubcommandUtil.execute_subcommand?(argv[0])
19
16
  return result if argv[0] == 'init'
17
+
20
18
  result = SubcommandOptionsParser.parse_options_file(options_file)
21
19
  end
22
20
  result
23
21
  end
24
-
25
22
  end
26
23
  end
27
24
  end
@@ -1,6 +1,5 @@
1
1
  module Beaker
2
2
  module Options
3
-
4
3
  class Validator
5
4
  VALID_FAIL_MODES = /stop|fast|slow/
6
5
  VALID_PRESERVE_HOSTS = /always|onfail|onpass|never/
@@ -29,7 +28,7 @@ module Beaker
29
28
  end
30
29
 
31
30
  # alias to keep old methods and functionality from throwing errors.
32
- alias_method :parser_error, :validator_error
31
+ alias parser_error validator_error
33
32
 
34
33
  # Raises an ArgumentError if more than one default exists,
35
34
  # otherwise returns true or false if default is set.
@@ -51,10 +50,10 @@ module Beaker
51
50
  # @param [String] fail_mode Failure mode setting
52
51
  # @return [nil] Does not return anything
53
52
  def validate_fail_mode(fail_mode)
54
- #check for valid fail mode
55
- unless fail_mode.is_a?(String) && VALID_FAIL_MODES.match?(fail_mode)
56
- validator_error "--fail-mode must be one of fast or slow, not '#{fail_mode}'"
57
- end
53
+ # check for valid fail mode
54
+ return if fail_mode.is_a?(String) && VALID_FAIL_MODES.match?(fail_mode)
55
+
56
+ validator_error "--fail-mode must be one of fast or slow, not '#{fail_mode}'"
58
57
  end
59
58
 
60
59
  # Raises an error if hosts_setting is not a supported preserve hosts value.
@@ -62,10 +61,10 @@ module Beaker
62
61
  # @param [String] hosts_setting Preserve hosts setting
63
62
  # @return [nil] Does not return anything
64
63
  def validate_preserve_hosts(hosts_setting)
65
- #check for valid preserve_hosts option
66
- unless hosts_setting.is_a?(String) && VALID_PRESERVE_HOSTS.match?(hosts_setting)
67
- validator_error("--preserve_hosts must be one of always, onfail, onpass or never, not '#{hosts_setting}'")
68
- end
64
+ # check for valid preserve_hosts option
65
+ return if hosts_setting.is_a?(String) && VALID_PRESERVE_HOSTS.match?(hosts_setting)
66
+
67
+ validator_error("--preserve_hosts must be one of always, onfail, onpass or never, not '#{hosts_setting}'")
69
68
  end
70
69
 
71
70
  # Raise an error if host does not have a platform defined.
@@ -74,9 +73,9 @@ module Beaker
74
73
  # @param [String] name Host name
75
74
  # @return [nil] Does not return anything
76
75
  def validate_platform(host, name)
77
- if !host['platform'] || host['platform'].empty?
78
- validator_error "Host #{name} does not have a platform specified"
79
- end
76
+ return unless !host['platform'] || host['platform'].empty?
77
+
78
+ validator_error "Host #{name} does not have a platform specified"
80
79
  end
81
80
 
82
81
  # Raise an error if an item exists in both the include and exclude lists.
@@ -87,16 +86,12 @@ module Beaker
87
86
  # @param [Array] tags_exclude excluded items
88
87
  # @return [nil] Does not return anything
89
88
  def validate_test_tags(tags_and, tags_or, tags_exclude)
90
- if tags_and.length > 0 && tags_or.length > 0
91
- validator_error "cannot have values for both test tagging operands (AND and OR)"
92
- end
89
+ validator_error "cannot have values for both test tagging operands (AND and OR)" if tags_and.length > 0 && tags_or.length > 0
93
90
 
94
91
  tags_and.each do |included_tag|
95
92
  # select items from exclude set that match included_tag
96
93
  # no match is an empty list/array/[]
97
- if tags_exclude.select { |ex| ex == included_tag } != []
98
- validator_error "tag '#{included_tag}' cannot be in both the included and excluded tag sets"
99
- end
94
+ validator_error "tag '#{included_tag}' cannot be in both the included and excluded tag sets" if tags_exclude.select { |ex| ex == included_tag } != []
100
95
  end
101
96
  end
102
97
 
@@ -105,9 +100,9 @@ module Beaker
105
100
  # @param [Array<String>] role_array List of roles
106
101
  # @raise [ArgumentError] Raises if role_array contains conflicting roles
107
102
  def validate_frictionless_roles(role_array)
108
- if role_array.include?(FRICTIONLESS_ROLE) and !(role_array & FRICTIONLESS_ADDITIONAL_ROLES).empty?
109
- validator_error "Only agent nodes may have the role 'frictionless'."
110
- end
103
+ return unless role_array.include?(FRICTIONLESS_ROLE) and !(role_array & FRICTIONLESS_ADDITIONAL_ROLES).empty?
104
+
105
+ validator_error "Only agent nodes may have the role 'frictionless'."
111
106
  end
112
107
 
113
108
  # Raise an error if the master count is incorrect.
@@ -116,9 +111,9 @@ module Beaker
116
111
  # @return [nil] Nothing is returned
117
112
  # @raise [ArgumentError] Raises if master count is greater than 1
118
113
  def validate_master_count(count)
119
- if count > 1
120
- validator_error("Only one host/node may have the role 'master'.")
121
- end
114
+ return unless count > 1
115
+
116
+ validator_error("Only one host/node may have the role 'master'.")
122
117
  end
123
118
 
124
119
  # Raise an error if file_list is empty
@@ -127,9 +122,9 @@ module Beaker
127
122
  # @param [String] path file path to report in error
128
123
  # @raise [ArgumentError] Raises if file_list is empty
129
124
  def validate_files(file_list, path)
130
- if file_list.empty?
131
- validator_error("No files found for path: '#{path}'")
132
- end
125
+ return unless file_list.empty?
126
+
127
+ validator_error("No files found for path: '#{path}'")
133
128
  end
134
129
 
135
130
  # Raise an error if path is not a valid file or directory
@@ -137,9 +132,9 @@ module Beaker
137
132
  # @param [String] path File path
138
133
  # @raise [ArgumentError] Raises if path is not a valid file or directory
139
134
  def validate_path(path)
140
- if !File.file?(path) && !File.directory?(path)
141
- validator_error("#{path} used as a file option but is not a file or directory!")
142
- end
135
+ return unless !File.file?(path) && !File.directory?(path)
136
+
137
+ validator_error("#{path} used as a file option but is not a file or directory!")
143
138
  end
144
139
  end
145
140
  end
data/lib/beaker/perf.rb CHANGED
@@ -1,7 +1,6 @@
1
1
  module Beaker
2
2
  # The Beaker Perf class. A single instance is created per Beaker run.
3
3
  class Perf
4
-
5
4
  PERF_PACKAGES = ['sysstat']
6
5
  # SLES does not treat sysstat as a service that can be started
7
6
  PERF_SUPPORTED_PLATFORMS = /debian|ubuntu|redhat|centos|oracle|scientific|fedora|el|eos|cumulus|opensuse|sles/
@@ -15,7 +14,7 @@ module Beaker
15
14
  # @param [Array<Host>] hosts All from the configuration
16
15
  # @param [Hash] options Options to alter execution
17
16
  # @return [void]
18
- def initialize( hosts, options )
17
+ def initialize(hosts, options)
19
18
  @hosts = hosts
20
19
  @options = options
21
20
  @logger = options[:logger]
@@ -31,9 +30,7 @@ module Beaker
31
30
  # Install sysstat if required
32
31
  if PERF_SUPPORTED_PLATFORMS.match?(host['platform'])
33
32
  PERF_PACKAGES.each do |pkg|
34
- if not host.check_for_package pkg
35
- host.install_package pkg
36
- end
33
+ host.install_package pkg if not host.check_for_package pkg
37
34
  end
38
35
  else
39
36
  @logger.perf_output("Perf (sysstat) not supported on host: " + host)
@@ -44,7 +41,7 @@ module Beaker
44
41
  host.exec(Command.new('sed -i s/ENABLED=\"false\"/ENABLED=\"true\"/ /etc/default/sysstat'))
45
42
  elsif /opensuse|sles/.match?(host['platform'])
46
43
  @logger.perf_output("Creating symlink from /etc/sysstat/sysstat.cron to /etc/cron.d")
47
- host.exec(Command.new('ln -s /etc/sysstat/sysstat.cron /etc/cron.d'),:acceptable_exit_codes => [0,1])
44
+ host.exec(Command.new('ln -s /etc/sysstat/sysstat.cron /etc/cron.d'), :acceptable_exit_codes => [0, 1])
48
45
  end
49
46
  if @options[:collect_perf_data]&.include?('aggressive')
50
47
  @logger.perf_output("Enabling aggressive sysstat polling")
@@ -54,14 +51,14 @@ module Beaker
54
51
  host.exec(Command.new('sed -i s/*\\\/10/*/ /etc/cron.d/sysstat'))
55
52
  end
56
53
  end
57
- if PERF_START_PLATFORMS.match?(host['platform']) # SLES doesn't need this step
58
- host.exec(Command.new('service sysstat start'))
59
- end
54
+ return unless PERF_START_PLATFORMS.match?(host['platform']) # SLES doesn't need this step
55
+
56
+ host.exec(Command.new('service sysstat start'))
60
57
  end
61
58
 
62
59
  # Iterate over all hosts, calling get_perf_data
63
60
  # @return [void]
64
- def print_perf_info()
61
+ def print_perf_info
65
62
  @perf_end_timestamp = Time.now
66
63
  @hosts.map { |h| get_perf_data(h, @perf_timestamp, @perf_end_timestamp) }
67
64
  end
@@ -74,9 +71,7 @@ module Beaker
74
71
  def get_perf_data(host, perf_start, perf_end)
75
72
  @logger.perf_output("Getting perf data for host: " + host)
76
73
  if PERF_SUPPORTED_PLATFORMS.match?(host['platform']) # All flavours of Linux
77
- if not @options[:collect_perf_data]&.include?('aggressive')
78
- host.exec(Command.new("sar -A -s #{perf_start.strftime("%H:%M:%S")} -e #{perf_end.strftime("%H:%M:%S")}"),:acceptable_exit_codes => [0,1,2])
79
- end
74
+ host.exec(Command.new("sar -A -s #{perf_start.strftime('%H:%M:%S')} -e #{perf_end.strftime('%H:%M:%S')}"), :acceptable_exit_codes => [0, 1, 2]) if not @options[:collect_perf_data]&.include?('aggressive')
80
75
  if (defined? @options[:graphite_server] and not @options[:graphite_server].nil?) and
81
76
  (defined? @options[:graphite_perf_data] and not @options[:graphite_perf_data].nil?)
82
77
  export_perf_data_to_graphite(host)
@@ -92,7 +87,7 @@ module Beaker
92
87
  def export_perf_data_to_graphite(host)
93
88
  @logger.perf_output("Sending data to Graphite server: " + @options[:graphite_server])
94
89
 
95
- data = JSON.parse(host.exec(Command.new("sadf -j -- -A"),:silent => true).stdout)
90
+ data = JSON.parse(host.exec(Command.new("sadf -j -- -A"), :silent => true).stdout)
96
91
  hostname = host['vmhostname'].split('.')[0]
97
92
 
98
93
  data['sysstat']['hosts'].each do |host|
@@ -101,23 +96,23 @@ module Beaker
101
96
 
102
97
  poll.keys.each do |stat|
103
98
  case stat
104
- when 'cpu-load-all'
105
- poll[stat].each do |s|
106
- s.keys.each do |k|
107
- next if k == 'cpu'
108
-
109
- socket = TCPSocket.new(@options[:graphite_server], 2003)
110
- socket.puts "#{@options[:graphite_perf_data]}.#{hostname}.cpu.#{s['cpu']}.#{k} #{s[k]} #{timestamp}"
111
- socket.close
112
- end
113
- end
99
+ when 'cpu-load-all'
100
+ poll[stat].each do |s|
101
+ s.keys.each do |k|
102
+ next if k == 'cpu'
114
103
 
115
- when 'memory'
116
- poll[stat].keys.each do |s|
117
104
  socket = TCPSocket.new(@options[:graphite_server], 2003)
118
- socket.puts "#{@options[:graphite_perf_data]}.#{hostname}.memory.#{s} #{poll[stat][s]} #{timestamp}"
105
+ socket.puts "#{@options[:graphite_perf_data]}.#{hostname}.cpu.#{s['cpu']}.#{k} #{s[k]} #{timestamp}"
119
106
  socket.close
120
107
  end
108
+ end
109
+
110
+ when 'memory'
111
+ poll[stat].keys.each do |s|
112
+ socket = TCPSocket.new(@options[:graphite_server], 2003)
113
+ socket.puts "#{@options[:graphite_perf_data]}.#{hostname}.memory.#{s} #{poll[stat][s]} #{timestamp}"
114
+ socket.close
115
+ end
121
116
  end
122
117
  end
123
118
  end