beaker 4.40.2 → 5.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/dependabot.yml +9 -0
- data/.github/workflows/release.yml +2 -2
- data/.github/workflows/test.yml +26 -13
- data/.rubocop.yml +23 -10
- data/.rubocop_todo.yml +34 -10
- data/CHANGELOG.md +17 -28
- data/Gemfile +12 -7
- data/Rakefile +99 -111
- data/acceptance/config/acceptance-options.rb +1 -1
- data/acceptance/config/base/acceptance-options.rb +2 -2
- data/acceptance/config/hypervisor/acceptance-options.rb +2 -2
- data/acceptance/config/subcommands/acceptance-options.rb +2 -2
- data/acceptance/fixtures/module/Rakefile +1 -1
- data/acceptance/fixtures/module/spec/acceptance/demo_spec.rb +8 -12
- data/acceptance/fixtures/module/spec/classes/init_spec.rb +0 -1
- data/acceptance/fixtures/module/spec/spec_helper_acceptance.rb +3 -5
- data/acceptance/lib/helpers/test_helper.rb +6 -5
- data/acceptance/pre_suite/subcommands/05_install_ruby.rb +2 -3
- data/acceptance/pre_suite/subcommands/08_install_beaker.rb +1 -2
- data/acceptance/tests/base/dsl/helpers/configuration_test.rb +4 -4
- data/acceptance/tests/base/dsl/helpers/hocon_helpers_test.rb +1 -2
- data/acceptance/tests/base/dsl/helpers/host_helpers/add_system32_hosts_entry_test.rb +0 -3
- data/acceptance/tests/base/dsl/helpers/host_helpers/archive_file_from_test.rb +3 -1
- data/acceptance/tests/base/dsl/helpers/host_helpers/backup_the_file_test.rb +9 -9
- data/acceptance/tests/base/dsl/helpers/host_helpers/check_for_package_test.rb +0 -4
- data/acceptance/tests/base/dsl/helpers/host_helpers/create_remote_file_test.rb +19 -26
- data/acceptance/tests/base/dsl/helpers/host_helpers/curl_on_test.rb +2 -2
- data/acceptance/tests/base/dsl/helpers/host_helpers/curl_with_retries_test.rb +0 -1
- data/acceptance/tests/base/dsl/helpers/host_helpers/on_test.rb +18 -13
- data/acceptance/tests/base/dsl/helpers/host_helpers/retry_on_test.rb +3 -3
- data/acceptance/tests/base/dsl/helpers/host_helpers/rsync_to_test.rb +22 -27
- data/acceptance/tests/base/dsl/helpers/host_helpers/run_cron_on_test.rb +12 -16
- data/acceptance/tests/base/dsl/helpers/host_helpers/run_script_on_test.rb +3 -4
- data/acceptance/tests/base/dsl/helpers/host_helpers/run_script_test.rb +3 -3
- data/acceptance/tests/base/dsl/helpers/host_helpers/scp_from_test.rb +4 -4
- data/acceptance/tests/base/dsl/helpers/host_helpers/scp_to_test.rb +3 -4
- data/acceptance/tests/base/dsl/helpers/host_helpers/shell_test.rb +5 -5
- data/acceptance/tests/base/dsl/helpers/host_helpers/upgrade_package_test.rb +3 -5
- data/acceptance/tests/base/dsl/platform_tag_confiner_test.rb +14 -17
- data/acceptance/tests/base/dsl/structure_test.rb +5 -11
- data/acceptance/tests/base/host/file_test.rb +2 -2
- data/acceptance/tests/base/host/group_test.rb +0 -1
- data/acceptance/tests/base/host/host_test.rb +66 -63
- data/acceptance/tests/base/host/packages.rb +1 -2
- data/acceptance/tests/base/host/packages_unix.rb +0 -55
- data/acceptance/tests/base/host/user_test.rb +0 -1
- data/acceptance/tests/base/host_prebuilt_steps/ssh_environment_test.rb +1 -2
- data/acceptance/tests/base/test_suite/export.rb +6 -9
- data/acceptance/tests/install/from_file.rb +2 -4
- data/acceptance/tests/load_path_bootstrap.rb +1 -1
- data/acceptance/tests/subcommands/destroy.rb +19 -21
- data/acceptance/tests/subcommands/exec.rb +0 -1
- data/acceptance/tests/subcommands/init.rb +2 -3
- data/acceptance/tests/subcommands/provision.rb +0 -1
- data/beaker.gemspec +4 -7
- data/docs/concepts/argument_processing_and_precedence.md +1 -10
- data/docs/how_to/debug_beaker_tests.md +12 -12
- data/docs/how_to/hosts/eos.md +2 -12
- data/docs/how_to/install_puppet.md +0 -18
- data/docs/how_to/the_beaker_dsl.md +0 -2
- data/lib/beaker/cli.rb +59 -68
- data/lib/beaker/command.rb +20 -28
- data/lib/beaker/command_factory.rb +3 -2
- data/lib/beaker/dsl/assertions.rb +6 -18
- data/lib/beaker/dsl/helpers/hocon_helpers.rb +3 -7
- data/lib/beaker/dsl/helpers/host_helpers.rb +62 -123
- data/lib/beaker/dsl/helpers/test_helpers.rb +3 -5
- data/lib/beaker/dsl/helpers/web_helpers.rb +19 -39
- data/lib/beaker/dsl/helpers.rb +2 -4
- data/lib/beaker/dsl/outcomes.rb +13 -15
- data/lib/beaker/dsl/patterns.rb +1 -3
- data/lib/beaker/dsl/roles.rb +17 -20
- data/lib/beaker/dsl/structure.rb +53 -65
- data/lib/beaker/dsl/test_tagging.rb +7 -10
- data/lib/beaker/dsl/wrappers.rb +15 -16
- data/lib/beaker/dsl.rb +2 -3
- data/lib/beaker/host/aix/exec.rb +1 -1
- data/lib/beaker/host/aix/file.rb +0 -1
- data/lib/beaker/host/aix/group.rb +1 -1
- data/lib/beaker/host/aix/user.rb +1 -1
- data/lib/beaker/host/aix.rb +3 -4
- data/lib/beaker/host/cisco.rb +27 -39
- data/lib/beaker/host/eos.rb +4 -30
- data/lib/beaker/host/freebsd/exec.rb +1 -1
- data/lib/beaker/host/freebsd/pkg.rb +3 -3
- data/lib/beaker/host/freebsd.rb +9 -12
- data/lib/beaker/host/mac/exec.rb +4 -4
- data/lib/beaker/host/mac/group.rb +7 -7
- data/lib/beaker/host/mac/pkg.rb +3 -106
- data/lib/beaker/host/mac/user.rb +2 -2
- data/lib/beaker/host/mac.rb +8 -9
- data/lib/beaker/host/pswindows/exec.rb +66 -70
- data/lib/beaker/host/pswindows/file.rb +3 -5
- data/lib/beaker/host/pswindows/group.rb +3 -3
- data/lib/beaker/host/pswindows/pkg.rb +12 -12
- data/lib/beaker/host/pswindows/user.rb +3 -3
- data/lib/beaker/host/pswindows.rb +4 -3
- data/lib/beaker/host/unix/exec.rb +80 -82
- data/lib/beaker/host/unix/file.rb +38 -43
- data/lib/beaker/host/unix/group.rb +1 -1
- data/lib/beaker/host/unix/pkg.rb +154 -417
- data/lib/beaker/host/unix/user.rb +2 -2
- data/lib/beaker/host/unix.rb +8 -11
- data/lib/beaker/host/windows/exec.rb +17 -17
- data/lib/beaker/host/windows/file.rb +3 -3
- data/lib/beaker/host/windows/group.rb +3 -3
- data/lib/beaker/host/windows/pkg.rb +3 -54
- data/lib/beaker/host/windows/user.rb +3 -3
- data/lib/beaker/host/windows.rb +12 -12
- data/lib/beaker/host.rb +76 -133
- data/lib/beaker/host_prebuilt_steps.rb +93 -198
- data/lib/beaker/hypervisor/noop.rb +2 -4
- data/lib/beaker/hypervisor.rb +44 -61
- data/lib/beaker/local_connection.rb +2 -4
- data/lib/beaker/logger.rb +68 -76
- data/lib/beaker/logger_junit.rb +21 -25
- data/lib/beaker/network_manager.rb +39 -42
- data/lib/beaker/options/command_line_parser.rb +12 -23
- data/lib/beaker/options/hosts_file_parser.rb +16 -24
- data/lib/beaker/options/options_file_parser.rb +3 -6
- data/lib/beaker/options/options_hash.rb +2 -7
- data/lib/beaker/options/parser.rb +86 -102
- data/lib/beaker/options/presets.rb +114 -123
- data/lib/beaker/options/subcommand_options_file_parser.rb +3 -6
- data/lib/beaker/options/validator.rb +26 -31
- data/lib/beaker/perf.rb +22 -27
- data/lib/beaker/platform.rb +38 -46
- data/lib/beaker/result.rb +7 -6
- data/lib/beaker/shared/error_handler.rb +8 -10
- data/lib/beaker/shared/fog_credentials.rb +5 -9
- data/lib/beaker/shared/host_manager.rb +36 -41
- data/lib/beaker/shared/options_resolver.rb +3 -7
- data/lib/beaker/shared/repetition.rb +2 -4
- data/lib/beaker/shared/semvar.rb +37 -41
- data/lib/beaker/shared/timed.rb +0 -3
- data/lib/beaker/shared.rb +1 -1
- data/lib/beaker/ssh_connection.rb +38 -47
- data/lib/beaker/subcommand.rb +17 -24
- data/lib/beaker/subcommands/subcommand_util.rb +4 -4
- data/lib/beaker/tasks/quick_start.rb +4 -9
- data/lib/beaker/tasks/rake_task.rb +25 -27
- data/lib/beaker/tasks/test.rb +4 -4
- data/lib/beaker/test_case.rb +16 -28
- data/lib/beaker/test_suite.rb +35 -39
- data/lib/beaker/test_suite_result.rb +45 -47
- data/lib/beaker/version.rb +1 -1
- data/lib/beaker.rb +6 -7
- data/spec/beaker/cli_spec.rb +121 -142
- data/spec/beaker/command_spec.rb +55 -59
- data/spec/beaker/dsl/assertions_spec.rb +36 -36
- data/spec/beaker/dsl/helpers/host_helpers_spec.rb +110 -131
- data/spec/beaker/dsl/helpers/test_helpers_spec.rb +9 -10
- data/spec/beaker/dsl/helpers/web_helpers_spec.rb +22 -31
- data/spec/beaker/dsl/outcomes_spec.rb +14 -14
- data/spec/beaker/dsl/roles_spec.rb +125 -130
- data/spec/beaker/dsl/structure_spec.rb +172 -161
- data/spec/beaker/dsl/test_tagging_spec.rb +89 -90
- data/spec/beaker/dsl/wrappers_spec.rb +32 -33
- data/spec/beaker/host/aix_spec.rb +14 -14
- data/spec/beaker/host/cisco_spec.rb +84 -94
- data/spec/beaker/host/eos_spec.rb +15 -36
- data/spec/beaker/host/freebsd/exec_spec.rb +3 -6
- data/spec/beaker/host/freebsd/pkg_spec.rb +24 -27
- data/spec/beaker/host/mac/exec_spec.rb +2 -3
- data/spec/beaker/host/mac/group_spec.rb +48 -57
- data/spec/beaker/host/mac/user_spec.rb +54 -63
- data/spec/beaker/host/pswindows/exec_spec.rb +30 -32
- data/spec/beaker/host/pswindows/file_spec.rb +16 -16
- data/spec/beaker/host/pswindows/user_spec.rb +17 -23
- data/spec/beaker/host/pswindows_spec.rb +13 -13
- data/spec/beaker/host/unix/exec_spec.rb +75 -80
- data/spec/beaker/host/unix/file_spec.rb +66 -73
- data/spec/beaker/host/unix/pkg_spec.rb +155 -401
- data/spec/beaker/host/unix_spec.rb +11 -207
- data/spec/beaker/host/windows/exec_spec.rb +30 -32
- data/spec/beaker/host/windows/file_spec.rb +18 -19
- data/spec/beaker/host/windows/group_spec.rb +10 -12
- data/spec/beaker/host/windows/pkg_spec.rb +6 -9
- data/spec/beaker/host/windows/user_spec.rb +17 -23
- data/spec/beaker/host/windows_spec.rb +39 -39
- data/spec/beaker/host_prebuilt_steps_spec.rb +172 -326
- data/spec/beaker/host_spec.rb +204 -284
- data/spec/beaker/hypervisor/hypervisor_spec.rb +36 -61
- data/spec/beaker/localhost_connection_spec.rb +10 -11
- data/spec/beaker/logger_junit_spec.rb +19 -30
- data/spec/beaker/logger_spec.rb +153 -136
- data/spec/beaker/network_manager_spec.rb +23 -23
- data/spec/beaker/options/command_line_parser_spec.rb +20 -23
- data/spec/beaker/options/hosts_file_parser_spec.rb +30 -32
- data/spec/beaker/options/options_file_parser_spec.rb +4 -7
- data/spec/beaker/options/options_hash_spec.rb +4 -6
- data/spec/beaker/options/parser_spec.rb +167 -167
- data/spec/beaker/options/presets_spec.rb +7 -9
- data/spec/beaker/options/subcommand_options_parser_spec.rb +13 -14
- data/spec/beaker/options/validator_spec.rb +10 -11
- data/spec/beaker/perf_spec.rb +18 -21
- data/spec/beaker/platform_spec.rb +25 -36
- data/spec/beaker/shared/error_handler_spec.rb +7 -16
- data/spec/beaker/shared/fog_credentials_spec.rb +29 -29
- data/spec/beaker/shared/host_manager_spec.rb +50 -84
- data/spec/beaker/shared/options_resolver_spec.rb +9 -12
- data/spec/beaker/shared/repetition_spec.rb +17 -24
- data/spec/beaker/shared/semvar_spec.rb +21 -26
- data/spec/beaker/ssh_connection_spec.rb +76 -83
- data/spec/beaker/subcommand/subcommand_util_spec.rb +31 -33
- data/spec/beaker/subcommand_spec.rb +75 -77
- data/spec/beaker/test_case_spec.rb +25 -50
- data/spec/beaker/test_suite_spec.rb +147 -154
- data/spec/helpers.rb +48 -53
- data/spec/matchers.rb +8 -7
- data/spec/mocks.rb +1 -6
- data/spec/spec_helper.rb +0 -1
- metadata +7 -24
- data/acceptance/tests/base/dsl/helpers/host_helpers/deploy_package_repo_test.rb +0 -142
- data/acceptance/tests/base/external_resources_test.rb +0 -31
- data/spec/beaker/host/mac_spec.rb +0 -113
@@ -1,14 +1,13 @@
|
|
1
|
-
[
|
1
|
+
['hypervisor'].each do |lib|
|
2
2
|
require "beaker/#{lib}"
|
3
3
|
end
|
4
4
|
|
5
5
|
module Beaker
|
6
|
-
#Object that holds all the provisioned and non-provisioned virtual machines.
|
7
|
-
#Controls provisioning, configuration, validation and cleanup of those virtual machines.
|
6
|
+
# Object that holds all the provisioned and non-provisioned virtual machines.
|
7
|
+
# Controls provisioning, configuration, validation and cleanup of those virtual machines.
|
8
8
|
class NetworkManager
|
9
|
-
|
10
|
-
#
|
11
|
-
#Provision if:
|
9
|
+
# Determine if a given host should be provisioned.
|
10
|
+
# Provision if:
|
12
11
|
# - only if we are running with ---provision
|
13
12
|
# - only if we have a hypervisor
|
14
13
|
# - only if either the specific hosts has no specification or has 'provision' in its config
|
@@ -32,12 +31,12 @@ module Beaker
|
|
32
31
|
# user provided prefix has top priority
|
33
32
|
if not @options[:log_prefix]
|
34
33
|
# name it after the hosts file
|
35
|
-
if @options[:hosts_file]
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
34
|
+
@options[:log_prefix] = if @options[:hosts_file]
|
35
|
+
File.basename(@options[:hosts_file], '.yml')
|
36
|
+
else
|
37
|
+
# here be the default
|
38
|
+
@options[:default_log_prefix]
|
39
|
+
end
|
41
40
|
end
|
42
41
|
@options[:timestamp] = Time.now unless @options.has_key?(:timestamp)
|
43
42
|
@options[:xml_dated_dir] = Beaker::Logger.generate_dated_log_folder(@options[:xml_dir], @options[:log_prefix], @options[:timestamp])
|
@@ -45,15 +44,13 @@ module Beaker
|
|
45
44
|
@options[:logger_sut] = Beaker::Logger.new(File.join(@options[:log_dated_dir], @options[:log_sut_event]), { :quiet => true })
|
46
45
|
end
|
47
46
|
|
48
|
-
#Provision all virtual machines. Provision machines according to their set hypervisor, if no hypervisor
|
49
|
-
#is selected assume that the described hosts are already up and reachable and do no provisioning.
|
47
|
+
# Provision all virtual machines. Provision machines according to their set hypervisor, if no hypervisor
|
48
|
+
# is selected assume that the described hosts are already up and reachable and do no provisioning.
|
50
49
|
def provision
|
51
|
-
if @hypervisors
|
52
|
-
cleanup
|
53
|
-
end
|
50
|
+
cleanup if @hypervisors
|
54
51
|
@hypervisors = {}
|
55
|
-
#sort hosts by their hypervisor, use hypervisor 'none' if no hypervisor is specified
|
56
|
-
hostless_options = Beaker::Options::OptionsHash.new.merge(@options.select{ |k,_v| !k.to_s.include?('HOSTS')})
|
52
|
+
# sort hosts by their hypervisor, use hypervisor 'none' if no hypervisor is specified
|
53
|
+
hostless_options = Beaker::Options::OptionsHash.new.merge(@options.select { |k, _v| !k.to_s.include?('HOSTS') })
|
57
54
|
@options['HOSTS'].each_key do |name|
|
58
55
|
host_hash = @options['HOSTS'][name]
|
59
56
|
hypervisor = host_hash['hypervisor']
|
@@ -62,7 +59,7 @@ module Beaker
|
|
62
59
|
end
|
63
60
|
@logger.debug "Hypervisor for #{name} is #{hypervisor}"
|
64
61
|
@machines[hypervisor] = [] unless @machines[hypervisor]
|
65
|
-
hostless_options[:timesync] = host_hash[:timesync] if host_hash[:timesync]!=nil
|
62
|
+
hostless_options[:timesync] = host_hash[:timesync] if host_hash[:timesync] != nil
|
66
63
|
host_itself = Beaker::Host.create(name, host_hash, hostless_options)
|
67
64
|
host_itself.validate_setup
|
68
65
|
@machines[hypervisor] << host_itself
|
@@ -79,41 +76,41 @@ module Beaker
|
|
79
76
|
@hosts
|
80
77
|
end
|
81
78
|
|
82
|
-
#Validate all provisioned machines, ensure that required packages are installed - if they are missing
|
83
|
-
#attempt to add them.
|
84
|
-
|
79
|
+
# Validate all provisioned machines, ensure that required packages are installed - if they are missing
|
80
|
+
# attempt to add them.
|
81
|
+
# @raise [Exception] Raise an exception if virtual machines fail to be validated
|
85
82
|
def validate
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
83
|
+
return unless @hypervisors
|
84
|
+
|
85
|
+
@hypervisors.each_key do |type|
|
86
|
+
@hypervisors[type].validate
|
90
87
|
end
|
91
88
|
end
|
92
89
|
|
93
|
-
#Configure all provisioned machines, adding any packages or settings required for SUTs
|
94
|
-
|
90
|
+
# Configure all provisioned machines, adding any packages or settings required for SUTs
|
91
|
+
# @raise [Exception] Raise an exception if virtual machines fail to be configured
|
95
92
|
def configure
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
93
|
+
return unless @hypervisors
|
94
|
+
|
95
|
+
@hypervisors.each_key do |type|
|
96
|
+
@hypervisors[type].configure
|
100
97
|
end
|
101
98
|
end
|
102
99
|
|
103
100
|
# configure proxy on all provioned machines
|
104
|
-
|
101
|
+
# @raise [Exception] Raise an exception if virtual machines fail to be configured
|
105
102
|
def proxy_package_manager
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
103
|
+
return unless @hypervisors
|
104
|
+
|
105
|
+
@hypervisors.each_key do |type|
|
106
|
+
@hypervisors[type].proxy_package_manager
|
110
107
|
end
|
111
108
|
end
|
112
109
|
|
113
|
-
#Shut down network connections and revert all provisioned virtual machines
|
110
|
+
# Shut down network connections and revert all provisioned virtual machines
|
114
111
|
def cleanup
|
115
|
-
#shut down connections
|
116
|
-
@hosts.each {|host| host.close }
|
112
|
+
# shut down connections
|
113
|
+
@hosts.each { |host| host.close }
|
117
114
|
|
118
115
|
if @hypervisors
|
119
116
|
@hypervisors.each_key do |type|
|
@@ -134,6 +131,7 @@ module Beaker
|
|
134
131
|
# @return [String] the log line created for this event
|
135
132
|
def log_sut_event host, create
|
136
133
|
raise ArgumentError.new "log_sut_event called before sut logger created. skipping #{host}, #{create}" unless @options.has_key?(:logger_sut)
|
134
|
+
|
137
135
|
sut_logger = @options[:logger_sut]
|
138
136
|
time = Time.new
|
139
137
|
stamp = time.strftime('%Y-%m-%d %H:%M:%S')
|
@@ -142,6 +140,5 @@ module Beaker
|
|
142
140
|
sut_logger.notify line
|
143
141
|
line
|
144
142
|
end
|
145
|
-
|
146
143
|
end
|
147
144
|
end
|
@@ -1,8 +1,7 @@
|
|
1
1
|
module Beaker
|
2
2
|
module Options
|
3
|
-
#An object that parses arguments in the format ['--option', 'value', '--option2', 'value2', '--switch']
|
3
|
+
# An object that parses arguments in the format ['--option', 'value', '--option2', 'value2', '--switch']
|
4
4
|
class CommandLineParser
|
5
|
-
|
6
5
|
# @example Create a CommanLineParser
|
7
6
|
# a = CommandLineParser.new
|
8
7
|
#
|
@@ -10,7 +9,7 @@ module Beaker
|
|
10
9
|
def initialize
|
11
10
|
@cmd_options = Beaker::Options::OptionsHash.new
|
12
11
|
|
13
|
-
@optparse = OptionParser.new do|opts|
|
12
|
+
@optparse = OptionParser.new do |opts|
|
14
13
|
# Set a banner
|
15
14
|
opts.banner = "Usage: #{File.basename($0)} [options...]"
|
16
15
|
|
@@ -27,7 +26,7 @@ module Beaker
|
|
27
26
|
'Read options from FILE',
|
28
27
|
'This should evaluate to a ruby hash.',
|
29
28
|
'CLI optons are given precedence.' do |file|
|
30
|
-
@cmd_options[:options_file] =
|
29
|
+
@cmd_options[:options_file] = file
|
31
30
|
end
|
32
31
|
|
33
32
|
opts.on '--helper PATH/TO/SCRIPT',
|
@@ -92,7 +91,7 @@ module Beaker
|
|
92
91
|
'onfail (keep SUTs alive if failures occur during testing)',
|
93
92
|
'onpass (keep SUTs alive if no failures occur during testing)',
|
94
93
|
'never (cleanup SUTs - shutdown and destroy any changes made during testing)',
|
95
|
-
'(default: never)'
|
94
|
+
'(default: never)' do |mode|
|
96
95
|
@cmd_options[:preserve_hosts] = mode || 'always'
|
97
96
|
end
|
98
97
|
|
@@ -153,9 +152,7 @@ module Beaker
|
|
153
152
|
'Ensure SUT colored output is preserved',
|
154
153
|
'(default: false)' do |bool|
|
155
154
|
@cmd_options[:color_host_output] = bool
|
156
|
-
if bool
|
157
|
-
@cmd_options[:color_host_output] = true
|
158
|
-
end
|
155
|
+
@cmd_options[:color_host_output] = true if bool
|
159
156
|
end
|
160
157
|
|
161
158
|
opts.on '--log-level LEVEL',
|
@@ -191,7 +188,7 @@ module Beaker
|
|
191
188
|
'slow (attempt to continue run post test failure)',
|
192
189
|
'stop (DEPRECATED, please use fast)',
|
193
190
|
'(default: slow)' do |mode|
|
194
|
-
@cmd_options[:fail_mode] = mode.include?('stop') ? 'fast' :
|
191
|
+
@cmd_options[:fail_mode] = mode.include?('stop') ? 'fast' : mode
|
195
192
|
end
|
196
193
|
|
197
194
|
opts.on '--test-results-file /FILE/TO/SAVE/TO.rb',
|
@@ -212,12 +209,6 @@ module Beaker
|
|
212
209
|
@cmd_options[:repo_proxy] = true
|
213
210
|
end
|
214
211
|
|
215
|
-
opts.on '--add-el-extras',
|
216
|
-
'Add Extra Packages for Enterprise Linux (EPEL) repository to el-* hosts',
|
217
|
-
'(default: false)' do
|
218
|
-
@cmd_options[:add_el_extras] = true
|
219
|
-
end
|
220
|
-
|
221
212
|
opts.on '--package-proxy URL', 'Set proxy url for package managers (yum and apt)' do |value|
|
222
213
|
@cmd_options[:package_proxy] = value
|
223
214
|
end
|
@@ -238,15 +229,15 @@ module Beaker
|
|
238
229
|
@cmd_options[:collect_perf_data] = mode || 'normal'
|
239
230
|
end
|
240
231
|
|
241
|
-
opts.on('--version', 'Report currently running version of beaker'
|
232
|
+
opts.on('--version', 'Report currently running version of beaker') do
|
242
233
|
@cmd_options[:beaker_version_print] = true
|
243
234
|
end
|
244
235
|
|
245
|
-
opts.on('--parse-only', 'Display beaker parsed options and exit'
|
236
|
+
opts.on('--parse-only', 'Display beaker parsed options and exit') do
|
246
237
|
@cmd_options[:parse_only] = true
|
247
238
|
end
|
248
239
|
|
249
|
-
opts.on('--help', 'Display this screen'
|
240
|
+
opts.on('--help', 'Display this screen') do
|
250
241
|
@cmd_options[:help] = true
|
251
242
|
end
|
252
243
|
|
@@ -262,12 +253,12 @@ module Beaker
|
|
262
253
|
|
263
254
|
opts.on '-x', '--[no-]xml',
|
264
255
|
'DEPRECATED - JUnit XML now generated by default' do
|
265
|
-
#noop
|
256
|
+
# noop
|
266
257
|
end
|
267
258
|
|
268
259
|
opts.on '--type TYPE',
|
269
260
|
'DEPRECATED - pe/foss/aio determined during runtime' do |type|
|
270
|
-
#backwards compatability, oh how i hate you
|
261
|
+
# backwards compatability, oh how i hate you
|
271
262
|
@cmd_options[:type] = type
|
272
263
|
end
|
273
264
|
|
@@ -298,9 +289,7 @@ module Beaker
|
|
298
289
|
'Output an additional JUnit XML file, sorted by execution time' do |bool|
|
299
290
|
@cmd_options[:xml_time_enabled] = bool
|
300
291
|
end
|
301
|
-
|
302
292
|
end
|
303
|
-
|
304
293
|
end
|
305
294
|
|
306
295
|
# Parse an array of arguments into a Hash of options
|
@@ -312,7 +301,7 @@ module Beaker
|
|
312
301
|
# parser.parse(args) == {:option => 'value, :options2 => value, :switch => true}
|
313
302
|
#
|
314
303
|
# @return [Hash] Return the Hash of options
|
315
|
-
def parse(
|
304
|
+
def parse(args = ARGV)
|
316
305
|
@optparse.parse(args)
|
317
306
|
@cmd_options
|
318
307
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
module Beaker
|
2
2
|
module Options
|
3
|
-
#A set of functions to parse hosts files
|
3
|
+
# A set of functions to parse hosts files
|
4
4
|
module HostsFileParser
|
5
5
|
PERMITTED_YAML_CLASSES = [
|
6
6
|
'Beaker',
|
@@ -36,15 +36,16 @@ module Beaker
|
|
36
36
|
|
37
37
|
host_options = new_host_options
|
38
38
|
return host_options unless hosts_file_path
|
39
|
+
|
39
40
|
error_message = "#{hosts_file_path} is not a valid YAML file\n\t"
|
40
|
-
host_options = self.merge_hosts_yaml(
|
41
|
-
hosts_file_path = File.expand_path(
|
41
|
+
host_options = self.merge_hosts_yaml(host_options, error_message) do
|
42
|
+
hosts_file_path = File.expand_path(hosts_file_path)
|
42
43
|
|
43
44
|
raise "#{hosts_file_path} is not a valid path" unless File.exist?(hosts_file_path)
|
44
45
|
|
45
46
|
process_yaml(File.read(hosts_file_path), binding)
|
46
|
-
|
47
|
-
fix_roles_array(
|
47
|
+
end
|
48
|
+
fix_roles_array(host_options)
|
48
49
|
end
|
49
50
|
|
50
51
|
# Read the contents of a host definition as a string into an OptionsHash
|
@@ -58,11 +59,12 @@ module Beaker
|
|
58
59
|
|
59
60
|
host_options = new_host_options
|
60
61
|
return host_options unless hosts_def_yaml
|
62
|
+
|
61
63
|
error_message = "#{hosts_def_yaml}\nis not a valid YAML string\n\t"
|
62
|
-
host_options = self.merge_hosts_yaml(
|
64
|
+
host_options = self.merge_hosts_yaml(host_options, error_message) do
|
63
65
|
process_yaml(hosts_def_yaml, binding)
|
64
|
-
|
65
|
-
fix_roles_array(
|
66
|
+
end
|
67
|
+
fix_roles_array(host_options)
|
66
68
|
end
|
67
69
|
|
68
70
|
# Convenience method to create new OptionsHashes with a HOSTS section
|
@@ -76,13 +78,11 @@ module Beaker
|
|
76
78
|
|
77
79
|
# Make sure the roles array is present for all hosts
|
78
80
|
#
|
79
|
-
def self.fix_roles_array(
|
81
|
+
def self.fix_roles_array(host_options)
|
80
82
|
host_options['HOSTS'].each_key do |host|
|
81
83
|
host_options['HOSTS'][host]['roles'] ||= []
|
82
84
|
end
|
83
|
-
if host_options.has_key?('CONFIG')
|
84
|
-
host_options = host_options.merge(host_options.delete('CONFIG'))
|
85
|
-
end
|
85
|
+
host_options = host_options.merge(host_options.delete('CONFIG')) if host_options.has_key?('CONFIG')
|
86
86
|
host_options
|
87
87
|
end
|
88
88
|
|
@@ -92,7 +92,7 @@ module Beaker
|
|
92
92
|
# @param [String] error_message Message to print if {::Psych::SyntaxError}
|
93
93
|
# is raised during block execution
|
94
94
|
# @return [OptionsHash] Updated host_options with host info merged
|
95
|
-
def self.merge_hosts_yaml(
|
95
|
+
def self.merge_hosts_yaml(host_options, error_message)
|
96
96
|
begin
|
97
97
|
loaded_host_options = yield
|
98
98
|
rescue Psych::SyntaxError => e
|
@@ -100,7 +100,7 @@ module Beaker
|
|
100
100
|
raise ArgumentError, error_message
|
101
101
|
end
|
102
102
|
|
103
|
-
host_options.merge(
|
103
|
+
host_options.merge(loaded_host_options)
|
104
104
|
end
|
105
105
|
|
106
106
|
# A helper to parse the YAML file and apply ERB templating
|
@@ -109,16 +109,8 @@ module Beaker
|
|
109
109
|
# @param [Binding] b The binding to pass to ERB rendering
|
110
110
|
# @api private
|
111
111
|
def self.process_yaml(template, b)
|
112
|
-
erb_obj =
|
113
|
-
|
114
|
-
else
|
115
|
-
ERB.new(template, nil, '-')
|
116
|
-
end
|
117
|
-
if RUBY_VERSION >= '2.6'
|
118
|
-
YAML.safe_load(erb_obj.result(b), permitted_classes: PERMITTED_YAML_CLASSES, aliases: true)
|
119
|
-
else
|
120
|
-
YAML.load(erb_obj.result(b)) # rubocop:disable Security/YAMLLoad
|
121
|
-
end
|
112
|
+
erb_obj = ERB.new(template, trim_mode: '-')
|
113
|
+
YAML.safe_load(erb_obj.result(b), permitted_classes: PERMITTED_YAML_CLASSES, aliases: true)
|
122
114
|
end
|
123
115
|
end
|
124
116
|
end
|
@@ -1,9 +1,8 @@
|
|
1
1
|
require 'open-uri'
|
2
2
|
module Beaker
|
3
3
|
module Options
|
4
|
-
#A set of functions to read options files
|
4
|
+
# A set of functions to read options files
|
5
5
|
module OptionsFileParser
|
6
|
-
|
7
6
|
# Eval the contents of options_file_path, return as an OptionsHash
|
8
7
|
#
|
9
8
|
# Options file is assumed to contain extra options stored in a Hash
|
@@ -28,9 +27,8 @@ module Beaker
|
|
28
27
|
result = Beaker::Options::OptionsHash.new
|
29
28
|
if options_file_path
|
30
29
|
options_file_path = File.expand_path(options_file_path)
|
31
|
-
unless File.exist?(options_file_path)
|
32
|
-
|
33
|
-
end
|
30
|
+
raise ArgumentError, "Specified options file '#{options_file_path}' does not exist!" unless File.exist?(options_file_path)
|
31
|
+
|
34
32
|
# This eval will allow the specified options file to have access to our
|
35
33
|
# scope. It is important that the variable 'options_file_path' is
|
36
34
|
# accessible, because some existing options files (e.g. puppetdb) rely on
|
@@ -39,7 +37,6 @@ module Beaker
|
|
39
37
|
end
|
40
38
|
result
|
41
39
|
end
|
42
|
-
|
43
40
|
end
|
44
41
|
end
|
45
42
|
end
|
@@ -2,11 +2,9 @@ require 'stringify-hash'
|
|
2
2
|
|
3
3
|
module Beaker
|
4
4
|
module Options
|
5
|
-
|
6
5
|
# A hash that treats Symbol and String keys interchangeably
|
7
6
|
# and recursively merges hashes
|
8
7
|
class OptionsHash < StringifyHash
|
9
|
-
|
10
8
|
# Determine if type of ObjectHash is pe, defaults to true
|
11
9
|
#
|
12
10
|
# @example Use this method to test if the :type setting is pe
|
@@ -38,12 +36,9 @@ module Beaker
|
|
38
36
|
|
39
37
|
def dump_to_file(output_file)
|
40
38
|
dirname = File.dirname(output_file)
|
41
|
-
unless File.directory?(dirname)
|
42
|
-
|
43
|
-
end
|
44
|
-
File.open(output_file, 'w+') { |f| f.write(dump) }
|
39
|
+
FileUtils.mkdir_p(dirname) unless File.directory?(dirname)
|
40
|
+
File.write(output_file, dump)
|
45
41
|
end
|
46
|
-
|
47
42
|
end
|
48
43
|
end
|
49
44
|
end
|