beaker 4.40.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.
- 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
|
@@ -11,7 +11,7 @@ module Unix::Exec
|
|
|
11
11
|
# @param [Integer] uptime_retries How many times to check to see if the value of the uptime has reset.
|
|
12
12
|
#
|
|
13
13
|
# Will throw an exception RebootFailure if it fails
|
|
14
|
-
def reboot(wait_time=10, max_connection_tries=9, uptime_retries=18)
|
|
14
|
+
def reboot(wait_time = 10, max_connection_tries = 9, uptime_retries = 18)
|
|
15
15
|
require 'time'
|
|
16
16
|
|
|
17
17
|
attempts = 0
|
|
@@ -30,7 +30,7 @@ module Unix::Exec
|
|
|
30
30
|
# Number of seconds to sleep before rebooting.
|
|
31
31
|
reboot_sleep = 1
|
|
32
32
|
|
|
33
|
-
original_boot_time_str = exec(Beaker::Command.new(boot_time_cmd), {:max_connection_tries => max_connection_tries, :silent => true}).stdout
|
|
33
|
+
original_boot_time_str = exec(Beaker::Command.new(boot_time_cmd), { :max_connection_tries => max_connection_tries, :silent => true }).stdout
|
|
34
34
|
original_boot_time_line = original_boot_time_str.lines.grep(/boot/).first
|
|
35
35
|
|
|
36
36
|
raise Beaker::Host::RebootWarning, "Could not find system boot time using '#{boot_time_cmd}': '#{original_boot_time_str}'" unless original_boot_time_line
|
|
@@ -41,9 +41,7 @@ module Unix::Exec
|
|
|
41
41
|
|
|
42
42
|
original_boot_time = Time.parse(original_boot_time_matches.first)
|
|
43
43
|
|
|
44
|
-
unless original_boot_time_matches.last
|
|
45
|
-
reboot_sleep = (61 - Time.now.strftime("%S").to_i)
|
|
46
|
-
end
|
|
44
|
+
reboot_sleep = (61 - Time.now.strftime("%S").to_i) unless original_boot_time_matches.last
|
|
47
45
|
|
|
48
46
|
@logger.notify("Sleeping #{reboot_sleep} seconds before rebooting")
|
|
49
47
|
|
|
@@ -54,14 +52,16 @@ module Unix::Exec
|
|
|
54
52
|
raise Beaker::Host::RebootFailure, "Unable to parse time: #{e.message}"
|
|
55
53
|
rescue Beaker::Host::RebootWarning => e
|
|
56
54
|
raise if attempts > uptime_retries
|
|
55
|
+
|
|
57
56
|
@logger.warn(e.message)
|
|
58
57
|
@logger.warn("Retrying #{uptime_retries - attempts} more times.")
|
|
59
58
|
retry
|
|
60
59
|
rescue StandardError => e
|
|
61
60
|
raise if attempts > uptime_retries
|
|
61
|
+
|
|
62
62
|
@logger.warn("Unexpected Exception: #{e.message}")
|
|
63
63
|
@logger.warn("Retrying #{uptime_retries - attempts} more times.")
|
|
64
|
-
@logger.warn(e.backtrace[0,3].join("\n"))
|
|
64
|
+
@logger.warn(e.backtrace[0, 3].join("\n"))
|
|
65
65
|
@logger.debug(e.backtrace.join("\n"))
|
|
66
66
|
retry
|
|
67
67
|
end
|
|
@@ -75,7 +75,7 @@ module Unix::Exec
|
|
|
75
75
|
sleep wait_time
|
|
76
76
|
|
|
77
77
|
# Accept all exit codes because this may fail due to the parallel nature of systemd
|
|
78
|
-
current_boot_time_str = exec(Beaker::Command.new(boot_time_cmd), {:max_connection_tries => max_connection_tries, :silent => true, :accept_all_exit_codes => true}).stdout
|
|
78
|
+
current_boot_time_str = exec(Beaker::Command.new(boot_time_cmd), { :max_connection_tries => max_connection_tries, :silent => true, :accept_all_exit_codes => true }).stdout
|
|
79
79
|
current_boot_time_line = current_boot_time_str.lines.grep(/boot/).first
|
|
80
80
|
|
|
81
81
|
raise Beaker::Host::RebootWarning, "Could not find system boot time using '#{boot_time_cmd}': '#{current_boot_time_str}'" unless current_boot_time_line
|
|
@@ -90,33 +90,33 @@ module Unix::Exec
|
|
|
90
90
|
@logger.debug("Current Boot Time: #{current_boot_time}")
|
|
91
91
|
|
|
92
92
|
# If this is *exactly* the same then there is really no good way to detect a reboot
|
|
93
|
-
if current_boot_time == original_boot_time
|
|
94
|
-
raise Beaker::Host::RebootFailure, "Boot time did not reset. Reboot appears to have failed."
|
|
95
|
-
end
|
|
93
|
+
raise Beaker::Host::RebootFailure, "Boot time did not reset. Reboot appears to have failed." if current_boot_time == original_boot_time
|
|
96
94
|
rescue ArgumentError => e
|
|
97
95
|
raise Beaker::Host::RebootFailure, "Unable to parse time: #{e.message}"
|
|
98
96
|
rescue Beaker::Host::RebootFailure => e
|
|
99
97
|
raise
|
|
100
98
|
rescue Beaker::Host::RebootWarning => e
|
|
101
99
|
raise if attempts > uptime_retries
|
|
100
|
+
|
|
102
101
|
@logger.warn(e.message)
|
|
103
102
|
@logger.warn("Retrying #{uptime_retries - attempts} more times.")
|
|
104
103
|
retry
|
|
105
104
|
rescue StandardError => e
|
|
106
105
|
raise if attempts > uptime_retries
|
|
106
|
+
|
|
107
107
|
@logger.warn("Unexpected Exception: #{e.message}")
|
|
108
108
|
@logger.warn("Retrying #{uptime_retries - attempts} more times.")
|
|
109
|
-
@logger.warn(e.backtrace[0,3].join("\n"))
|
|
109
|
+
@logger.warn(e.backtrace[0, 3].join("\n"))
|
|
110
110
|
@logger.debug(e.backtrace.join("\n"))
|
|
111
111
|
retry
|
|
112
112
|
end
|
|
113
113
|
end
|
|
114
114
|
|
|
115
|
-
def echo(msg, abs=true)
|
|
115
|
+
def echo(msg, abs = true)
|
|
116
116
|
(abs ? '/bin/echo' : 'echo') + " #{msg}"
|
|
117
117
|
end
|
|
118
118
|
|
|
119
|
-
def touch(file, abs=true)
|
|
119
|
+
def touch(file, abs = true)
|
|
120
120
|
(abs ? '/bin/touch' : 'touch') + " #{file}"
|
|
121
121
|
end
|
|
122
122
|
|
|
@@ -163,7 +163,7 @@ module Unix::Exec
|
|
|
163
163
|
# @param [String] orig The origin path
|
|
164
164
|
# @param [String] dest the destination path
|
|
165
165
|
# @param [Boolean] rm Remove the destination prior to move
|
|
166
|
-
def mv orig, dest, rm=true
|
|
166
|
+
def mv orig, dest, rm = true
|
|
167
167
|
rm_rf dest unless !rm
|
|
168
168
|
execute("mv #{orig} #{dest}")
|
|
169
169
|
end
|
|
@@ -172,14 +172,13 @@ module Unix::Exec
|
|
|
172
172
|
# @param [String] target The hostname to ping
|
|
173
173
|
# @param [Integer] attempts Amount of times to attempt ping before giving up
|
|
174
174
|
# @return [Boolean] true of ping successful, overwise false
|
|
175
|
-
def ping target, attempts=5
|
|
175
|
+
def ping target, attempts = 5
|
|
176
176
|
try = 0
|
|
177
|
-
while try < attempts
|
|
177
|
+
while try < attempts
|
|
178
178
|
result = exec(Beaker::Command.new("ping -c 1 #{target}"), :accept_all_exit_codes => true)
|
|
179
|
-
if result.exit_code == 0
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
try+=1
|
|
179
|
+
return true if result.exit_code == 0
|
|
180
|
+
|
|
181
|
+
try += 1
|
|
183
182
|
end
|
|
184
183
|
result.exit_code == 0
|
|
185
184
|
end
|
|
@@ -195,81 +194,82 @@ module Unix::Exec
|
|
|
195
194
|
cur_env.each_line do |env_line|
|
|
196
195
|
shell_env << "export #{env_line}"
|
|
197
196
|
end
|
|
198
|
-
#here doc it over
|
|
197
|
+
# here doc it over
|
|
199
198
|
exec(Beaker::Command.new("cat << EOF > #{self[:profile_d_env_file]}\n#{shell_env}EOF"))
|
|
200
|
-
#set permissions
|
|
199
|
+
# set permissions
|
|
201
200
|
exec(Beaker::Command.new("chmod +x #{self[:profile_d_env_file]}"))
|
|
202
|
-
#keep it current
|
|
201
|
+
# keep it current
|
|
203
202
|
exec(Beaker::Command.new("source #{self[:profile_d_env_file]}"))
|
|
204
203
|
else
|
|
205
|
-
#noop
|
|
204
|
+
# noop
|
|
206
205
|
@logger.debug("will not mirror environment to /etc/profile.d on non-sles platform host")
|
|
207
206
|
end
|
|
208
207
|
end
|
|
209
208
|
|
|
210
|
-
#Add the provided key/val to the current ssh environment
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
209
|
+
# Add the provided key/val to the current ssh environment
|
|
210
|
+
# @param [String] key The key to add the value to
|
|
211
|
+
# @param [String] val The value for the key
|
|
212
|
+
# @example
|
|
214
213
|
# host.add_env_var('PATH', '/usr/bin:PATH')
|
|
215
214
|
def add_env_var key, val
|
|
216
215
|
key = key.to_s
|
|
217
216
|
env_file = self[:ssh_env_file]
|
|
218
217
|
escaped_val = Regexp.escape(val).gsub('/', '\/').gsub(';', '\;')
|
|
219
|
-
#see if the key/value pair already exists
|
|
220
|
-
if exec(Beaker::Command.new("grep ^#{key}=.*#{escaped_val} #{env_file}"), :accept_all_exit_codes => true
|
|
221
|
-
return #nothing to do here, key value pair already exists
|
|
222
|
-
#see if the key already exists
|
|
223
|
-
elsif exec(Beaker::Command.new("grep ^#{key}= #{env_file}"), :accept_all_exit_codes => true
|
|
218
|
+
# see if the key/value pair already exists
|
|
219
|
+
if exec(Beaker::Command.new("grep ^#{key}=.*#{escaped_val} #{env_file}"), :accept_all_exit_codes => true).exit_code == 0
|
|
220
|
+
return # nothing to do here, key value pair already exists
|
|
221
|
+
# see if the key already exists
|
|
222
|
+
elsif exec(Beaker::Command.new("grep ^#{key}= #{env_file}"), :accept_all_exit_codes => true).exit_code == 0
|
|
224
223
|
exec(Beaker::SedCommand.new(self['platform'], "s/^#{key}=/#{key}=#{escaped_val}:/", env_file))
|
|
225
224
|
else
|
|
226
225
|
exec(Beaker::Command.new("echo \"#{key}=#{val}\" >> #{env_file}"))
|
|
227
226
|
end
|
|
228
|
-
|
|
229
|
-
#
|
|
227
|
+
|
|
228
|
+
# update the profile.d to current state
|
|
229
|
+
# match it to the contents of ssh_env_file
|
|
230
230
|
mirror_env_to_profile_d(env_file)
|
|
231
231
|
end
|
|
232
232
|
|
|
233
|
-
#Delete the provided key/val from the current ssh environment
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
233
|
+
# Delete the provided key/val from the current ssh environment
|
|
234
|
+
# @param [String] key The key to delete the value from
|
|
235
|
+
# @param [String] val The value to delete for the key
|
|
236
|
+
# @example
|
|
237
237
|
# host.delete_env_var('PATH', '/usr/bin:PATH')
|
|
238
238
|
def delete_env_var key, val
|
|
239
239
|
key = key.to_s
|
|
240
240
|
env_file = self[:ssh_env_file]
|
|
241
241
|
val = Regexp.escape(val).gsub('/', '\/').gsub(';', '\;')
|
|
242
|
-
#if the key only has that single value remove the entire line
|
|
242
|
+
# if the key only has that single value remove the entire line
|
|
243
243
|
exec(Beaker::SedCommand.new(self['platform'], "/#{key}=#{val}$/d", env_file))
|
|
244
|
-
#value in middle of list
|
|
244
|
+
# value in middle of list
|
|
245
245
|
exec(Beaker::SedCommand.new(self['platform'], "s/#{key}=\\(.*\\)[;:]#{val}/#{key}=\\1/", env_file))
|
|
246
|
-
#value in start of list
|
|
246
|
+
# value in start of list
|
|
247
247
|
exec(Beaker::SedCommand.new(self['platform'], "s/#{key}=#{val}[;:]/#{key}=/", env_file))
|
|
248
|
-
#update the profile.d to current state
|
|
249
|
-
#match it to the contents of ssh_env_file
|
|
248
|
+
# update the profile.d to current state
|
|
249
|
+
# match it to the contents of ssh_env_file
|
|
250
250
|
mirror_env_to_profile_d(env_file)
|
|
251
251
|
end
|
|
252
252
|
|
|
253
|
-
#Return the value of a specific env var
|
|
254
|
-
|
|
255
|
-
|
|
253
|
+
# Return the value of a specific env var
|
|
254
|
+
# @param [String] key The key to look for
|
|
255
|
+
# @example
|
|
256
256
|
# host.get_env_var('path')
|
|
257
257
|
def get_env_var key
|
|
258
258
|
key = key.to_s
|
|
259
259
|
exec(Beaker::Command.new("env | grep ^#{key}="), :accept_all_exit_codes => true).stdout.chomp
|
|
260
260
|
end
|
|
261
261
|
|
|
262
|
-
#Delete the environment variable from the current ssh environment
|
|
263
|
-
|
|
264
|
-
|
|
262
|
+
# Delete the environment variable from the current ssh environment
|
|
263
|
+
# @param [String] key The key to delete
|
|
264
|
+
# @example
|
|
265
265
|
# host.clear_env_var('PATH')
|
|
266
266
|
def clear_env_var key
|
|
267
267
|
key = key.to_s
|
|
268
268
|
env_file = self[:ssh_env_file]
|
|
269
|
-
#remove entire line
|
|
269
|
+
# remove entire line
|
|
270
270
|
exec(Beaker::SedCommand.new(self['platform'], "/^#{key}=.*$/d", env_file))
|
|
271
|
-
#update the profile.d to current state
|
|
272
|
-
#match it to the contents of ssh_env_file
|
|
271
|
+
# update the profile.d to current state
|
|
272
|
+
# match it to the contents of ssh_env_file
|
|
273
273
|
mirror_env_to_profile_d(env_file)
|
|
274
274
|
end
|
|
275
275
|
|
|
@@ -303,17 +303,17 @@ module Unix::Exec
|
|
|
303
303
|
def ssh_permit_user_environment
|
|
304
304
|
case self['platform']
|
|
305
305
|
when /debian|ubuntu|cumulus|huaweios|archlinux|el-|centos|fedora|redhat|oracle|scientific|eos|opensuse|sles|solaris/
|
|
306
|
-
directory = tmpdir
|
|
306
|
+
directory = tmpdir
|
|
307
307
|
exec(Beaker::Command.new("echo 'PermitUserEnvironment yes' | cat - /etc/ssh/sshd_config > #{directory}/sshd_config.permit"))
|
|
308
308
|
exec(Beaker::Command.new("mv #{directory}/sshd_config.permit /etc/ssh/sshd_config"))
|
|
309
309
|
exec(Beaker::Command.new("echo '' >/etc/environment")) if /ubuntu-2(0|2).04/.match?(self['platform'])
|
|
310
310
|
when /(free|open)bsd/
|
|
311
|
-
exec(Beaker::Command.new("sudo perl -pi -e 's/^#?PermitUserEnvironment no/PermitUserEnvironment yes/' /etc/ssh/sshd_config"), {:pty => true}
|
|
311
|
+
exec(Beaker::Command.new("sudo perl -pi -e 's/^#?PermitUserEnvironment no/PermitUserEnvironment yes/' /etc/ssh/sshd_config"), { :pty => true })
|
|
312
312
|
else
|
|
313
313
|
raise ArgumentError, "Unsupported Platform: '#{self['platform']}'"
|
|
314
314
|
end
|
|
315
315
|
|
|
316
|
-
ssh_service_restart
|
|
316
|
+
ssh_service_restart
|
|
317
317
|
end
|
|
318
318
|
|
|
319
319
|
# Construct the environment string for this command
|
|
@@ -329,7 +329,8 @@ module Unix::Exec
|
|
|
329
329
|
# given host.
|
|
330
330
|
def environment_string env
|
|
331
331
|
return '' if env.empty?
|
|
332
|
-
|
|
332
|
+
|
|
333
|
+
env_array = self.environment_variable_string_pair_array(env)
|
|
333
334
|
environment_string = env_array.join(' ')
|
|
334
335
|
"env #{environment_string}"
|
|
335
336
|
end
|
|
@@ -338,11 +339,11 @@ module Unix::Exec
|
|
|
338
339
|
env_array = []
|
|
339
340
|
env.each_key do |key|
|
|
340
341
|
val = env[key]
|
|
341
|
-
if val.is_a?(Array)
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
342
|
+
val = if val.is_a?(Array)
|
|
343
|
+
val.join(':')
|
|
344
|
+
else
|
|
345
|
+
val.to_s
|
|
346
|
+
end
|
|
346
347
|
# doing this for the key itself & the upcase'd version allows us to remain
|
|
347
348
|
# backwards compatible
|
|
348
349
|
# TODO: (Next Major Version) get rid of upcase'd version
|
|
@@ -387,33 +388,31 @@ module Unix::Exec
|
|
|
387
388
|
# @api private
|
|
388
389
|
# @return nil
|
|
389
390
|
def ssh_set_user_environment(env)
|
|
390
|
-
#ensure that ~/.ssh/environment exists
|
|
391
|
+
# ensure that ~/.ssh/environment exists
|
|
391
392
|
ssh_env_file_dir = Pathname.new(self[:ssh_env_file]).dirname
|
|
392
393
|
mkdir_p(ssh_env_file_dir)
|
|
393
394
|
exec(Beaker::Command.new("chmod 0600 #{ssh_env_file_dir}"))
|
|
394
395
|
exec(Beaker::Command.new("touch #{self[:ssh_env_file]}"))
|
|
395
|
-
#add the constructed env vars to this host
|
|
396
|
+
# add the constructed env vars to this host
|
|
396
397
|
add_env_var('PATH', '$PATH')
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
arch
|
|
401
|
-
arch = 'amd64' if ['x64', 'x86_64'].include?(arch)
|
|
402
|
-
add_env_var('PKG_PATH', "http://ftp.openbsd.org/pub/OpenBSD/#{version}/packages/#{arch}/")
|
|
398
|
+
if self['platform'].variant == 'openbsd'
|
|
399
|
+
arch = self['platform'].arch
|
|
400
|
+
arch = 'amd64' if %w[x64 x86_64].include?(arch)
|
|
401
|
+
add_env_var('PKG_PATH', "http://ftp.openbsd.org/pub/OpenBSD/#{self['platform'].version}/packages/#{arch}/")
|
|
403
402
|
elsif self['platform'].include?('solaris-10')
|
|
404
403
|
add_env_var('PATH', '/opt/csw/bin')
|
|
405
404
|
end
|
|
406
405
|
|
|
407
|
-
#add the env var set to this test host
|
|
406
|
+
# add the env var set to this test host
|
|
408
407
|
env.each_pair do |var, value|
|
|
409
408
|
add_env_var(var, value)
|
|
410
409
|
end
|
|
411
410
|
end
|
|
412
411
|
|
|
413
|
-
#
|
|
412
|
+
# Checks if selinux is enabled
|
|
414
413
|
#
|
|
415
414
|
# @return [Boolean] true if selinux is enabled, false otherwise
|
|
416
|
-
def selinux_enabled?
|
|
415
|
+
def selinux_enabled?
|
|
417
416
|
exec(Beaker::Command.new("sudo selinuxenabled"), :accept_all_exit_codes => true).exit_code == 0
|
|
418
417
|
end
|
|
419
418
|
|
|
@@ -424,7 +423,7 @@ module Unix::Exec
|
|
|
424
423
|
end
|
|
425
424
|
commands = [
|
|
426
425
|
"echo '*.* @#{server}:#{port}' >> /etc/rsyslog.d/51-sendrsyslogs.conf",
|
|
427
|
-
'systemctl restart rsyslog'
|
|
426
|
+
'systemctl restart rsyslog',
|
|
428
427
|
]
|
|
429
428
|
commands.each do |command|
|
|
430
429
|
exec(Beaker::Command.new(command))
|
|
@@ -432,21 +431,20 @@ module Unix::Exec
|
|
|
432
431
|
true
|
|
433
432
|
end
|
|
434
433
|
|
|
435
|
-
#First path it finds for the command executable
|
|
436
|
-
|
|
434
|
+
# First path it finds for the command executable
|
|
435
|
+
# @param [String] command The command executable to search for
|
|
437
436
|
#
|
|
438
437
|
# @return [String] Path to the searched executable or empty string if not found
|
|
439
438
|
#
|
|
440
|
-
|
|
439
|
+
# @example
|
|
441
440
|
# host.which('ruby')
|
|
442
441
|
def which(command)
|
|
443
442
|
unless @which_command
|
|
444
443
|
if execute('type -P true', :accept_all_exit_codes => true).empty?
|
|
445
|
-
if execute('which true', :accept_all_exit_codes => true).empty?
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
end
|
|
444
|
+
raise ArgumentError, "Could not find suitable 'which' command" if execute('which true', :accept_all_exit_codes => true).empty?
|
|
445
|
+
|
|
446
|
+
@which_command = 'which'
|
|
447
|
+
|
|
450
448
|
else
|
|
451
449
|
@which_command = 'type -P'
|
|
452
450
|
end
|
|
@@ -26,11 +26,11 @@ module Unix::File
|
|
|
26
26
|
# @param [Boolean] recursive Whether to pass the recursive flag
|
|
27
27
|
#
|
|
28
28
|
# @return [Beaker::Result] result of command execution
|
|
29
|
-
def chown(user, path, recursive=false)
|
|
29
|
+
def chown(user, path, recursive = false)
|
|
30
30
|
execute("chown #{recursive ? '-R ' : ''}#{user} #{path}")
|
|
31
31
|
end
|
|
32
32
|
|
|
33
|
-
def chmod(mod, path, recursive=false)
|
|
33
|
+
def chmod(mod, path, recursive = false)
|
|
34
34
|
execute("chmod #{recursive ? '-R ' : ''}#{mod} #{path}")
|
|
35
35
|
end
|
|
36
36
|
|
|
@@ -43,7 +43,7 @@ module Unix::File
|
|
|
43
43
|
# @param [Boolean] recursive Whether to pass the recursive flag
|
|
44
44
|
#
|
|
45
45
|
# @return [Beaker::Result] result of command execution
|
|
46
|
-
def chgrp(group, path, recursive=false)
|
|
46
|
+
def chgrp(group, path, recursive = false)
|
|
47
47
|
execute("chgrp #{recursive ? '-R ' : ''}#{group} #{path}")
|
|
48
48
|
end
|
|
49
49
|
|
|
@@ -110,11 +110,11 @@ module Unix::File
|
|
|
110
110
|
# @return [String] Filename of the repo
|
|
111
111
|
def repo_filename(package_name, build_version)
|
|
112
112
|
variant, version, arch, codename = self['platform'].to_array
|
|
113
|
-
repo_filename = "pl-%s-%s-"
|
|
113
|
+
repo_filename = format("pl-%s-%s-", package_name, build_version)
|
|
114
114
|
|
|
115
115
|
case variant
|
|
116
116
|
when /fedora|el|redhat|centos|cisco_nexus|cisco_ios_xr|opensuse|sles/
|
|
117
|
-
variant = 'el' if [
|
|
117
|
+
variant = 'el' if %w[centos redhat].include?(variant)
|
|
118
118
|
|
|
119
119
|
variant = 'redhatfips' if self['packaging_platform']&.include?('redhatfips')
|
|
120
120
|
|
|
@@ -126,19 +126,14 @@ module Unix::File
|
|
|
126
126
|
variant = 'cisco-wrlinux'
|
|
127
127
|
version = '7'
|
|
128
128
|
end
|
|
129
|
-
fedora_prefix = (
|
|
129
|
+
fedora_prefix = (variant == 'fedora' ? 'f' : '')
|
|
130
130
|
|
|
131
131
|
pattern = "%s-%s%s-%s.repo"
|
|
132
132
|
|
|
133
|
-
repo_filename << pattern
|
|
134
|
-
variant,
|
|
135
|
-
fedora_prefix,
|
|
136
|
-
version,
|
|
137
|
-
arch
|
|
138
|
-
]
|
|
133
|
+
repo_filename << (format(pattern, variant, fedora_prefix, version, arch))
|
|
139
134
|
when /debian|ubuntu|cumulus|huaweios/
|
|
140
135
|
codename = variant if variant == 'cumulus' || variant == 'huaweios'
|
|
141
|
-
repo_filename << "%s.list"
|
|
136
|
+
repo_filename << (format("%s.list", codename))
|
|
142
137
|
else
|
|
143
138
|
msg = "#repo_filename: repo filename pattern not known for platform '#{self['platform']}'"
|
|
144
139
|
raise ArgumentError, msg
|
|
@@ -171,36 +166,36 @@ module Unix::File
|
|
|
171
166
|
# @return [String] the text of the noask file
|
|
172
167
|
def noask_file_text
|
|
173
168
|
if self['platform'].variant == 'solaris' && self['platform'].version == '10'
|
|
174
|
-
noask =
|
|
175
|
-
# Write the noask file to a temporary directory
|
|
176
|
-
# please see man -s 4 admin for details about this file:
|
|
177
|
-
# http://www.opensolarisforum.org/man/man4/admin.html
|
|
178
|
-
#
|
|
179
|
-
# The key thing we don't want to prompt for are conflicting files.
|
|
180
|
-
# The other nocheck settings are mostly defensive to prevent prompts
|
|
181
|
-
# We _do_ want to check for available free space and abort if there is
|
|
182
|
-
# not enough
|
|
183
|
-
mail=
|
|
184
|
-
# Overwrite already installed instances
|
|
185
|
-
instance=overwrite
|
|
186
|
-
# Do not bother checking for partially installed packages
|
|
187
|
-
partial=nocheck
|
|
188
|
-
# Do not bother checking the runlevel
|
|
189
|
-
runlevel=nocheck
|
|
190
|
-
# Do not bother checking package dependencies (We take care of this)
|
|
191
|
-
idepend=nocheck
|
|
192
|
-
rdepend=nocheck
|
|
193
|
-
# DO check for available free space and abort if there isn't enough
|
|
194
|
-
space=quit
|
|
195
|
-
# Do not check for setuid files.
|
|
196
|
-
setuid=nocheck
|
|
197
|
-
# Do not check if files conflict with other packages
|
|
198
|
-
conflict=nocheck
|
|
199
|
-
# We have no action scripts. Do not check for them.
|
|
200
|
-
action=nocheck
|
|
201
|
-
# Install to the default base directory.
|
|
202
|
-
basedir=default
|
|
203
|
-
NOASK
|
|
169
|
+
noask = <<~NOASK
|
|
170
|
+
# Write the noask file to a temporary directory
|
|
171
|
+
# please see man -s 4 admin for details about this file:
|
|
172
|
+
# http://www.opensolarisforum.org/man/man4/admin.html
|
|
173
|
+
#
|
|
174
|
+
# The key thing we don't want to prompt for are conflicting files.
|
|
175
|
+
# The other nocheck settings are mostly defensive to prevent prompts
|
|
176
|
+
# We _do_ want to check for available free space and abort if there is
|
|
177
|
+
# not enough
|
|
178
|
+
mail=
|
|
179
|
+
# Overwrite already installed instances
|
|
180
|
+
instance=overwrite
|
|
181
|
+
# Do not bother checking for partially installed packages
|
|
182
|
+
partial=nocheck
|
|
183
|
+
# Do not bother checking the runlevel
|
|
184
|
+
runlevel=nocheck
|
|
185
|
+
# Do not bother checking package dependencies (We take care of this)
|
|
186
|
+
idepend=nocheck
|
|
187
|
+
rdepend=nocheck
|
|
188
|
+
# DO check for available free space and abort if there isn't enough
|
|
189
|
+
space=quit
|
|
190
|
+
# Do not check for setuid files.
|
|
191
|
+
setuid=nocheck
|
|
192
|
+
# Do not check if files conflict with other packages
|
|
193
|
+
conflict=nocheck
|
|
194
|
+
# We have no action scripts. Do not check for them.
|
|
195
|
+
action=nocheck
|
|
196
|
+
# Install to the default base directory.
|
|
197
|
+
basedir=default
|
|
198
|
+
NOASK
|
|
204
199
|
else
|
|
205
200
|
msg = "noask file text unknown for platform '#{self['platform']}'"
|
|
206
201
|
raise ArgumentError, msg
|