beaker 4.1.0 → 4.2.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/CHANGELOG.md +18 -1
- data/acceptance/tests/base/dsl/helpers/host_helpers/create_remote_file_test.rb +36 -18
- data/acceptance/tests/base/dsl/helpers/host_helpers/rsync_to_test.rb +26 -18
- data/docs/tutorials/lets_write_a_test.md +21 -1
- data/lib/beaker/command.rb +5 -8
- data/lib/beaker/host/cisco.rb +13 -0
- data/lib/beaker/host/unix/exec.rb +11 -0
- data/lib/beaker/host/windows/exec.rb +11 -0
- data/lib/beaker/network_manager.rb +3 -4
- data/lib/beaker/options/parser.rb +4 -1
- data/lib/beaker/subcommand.rb +1 -8
- data/lib/beaker/subcommands/subcommand_util.rb +16 -1
- data/lib/beaker/version.rb +1 -1
- data/spec/beaker/command_spec.rb +25 -0
- data/spec/beaker/host/cisco_spec.rb +65 -0
- data/spec/beaker/options/parser_spec.rb +33 -0
- data/spec/beaker/subcommand/subcommand_util_spec.rb +36 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 700b4229c8f566623b2a3a3caf5ae26308c4bb82
|
4
|
+
data.tar.gz: 27a0432eaba2fd5cb77080b86faac0c1b337062f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 906361a2f47a868f2062684db26eac305079df40c11aefbc081316d01722a82ed18f94f808aba9167bbe52a656a4c6d3f07c9a27ec1cc2dd341d1b0bd90a5171
|
7
|
+
data.tar.gz: b763ee73c7882b8280da83dbab6fcbc7817c1d2b19ff5ea7aa43b7fedcf90e0bf5c3c44d8a397b519d437b7f0c36f81051b94377b275e3511481bfadadb2bad8
|
data/CHANGELOG.md
CHANGED
@@ -11,7 +11,24 @@ Tracking in this Changelog began for this project in version 3.25.0.
|
|
11
11
|
If you're looking for changes from before this, refer to the project's
|
12
12
|
git logs & PR history.
|
13
13
|
|
14
|
-
# [Unreleased](https://github.com/puppetlabs/beaker/compare/4.
|
14
|
+
# [Unreleased](https://github.com/puppetlabs/beaker/compare/4.2.0...master)
|
15
|
+
|
16
|
+
# [4.2.0](https://github.com/puppetlabs/beaker/compare/4.1.0...4.2.0) - 2018.11.28
|
17
|
+
|
18
|
+
### Added
|
19
|
+
|
20
|
+
- `BEAKER_HYPERVISOR` environment variable to choose the beaker-hostgenerator hypervisor
|
21
|
+
|
22
|
+
### Changed
|
23
|
+
|
24
|
+
- Handling of vsh appended commands for cisco_nexus (BKR-1556)
|
25
|
+
- Acceptance tests: Add backoffs to other create_remote_file test
|
26
|
+
|
27
|
+
### Fixed
|
28
|
+
|
29
|
+
- Don't always start a new container with docker (can be reused between invocations of the provision and exec beaker subcommands) (BKR-1547)
|
30
|
+
- Recursively remove unpersisted subcommand options (BKR-1549)
|
31
|
+
|
15
32
|
|
16
33
|
# [4.1.0](https://github.com/puppetlabs/beaker/compare/4.0.0...4.1.0) - 2018.10.25
|
17
34
|
|
@@ -2,6 +2,32 @@ require "helpers/test_helper"
|
|
2
2
|
|
3
3
|
test_name "dsl::helpers::host_helpers #create_remote_file" do
|
4
4
|
|
5
|
+
def create_remote_file_with_backups host, remote_filename, contents, opts={}
|
6
|
+
result = nil
|
7
|
+
repeat_fibonacci_style_for(10) do
|
8
|
+
begin
|
9
|
+
result = create_remote_file(
|
10
|
+
host, remote_filename, contents, opts
|
11
|
+
) # return of block is whether or not we're done repeating
|
12
|
+
if result.is_a?(Rsync::Result) || result.is_a?(Beaker::Result)
|
13
|
+
return result.success?
|
14
|
+
end
|
15
|
+
|
16
|
+
result.each do |individual_result|
|
17
|
+
next if individual_result.success?
|
18
|
+
return false
|
19
|
+
end
|
20
|
+
true
|
21
|
+
rescue Beaker::Host::CommandFailure => err
|
22
|
+
logger.info("create_remote_file threw command failure, details: ")
|
23
|
+
logger.info(" #{err}")
|
24
|
+
logger.info("continuing back-off execution")
|
25
|
+
false
|
26
|
+
end
|
27
|
+
end
|
28
|
+
result
|
29
|
+
end
|
30
|
+
|
5
31
|
if test_scp_error_on_close?
|
6
32
|
step "#create_remote_file fails when the remote path does not exist" do
|
7
33
|
assert_raises Beaker::Host::CommandFailure do
|
@@ -21,7 +47,7 @@ test_name "dsl::helpers::host_helpers #create_remote_file" do
|
|
21
47
|
remote_filename = File.join(remote_tmpdir, "testfile.txt")
|
22
48
|
contents = fixture_contents("simple_text_file")
|
23
49
|
|
24
|
-
|
50
|
+
create_remote_file_with_backups default, remote_filename, contents
|
25
51
|
|
26
52
|
remote_contents = on(default, "cat #{remote_filename}").stdout
|
27
53
|
assert_equal contents, remote_contents
|
@@ -32,7 +58,7 @@ test_name "dsl::helpers::host_helpers #create_remote_file" do
|
|
32
58
|
remote_filename = File.join(remote_tmpdir, "testfile.txt")
|
33
59
|
contents = fixture_contents("simple_text_file")
|
34
60
|
|
35
|
-
|
61
|
+
create_remote_file_with_backups default, remote_filename, contents, { :protocol => "scp" }
|
36
62
|
|
37
63
|
remote_contents = on(default, "cat #{remote_filename}").stdout
|
38
64
|
assert_equal contents, remote_contents
|
@@ -49,7 +75,7 @@ test_name "dsl::helpers::host_helpers #create_remote_file" do
|
|
49
75
|
remote_filename = File.join(remote_dir, "testfile.txt")
|
50
76
|
contents = fixture_contents("simple_text_file")
|
51
77
|
|
52
|
-
|
78
|
+
create_remote_file_with_backups hosts, remote_filename, contents
|
53
79
|
|
54
80
|
hosts.each do |host|
|
55
81
|
remote_contents = on(host, "cat #{remote_filename}").stdout
|
@@ -68,7 +94,7 @@ test_name "dsl::helpers::host_helpers #create_remote_file" do
|
|
68
94
|
remote_filename = File.join(remote_dir, "testfile.txt")
|
69
95
|
contents = fixture_contents("simple_text_file")
|
70
96
|
|
71
|
-
|
97
|
+
create_remote_file_with_backups hosts, remote_filename, contents, { :protocol => 'scp' }
|
72
98
|
|
73
99
|
hosts.each do |host|
|
74
100
|
remote_contents = on(host, "cat #{remote_filename}").stdout
|
@@ -112,19 +138,9 @@ test_name "dsl::helpers::host_helpers #create_remote_file" do
|
|
112
138
|
remote_filename = File.join(remote_tmpdir, "testfile.txt")
|
113
139
|
contents = fixture_contents("simple_text_file")
|
114
140
|
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
default, remote_filename, contents, { :protocol => "rsync" }
|
119
|
-
) # return of block is whether or not we're done repeating
|
120
|
-
result.success?
|
121
|
-
rescue Beaker::Host::CommandFailure => err
|
122
|
-
logger.info("Rsync threw command failure, details: ")
|
123
|
-
logger.info(" #{err}")
|
124
|
-
logger.info("continuing back-off execution")
|
125
|
-
false
|
126
|
-
end
|
127
|
-
end
|
141
|
+
create_remote_file_with_backups(
|
142
|
+
default, remote_filename, contents, { :protocol => "rsync" }
|
143
|
+
)
|
128
144
|
|
129
145
|
fails_intermittently("https://tickets.puppetlabs.com/browse/BKR-612",
|
130
146
|
"default" => default,
|
@@ -149,7 +165,9 @@ test_name "dsl::helpers::host_helpers #create_remote_file" do
|
|
149
165
|
remote_filename = File.join(remote_tmpdir, "testfile.txt")
|
150
166
|
contents = fixture_contents("simple_text_file")
|
151
167
|
|
152
|
-
result =
|
168
|
+
result = create_remote_file_with_backups(
|
169
|
+
hosts, remote_filename, contents, { :protocol => 'rsync' }
|
170
|
+
)
|
153
171
|
|
154
172
|
hosts.each do |host|
|
155
173
|
fails_intermittently("https://tickets.puppetlabs.com/browse/BKR-612",
|
@@ -3,6 +3,30 @@ require "rsync"
|
|
3
3
|
|
4
4
|
test_name "dsl::helpers::host_helpers #rsync_to" do
|
5
5
|
|
6
|
+
def rsync_to_with_backups hosts, local_filename, remote_dir
|
7
|
+
result = nil
|
8
|
+
repeat_fibonacci_style_for(10) do
|
9
|
+
begin
|
10
|
+
result = rsync_to(
|
11
|
+
hosts, local_filename, remote_dir
|
12
|
+
) # return of block is whether or not we're done repeating
|
13
|
+
return result.success? if result.is_a? Rsync::Result
|
14
|
+
|
15
|
+
result.each do |individual_result|
|
16
|
+
next if individual_result.success?
|
17
|
+
return false
|
18
|
+
end
|
19
|
+
true
|
20
|
+
rescue Beaker::Host::CommandFailure => err
|
21
|
+
logger.info("create_remote_file threw command failure, details: ")
|
22
|
+
logger.info(" #{err}")
|
23
|
+
logger.info("continuing back-off execution")
|
24
|
+
false
|
25
|
+
end
|
26
|
+
end
|
27
|
+
result
|
28
|
+
end
|
29
|
+
|
6
30
|
# NOTE: there does not seem to be a reliable way to confine to cygwin hosts.
|
7
31
|
confine_block :to, :platform => /windows/ do
|
8
32
|
|
@@ -99,7 +123,7 @@ test_name "dsl::helpers::host_helpers #rsync_to" do
|
|
99
123
|
remote_tmpdir = default.tmpdir()
|
100
124
|
remote_filename = File.join(remote_tmpdir, "testfile.txt")
|
101
125
|
|
102
|
-
result =
|
126
|
+
result = rsync_to_with_backups default, local_filename, remote_tmpdir
|
103
127
|
|
104
128
|
fails_intermittently("https://tickets.puppetlabs.com/browse/QENG-3053",
|
105
129
|
"result" => result,
|
@@ -124,23 +148,7 @@ test_name "dsl::helpers::host_helpers #rsync_to" do
|
|
124
148
|
on hosts, "mkdir -p #{remote_tmpdir}"
|
125
149
|
remote_filename = File.join(remote_tmpdir, "testfile.txt")
|
126
150
|
|
127
|
-
|
128
|
-
begin
|
129
|
-
result = rsync_to hosts, local_filename, remote_tmpdir
|
130
|
-
return result.success? if result.is_a? Rsync::Result
|
131
|
-
|
132
|
-
result.each do |individual_result|
|
133
|
-
next if individual_result.success?
|
134
|
-
return false
|
135
|
-
end
|
136
|
-
true
|
137
|
-
rescue Beaker::Host::CommandFailure => err
|
138
|
-
logger.info("Rsync threw command failure, details: ")
|
139
|
-
logger.info(" #{err}")
|
140
|
-
logger.info("continuing back-off execution")
|
141
|
-
false
|
142
|
-
end
|
143
|
-
end
|
151
|
+
result = rsync_to_with_backups(hosts, local_filename, remote_tmpdir)
|
144
152
|
|
145
153
|
hosts.each do |host|
|
146
154
|
fails_intermittently("https://tickets.puppetlabs.com/browse/QENG-3053",
|
@@ -89,7 +89,27 @@ end
|
|
89
89
|
You can now run this with
|
90
90
|
|
91
91
|
```console
|
92
|
-
|
92
|
+
$ beaker --host redhat7-64ma.yaml --pre-suite install.rb --tests mytest.rb
|
93
|
+
```
|
94
|
+
|
95
|
+
## Creating the host configuration on at runtime
|
96
|
+
|
97
|
+
When you don't want to store a static file, you can also let [beaker-hostgenerator](https://github.com/puppetlabs/beaker-hostgenerator) generate it on the fly. The filename is used as a host specification. A simple example is:
|
98
|
+
|
99
|
+
```console
|
100
|
+
$ beaker --host centos7-64 --pre-suite install.rb --tests mytest.rb
|
101
|
+
```
|
102
|
+
|
103
|
+
It's also possible to set the hypervisor and hostname:
|
104
|
+
|
105
|
+
```console
|
106
|
+
$ beaker --host 'centos7-64{hypervisor=docker,hostname=centos7-64.example.com}' --pre-suite install.rb --tests mytest.rb
|
107
|
+
```
|
108
|
+
|
109
|
+
An alternative way to set the hypervisor is `BEAKER_HYPERVISOR`:
|
110
|
+
|
111
|
+
```console
|
112
|
+
$ BEAKER_HYPERVISOR=docker beaker --host centos7-64 --pre-suite install.rb --tests mytest.rb
|
93
113
|
```
|
94
114
|
|
95
115
|
Next up you may want to look at the [Beaker test for a module](../how_to/write_a_beaker_test_for_a_module.md) page.
|
data/lib/beaker/command.rb
CHANGED
@@ -51,6 +51,7 @@ module Beaker
|
|
51
51
|
@environment = {}
|
52
52
|
@cmdexe = @options.delete(:cmdexe) || false
|
53
53
|
@prepend_cmds = @options.delete(:prepend_cmds) || nil
|
54
|
+
@append_cmds = @options.delete(:append_cmds) || nil
|
54
55
|
|
55
56
|
# this is deprecated and will not allow you to use a command line
|
56
57
|
# option of `--environment`, please use ENV instead.
|
@@ -69,21 +70,17 @@ module Beaker
|
|
69
70
|
# @param [String] pc An optional list of commands to prepend
|
70
71
|
#
|
71
72
|
# @return [String] This returns the fully formed command line invocation.
|
72
|
-
def cmd_line host, cmd = @command, env = @environment, pc = @prepend_cmds
|
73
|
+
def cmd_line host, cmd = @command, env = @environment, pc = @prepend_cmds, ac = @append_cmds
|
73
74
|
env_string = host.environment_string( env )
|
74
75
|
prepend_commands = host.prepend_commands( cmd, pc, :cmd_exe => @cmdexe )
|
75
|
-
|
76
|
-
append_command = '"'
|
77
|
-
cmd = cmd.gsub('"') { '\\"' }
|
78
|
-
end
|
76
|
+
append_commands = host.append_commands( cmd, ac, :cmd_exe => @cmdexe )
|
79
77
|
|
80
78
|
# This will cause things like `puppet -t -v agent` which is maybe bad.
|
81
79
|
if host[:platform] =~ /cisco_ios_xr/
|
82
|
-
cmd_line_array = [prepend_commands, env_string, cmd, options_string, args_string]
|
80
|
+
cmd_line_array = [prepend_commands, env_string, cmd, options_string, args_string, append_commands]
|
83
81
|
else
|
84
|
-
cmd_line_array = [env_string, prepend_commands, cmd, options_string, args_string]
|
82
|
+
cmd_line_array = [env_string, prepend_commands, cmd, options_string, args_string, append_commands]
|
85
83
|
end
|
86
|
-
cmd_line_array << append_command unless (cmd =~ /ntpdate/ && host[:platform] =~ /cisco_nexus/)
|
87
84
|
cmd_line_array.compact.reject( &:empty? ).join( ' ' )
|
88
85
|
end
|
89
86
|
|
data/lib/beaker/host/cisco.rb
CHANGED
@@ -85,6 +85,19 @@ module Cisco
|
|
85
85
|
prepend_cmds.strip
|
86
86
|
end
|
87
87
|
|
88
|
+
# Gets the specific append commands as needed for this host
|
89
|
+
#
|
90
|
+
# @param [String] command Command to be executed
|
91
|
+
# @param [String] user_ac List of user-specified commands to append
|
92
|
+
# @param [Hash] opts optional parameters
|
93
|
+
#
|
94
|
+
# @return [String] Command string as needed for this host
|
95
|
+
def append_commands(command = '', user_ac = '', opts = {})
|
96
|
+
command.gsub('"') {'\\"'}
|
97
|
+
# vsh commands and ntpdate commands do not require an appended `"`
|
98
|
+
return '"' unless command =~ /ntpdate|\/isan\/bin\/vsh/
|
99
|
+
end
|
100
|
+
|
88
101
|
# Construct the environment string for this command
|
89
102
|
#
|
90
103
|
# @param [Hash{String=>String}] env An optional Hash containing
|
@@ -270,6 +270,17 @@ module Unix::Exec
|
|
270
270
|
user_pc
|
271
271
|
end
|
272
272
|
|
273
|
+
# Gets the specific append commands as needed for this host
|
274
|
+
#
|
275
|
+
# @param [String] command Command to be executed
|
276
|
+
# @param [String] user_ac List of user-specified commands to append
|
277
|
+
# @param [Hash] opts optional parameters
|
278
|
+
#
|
279
|
+
# @return [String] Command string as needed for this host
|
280
|
+
def append_commands(command = '', user_ac = '', opts = {})
|
281
|
+
user_ac
|
282
|
+
end
|
283
|
+
|
273
284
|
# Fills the user SSH environment file.
|
274
285
|
#
|
275
286
|
# @param [Hash{String=>String}] env Environment variables to set on the system,
|
@@ -100,6 +100,17 @@ module Windows::Exec
|
|
100
100
|
"#{cygwin_prefix}#{spacing}#{user_pc}"
|
101
101
|
end
|
102
102
|
|
103
|
+
# Gets the specific append commands as needed for this host
|
104
|
+
#
|
105
|
+
# @param [String] command Command to be executed
|
106
|
+
# @param [String] user_ac List of user-specified commands to append
|
107
|
+
# @param [Hash] opts optional parameters
|
108
|
+
#
|
109
|
+
# @return [String] Command string as needed for this host
|
110
|
+
def append_commands(command = '', user_ac = '', opts = {})
|
111
|
+
user_ac
|
112
|
+
end
|
113
|
+
|
103
114
|
# Checks if selinux is enabled
|
104
115
|
# selinux is not available on Windows
|
105
116
|
#
|
@@ -12,13 +12,12 @@ module Beaker
|
|
12
12
|
# - only if we are running with ---provision
|
13
13
|
# - only if we have a hypervisor
|
14
14
|
# - only if either the specific hosts has no specification or has 'provision' in its config
|
15
|
-
# - always if it is a vagrant
|
16
|
-
#
|
17
|
-
# specified)
|
15
|
+
# - always if it is a vagrant box (vagrant boxes are always provisioned as
|
16
|
+
# they always need ssh key hacking.)
|
18
17
|
def provision? options, host
|
19
18
|
command_line_says = options[:provision]
|
20
19
|
host_says = host['hypervisor'] && (host.has_key?('provision') ? host['provision'] : true)
|
21
|
-
(command_line_says && host_says) or (host['hypervisor'] =~/(vagrant
|
20
|
+
(command_line_says && host_says) or (host['hypervisor'] =~/(vagrant)/)
|
22
21
|
end
|
23
22
|
|
24
23
|
attr_accessor :hosts, :hypervisors
|
@@ -291,8 +291,11 @@ module Beaker
|
|
291
291
|
$stdout.puts dne_message
|
292
292
|
require 'beaker-hostgenerator'
|
293
293
|
|
294
|
+
host_generator_options = [ @options[:hosts_file] ]
|
295
|
+
host_generator_options += [ '--hypervisor', ENV['BEAKER_HYPERVISOR'] ] if ENV['BEAKER_HYPERVISOR']
|
296
|
+
|
294
297
|
hosts_file_content = begin
|
295
|
-
bhg_cli = BeakerHostGenerator::CLI.new(
|
298
|
+
bhg_cli = BeakerHostGenerator::CLI.new(host_generator_options)
|
296
299
|
bhg_cli.execute
|
297
300
|
rescue BeakerHostGenerator::Exceptions::Error,
|
298
301
|
BeakerHostGenerator::Exceptions::InvalidNodeSpecError => error
|
data/lib/beaker/subcommand.rb
CHANGED
@@ -83,14 +83,7 @@ module Beaker
|
|
83
83
|
|
84
84
|
@cli.parse_options
|
85
85
|
|
86
|
-
|
87
|
-
options_to_write = @cli.configured_options
|
88
|
-
# Remove keys we don't want to save
|
89
|
-
[:timestamp, :logger, :command_line, :beaker_version, :hosts_file].each do |key|
|
90
|
-
options_to_write.delete(key)
|
91
|
-
end
|
92
|
-
|
93
|
-
options_to_write = SubcommandUtil.sanitize_options_for_save(options_to_write)
|
86
|
+
options_to_write = SubcommandUtil.sanitize_options_for_save(@cli.configured_options)
|
94
87
|
|
95
88
|
@cli.logger.notify 'Writing configured options to disk'
|
96
89
|
File.open(SubcommandUtil::SUBCOMMAND_OPTIONS, 'w') do |f|
|
@@ -16,18 +16,33 @@ module Beaker
|
|
16
16
|
SUBCOMMAND_STATE = Pathname("#{CONFIG_DIR}/.subcommand_state.yaml")
|
17
17
|
PERSISTED_HOSTS = Pathname("#{CONFIG_DIR}/.hosts.yaml")
|
18
18
|
PERSISTED_HYPERVISORS = Pathname("#{CONFIG_DIR}/.hypervisors.yaml")
|
19
|
+
# These options should not be part of persisted subcommand state
|
20
|
+
UNPERSISTED_OPTIONS = [:beaker_version, :command_line, :hosts_file, :logger, :password_prompt, :timestamp]
|
19
21
|
|
20
22
|
def self.execute_subcommand?(arg0)
|
21
23
|
return false if arg0.nil?
|
22
24
|
(Beaker::Subcommand.instance_methods(false) << :help).include? arg0.to_sym
|
23
25
|
end
|
24
26
|
|
27
|
+
def self.prune_unpersisted(options)
|
28
|
+
UNPERSISTED_OPTIONS.each do |unpersisted_key|
|
29
|
+
options.each do |key, value|
|
30
|
+
if key == unpersisted_key
|
31
|
+
options.delete(key)
|
32
|
+
elsif value.is_a?(Hash)
|
33
|
+
options[key] = self.prune_unpersisted(value) unless value.empty?
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
options
|
38
|
+
end
|
39
|
+
|
25
40
|
def self.sanitize_options_for_save(options)
|
26
41
|
# God help us, the YAML library won't stop adding tags to objects, so this
|
27
42
|
# hack is a way to force the options into the basic object types so that
|
28
43
|
# an eventual YAML.dump or .to_yaml call doesn't add tags.
|
29
44
|
# Relevant stackoverflow: http://stackoverflow.com/questions/18178098/how-do-i-have-ruby-yaml-dump-a-hash-subclass-as-a-simple-hash
|
30
|
-
JSON.parse(options.to_json)
|
45
|
+
JSON.parse(prune_unpersisted(options).to_json)
|
31
46
|
end
|
32
47
|
|
33
48
|
# Print a message to the console and exit with specified exit code, defaults to 1
|
data/lib/beaker/version.rb
CHANGED
data/spec/beaker/command_spec.rb
CHANGED
@@ -32,6 +32,7 @@ module Beaker
|
|
32
32
|
@args = [ 'to', 'the', 'baz' ]
|
33
33
|
@options = { :foo => 'bar' }
|
34
34
|
allow( host ).to receive( :prepend_commands ).and_return( 'aloha!' )
|
35
|
+
allow( host ).to receive( :append_commands ).and_return( '' )
|
35
36
|
|
36
37
|
expect( cmd.cmd_line( host ) ).to be == "aloha! /usr/bin/blah --foo=bar to the baz"
|
37
38
|
end
|
@@ -41,6 +42,29 @@ module Beaker
|
|
41
42
|
@args = [ 'to', 'the', 'baz' ]
|
42
43
|
@options = { :foo => 'bar' }
|
43
44
|
allow( host ).to receive( :prepend_commands ).and_return( '' )
|
45
|
+
allow( host ).to receive( :append_commands ).and_return( '' )
|
46
|
+
|
47
|
+
expect( cmd.cmd_line( host ) ).to be == "/usr/bin/blah --foo=bar to the baz"
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
describe '#:append_commands' do
|
52
|
+
it 'can append commands' do
|
53
|
+
@command = '/usr/bin/blah'
|
54
|
+
@args = [ 'to', 'the', 'baz' ]
|
55
|
+
@options = { :foo => 'bar' }
|
56
|
+
allow( host ).to receive( :prepend_commands ).and_return( 'aloha!' )
|
57
|
+
allow( host ).to receive( :append_commands ).and_return( 'moo cow' )
|
58
|
+
|
59
|
+
expect( cmd.cmd_line( host ) ).to be == "aloha! /usr/bin/blah --foo=bar to the baz moo cow"
|
60
|
+
end
|
61
|
+
|
62
|
+
it 'can handle no append_cmds' do
|
63
|
+
@command = '/usr/bin/blah'
|
64
|
+
@args = [ 'to', 'the', 'baz' ]
|
65
|
+
@options = { :foo => 'bar' }
|
66
|
+
allow( host ).to receive( :prepend_commands ).and_return( '' )
|
67
|
+
allow( host ).to receive( :append_commands ).and_return( '' )
|
44
68
|
|
45
69
|
expect( cmd.cmd_line( host ) ).to be == "/usr/bin/blah --foo=bar to the baz"
|
46
70
|
end
|
@@ -91,6 +115,7 @@ module Beaker
|
|
91
115
|
h = Hash.new
|
92
116
|
allow( h ).to receive( :environment_string ).and_return( '' )
|
93
117
|
allow( h ).to receive( :prepend_commands ).and_return( '' )
|
118
|
+
allow( h ).to receive( :append_commands ).and_return( '' )
|
94
119
|
h
|
95
120
|
}
|
96
121
|
let(:platform) { @platform || 'unix' }
|
@@ -101,6 +101,71 @@ module Cisco
|
|
101
101
|
end
|
102
102
|
end
|
103
103
|
|
104
|
+
describe '#append_commands' do
|
105
|
+
|
106
|
+
context 'for cisco_nexus-7' do
|
107
|
+
|
108
|
+
before :each do
|
109
|
+
@platform = 'cisco_nexus-7-x86_64'
|
110
|
+
end
|
111
|
+
|
112
|
+
it 'appends `"` for commands' do
|
113
|
+
answer_correct = '"'
|
114
|
+
answer_test = host.append_commands( 'fake_command' )
|
115
|
+
expect( answer_test ).to be === answer_correct
|
116
|
+
end
|
117
|
+
|
118
|
+
it 'returns nil when vsh command' do
|
119
|
+
answer_correct = nil
|
120
|
+
answer_test = host.append_commands( '/isan/bin/vsh -c foo' )
|
121
|
+
expect( answer_test ).to be === answer_correct
|
122
|
+
end
|
123
|
+
|
124
|
+
it 'returns `"` when command contains vsh' do
|
125
|
+
answer_correct = '"'
|
126
|
+
answer_test = host.append_commands( 'fake_command -c foo vsh' )
|
127
|
+
expect( answer_test ).to be === answer_correct
|
128
|
+
end
|
129
|
+
|
130
|
+
it 'returns nil when ntpdate command' do
|
131
|
+
answer_correct = nil
|
132
|
+
answer_test = host.append_commands( 'fake/ntpdate/command foo' )
|
133
|
+
expect( answer_test ).to be === answer_correct
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
context 'for cisco_ios_xr-6' do
|
138
|
+
|
139
|
+
before :each do
|
140
|
+
@platform = 'cisco_ios_xr-6-x86_64'
|
141
|
+
end
|
142
|
+
|
143
|
+
it 'appends `"` for commands' do
|
144
|
+
answer_correct = '"'
|
145
|
+
answer_test = host.append_commands( 'fake_command' )
|
146
|
+
expect( answer_test ).to be === answer_correct
|
147
|
+
end
|
148
|
+
|
149
|
+
it 'returns nil when vsh command' do
|
150
|
+
answer_correct = nil
|
151
|
+
answer_test = host.append_commands( '/isan/bin/vsh -c foo' )
|
152
|
+
expect( answer_test ).to be === answer_correct
|
153
|
+
end
|
154
|
+
|
155
|
+
it 'returns `"` when command contains vsh' do
|
156
|
+
answer_correct = '"'
|
157
|
+
answer_test = host.append_commands( 'fake_command -c foo vsh' )
|
158
|
+
expect( answer_test ).to be === answer_correct
|
159
|
+
end
|
160
|
+
|
161
|
+
it 'returns nil when ntpdate command' do
|
162
|
+
answer_correct = nil
|
163
|
+
answer_test = host.append_commands( 'fake/ntpdate/command foo' )
|
164
|
+
expect( answer_test ).to be === answer_correct
|
165
|
+
end
|
166
|
+
end
|
167
|
+
end
|
168
|
+
|
104
169
|
describe '#environment_string' do
|
105
170
|
|
106
171
|
context 'for cisco_nexus-7' do
|
@@ -376,6 +376,8 @@ module Beaker
|
|
376
376
|
).and_return( cli_execute_return )
|
377
377
|
expect( BeakerHostGenerator::CLI ).to receive(
|
378
378
|
:new
|
379
|
+
).with(
|
380
|
+
[ 'notafile.yml' ]
|
379
381
|
).and_return( mock_beaker_hostgenerator_cli )
|
380
382
|
allow( Beaker::Options::HostsFileParser ).to receive(
|
381
383
|
:parse_hosts_string
|
@@ -383,6 +385,37 @@ module Beaker
|
|
383
385
|
parser.parse_hosts_options
|
384
386
|
end
|
385
387
|
|
388
|
+
it 'calls beaker-hostgenerator to get hosts information with a default hypervisor' do
|
389
|
+
old_beaker_hypervisor = ENV['BEAKER_HYPERVISOR']
|
390
|
+
begin
|
391
|
+
ENV['BEAKER_HYPERVISOR'] = 'docker'
|
392
|
+
|
393
|
+
parser.instance_variable_set( :@options, {
|
394
|
+
:hosts_file => 'notafile.yml'
|
395
|
+
} )
|
396
|
+
allow( Beaker::Options::HostsFileParser ).to receive(
|
397
|
+
:parse_hosts_file
|
398
|
+
).and_raise( Errno::ENOENT )
|
399
|
+
|
400
|
+
mock_beaker_hostgenerator_cli = Object.new
|
401
|
+
cli_execute_return = 'job150865'
|
402
|
+
expect( mock_beaker_hostgenerator_cli ).to receive(
|
403
|
+
:execute
|
404
|
+
).and_return( cli_execute_return )
|
405
|
+
expect( BeakerHostGenerator::CLI ).to receive(
|
406
|
+
:new
|
407
|
+
).with(
|
408
|
+
[ 'notafile.yml', '--hypervisor', 'docker' ]
|
409
|
+
).and_return( mock_beaker_hostgenerator_cli )
|
410
|
+
allow( Beaker::Options::HostsFileParser ).to receive(
|
411
|
+
:parse_hosts_string
|
412
|
+
).with( cli_execute_return )
|
413
|
+
parser.parse_hosts_options
|
414
|
+
ensure
|
415
|
+
ENV['BEAKER_HYPERVISOR'] = old_beaker_hypervisor
|
416
|
+
end
|
417
|
+
end
|
418
|
+
|
386
419
|
it 'sets the :hosts_file_generated flag to signal others when needed' do
|
387
420
|
options_test = {
|
388
421
|
:hosts_file => 'not_a_file.yml'
|
@@ -104,6 +104,42 @@ module Beaker
|
|
104
104
|
end
|
105
105
|
end
|
106
106
|
|
107
|
+
describe 'prune_unpersisted' do
|
108
|
+
let(:good_options) do
|
109
|
+
{ user: 'root', roles: ['agent'] }
|
110
|
+
end
|
111
|
+
|
112
|
+
let(:bad_options) do
|
113
|
+
{ logger: Beaker::Logger.new, timestamp: Time.now }
|
114
|
+
end
|
115
|
+
|
116
|
+
let(:initial_options) do
|
117
|
+
Beaker::Options::OptionsHash.new.merge(good_options.merge(bad_options))
|
118
|
+
end
|
119
|
+
|
120
|
+
it 'removes unwanted keys from an options hash' do
|
121
|
+
result = subject.prune_unpersisted(initial_options)
|
122
|
+
good_options.keys.each { |key| expect(result).to have_key(key) }
|
123
|
+
bad_options.keys.each { |key| expect(result).not_to have_key(key) }
|
124
|
+
end
|
125
|
+
|
126
|
+
it 'recurses to remove any nested unwanted keys' do
|
127
|
+
opts = initial_options.merge(child: initial_options.merge(child: initial_options))
|
128
|
+
result = subject.prune_unpersisted(opts)
|
129
|
+
|
130
|
+
good_options.keys.each do |key|
|
131
|
+
expect(result).to have_key(key)
|
132
|
+
expect(result[:child]).to have_key(key)
|
133
|
+
expect(result[:child][:child]).to have_key(key)
|
134
|
+
end
|
135
|
+
|
136
|
+
bad_options.keys.each do |key|
|
137
|
+
expect(result).not_to have_key(key)
|
138
|
+
expect(result[:child]).not_to have_key(key)
|
139
|
+
expect(result[:child][:child]).not_to have_key(key)
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|
107
143
|
end
|
108
144
|
end
|
109
145
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: beaker
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.
|
4
|
+
version: 4.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Puppet
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-11-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|