beaker 7.8.4 → 7.9.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 +14 -2
- data/README.md +1 -1
- data/acceptance/tests/base/dsl/helpers/host_helpers/upgrade_package_test.rb +13 -4
- data/acceptance/tests/base/dsl/structure_test.rb +5 -4
- data/acceptance/tests/base/host/host_test.rb +11 -2
- data/lib/beaker/dsl/helpers/host_helpers.rb +2 -1
- data/lib/beaker/host/pswindows/group.rb +3 -2
- data/lib/beaker/host/pswindows/user.rb +3 -2
- data/lib/beaker/host/windows/group.rb +4 -14
- data/lib/beaker/host/windows/user.rb +4 -14
- data/lib/beaker/local_connection.rb +4 -4
- data/lib/beaker/ssh_connection.rb +2 -0
- data/lib/beaker/version.rb +1 -1
- data/spec/beaker/dsl/helpers/host_helpers_spec.rb +1 -1
- data/spec/beaker/host/pswindows/group_spec.rb +21 -0
- data/spec/beaker/host/pswindows/user_spec.rb +10 -37
- data/spec/beaker/host/windows/group_spec.rb +4 -9
- data/spec/beaker/host/windows/user_spec.rb +10 -37
- data/spec/beaker/localhost_connection_spec.rb +19 -1
- data/spec/beaker/ssh_connection_spec.rb +34 -0
- metadata +2 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 707a66bcbdc5c52e9d4730e69ab81a95347d43e3b7d8239b81c40b237d9e6863
|
|
4
|
+
data.tar.gz: bc2d2f636ac6f02dc5b18e8bacdeaeded4912954b62b0b482b009e63255d40da
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 6804db468385f7ecca0337163c5871969346c4abdf3d8a0fa51bae0c712b52cc283bf3dc9bb893c8fadbb70cf8c332092795594ef3ac9f539253f8437b187f0d
|
|
7
|
+
data.tar.gz: b1bf4cc3aa3610a7b35cbe17fe6cf795f96086d9556471679ea33b428e9f3535626634b952410883f9a911bb79707e7145f88159685e1516addeebf28ac198b2
|
data/CHANGELOG.md
CHANGED
|
@@ -2,9 +2,21 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
|
|
5
|
-
## [7.
|
|
5
|
+
## [7.9.0](https://github.com/voxpupuli/beaker/tree/7.9.0) (2026-11-16)
|
|
6
6
|
|
|
7
|
-
[Full Changelog](https://github.com/voxpupuli/beaker/compare/v7.8.
|
|
7
|
+
[Full Changelog](https://github.com/voxpupuli/beaker/compare/v7.8.4...7.9.0)
|
|
8
|
+
|
|
9
|
+
**Implemented enhancements:**
|
|
10
|
+
|
|
11
|
+
- test\(acceptance\): support multi-platform hosts and current deps [\#2061](https://github.com/voxpupuli/beaker/pull/2061) ([alaunay](https://github.com/alaunay))
|
|
12
|
+
|
|
13
|
+
**Fixed bugs:**
|
|
14
|
+
|
|
15
|
+
- Various fixes for Windows and MacOS SUTs [\#2062](https://github.com/voxpupuli/beaker/pull/2062) ([nmburgan](https://github.com/nmburgan))
|
|
16
|
+
|
|
17
|
+
## [v7.8.4](https://github.com/voxpupuli/beaker/tree/v7.8.4) (2026-11-11)
|
|
18
|
+
|
|
19
|
+
[Full Changelog](https://github.com/voxpupuli/beaker/compare/v7.8.3...v7.8.4)
|
|
8
20
|
|
|
9
21
|
**Fixed bugs:**
|
|
10
22
|
|
data/README.md
CHANGED
|
@@ -61,7 +61,7 @@ This gem is licensed under the Apache-2 license.
|
|
|
61
61
|
## Release information
|
|
62
62
|
|
|
63
63
|
To make a new release, please do:
|
|
64
|
-
* update the version in the
|
|
64
|
+
* update the version in the `lib/beaker/version.rb` file
|
|
65
65
|
* Install gems with `bundle install --with release --path .vendor`
|
|
66
66
|
* generate the changelog with `bundle exec rake changelog`
|
|
67
67
|
* Check if the new version matches the closed issues/PRs in the changelog
|
|
@@ -31,7 +31,7 @@ test_name "dsl::helpers::host_helpers #upgrade_package" do
|
|
|
31
31
|
confine :except, :hypervisor => 'docker'
|
|
32
32
|
|
|
33
33
|
confine_block :to, :platform => /centos|el-\d/ do
|
|
34
|
-
step "#upgrade_package
|
|
34
|
+
step "#upgrade_package does not fail on CentOS if unknown package is specified" do
|
|
35
35
|
# NOTE: I would expect this to fail with an Beaker::Host::CommandFailure,
|
|
36
36
|
# but maybe it's because yum doesn't really care:
|
|
37
37
|
#
|
|
@@ -40,17 +40,26 @@ test_name "dsl::helpers::host_helpers #upgrade_package" do
|
|
|
40
40
|
# > Setting up Update Process
|
|
41
41
|
# > No package non-existent-package-name available.
|
|
42
42
|
# > No Packages marked for Update
|
|
43
|
+
#
|
|
44
|
+
# Newer dnf based systems (el-8+) exit 1 instead:
|
|
45
|
+
#
|
|
46
|
+
# > No match for argument: non-existent-package-name
|
|
47
|
+
# > Error: No packages marked for upgrade.
|
|
43
48
|
|
|
44
|
-
|
|
49
|
+
begin
|
|
50
|
+
result = upgrade_package hosts.first, "non-existent-package-name"
|
|
45
51
|
|
|
46
|
-
|
|
52
|
+
assert_match(/No Packages marked for Update/i, result)
|
|
53
|
+
rescue Beaker::Host::CommandFailure => e
|
|
54
|
+
assert_match(/No match for argument|No packages marked for upgrade/i, e.message)
|
|
55
|
+
end
|
|
47
56
|
end
|
|
48
57
|
end
|
|
49
58
|
|
|
50
59
|
confine_block :except, :platform => /centos|el-\d/ do
|
|
51
60
|
step "#upgrade_package fails if package is not already installed" do
|
|
52
61
|
assert_raises Beaker::Host::CommandFailure do
|
|
53
|
-
upgrade_package
|
|
62
|
+
upgrade_package hosts.first, "non-existent-package-name"
|
|
54
63
|
end
|
|
55
64
|
end
|
|
56
65
|
end
|
|
@@ -29,7 +29,7 @@ test_name "dsl::structure" do
|
|
|
29
29
|
step "#confine_block will not run specified block on non-matching hosts" do
|
|
30
30
|
begin
|
|
31
31
|
@in_confine = 0
|
|
32
|
-
confine_block :except, :platform =>
|
|
32
|
+
confine_block :except, :platform => hosts.map { |host| host['platform'] } do
|
|
33
33
|
@in_confine += 1
|
|
34
34
|
end
|
|
35
35
|
|
|
@@ -42,7 +42,7 @@ test_name "dsl::structure" do
|
|
|
42
42
|
step "#confine_block leaves hosts array intact after skipping block on non-matching hosts" do
|
|
43
43
|
begin
|
|
44
44
|
@in_confine = 0
|
|
45
|
-
confine_block :except, :platform =>
|
|
45
|
+
confine_block :except, :platform => hosts.map { |host| host['platform'] } do
|
|
46
46
|
@in_confine += 1
|
|
47
47
|
end
|
|
48
48
|
|
|
@@ -79,11 +79,12 @@ test_name "dsl::structure" do
|
|
|
79
79
|
|
|
80
80
|
step "#confine reports correct message and skips test when criteria doesn't match on 'except'" do
|
|
81
81
|
begin
|
|
82
|
-
|
|
82
|
+
criteria = { :platform => hosts.map { |host| host['platform'] } }
|
|
83
|
+
confine :except, criteria
|
|
83
84
|
|
|
84
85
|
fail "#confine did not skip test but should have."
|
|
85
86
|
rescue Beaker::DSL::Outcomes::SkipTest => e
|
|
86
|
-
assert_match(/No suitable hosts found without {(:platform=>|platform: )
|
|
87
|
+
assert_match(/No suitable hosts found without {(:platform=>|platform: )/, e.message, "#confine raised an unexpected
|
|
87
88
|
# skip_test")
|
|
88
89
|
end
|
|
89
90
|
end
|
|
@@ -317,8 +317,12 @@ step "Ensure scp errors close the ssh connection" do
|
|
|
317
317
|
# indirectly called by beaker's own SshConnection #close mehod. View
|
|
318
318
|
# the source for further info:
|
|
319
319
|
# https://github.com/net-ssh/net-sacp/blob/master/lib/net/scp.rb
|
|
320
|
-
|
|
320
|
+
# net-scp 4 no longer raises from #close, so accept both behaviors.
|
|
321
|
+
# The next step checks the connection is still usable.
|
|
322
|
+
begin
|
|
321
323
|
create_remote_file(default, '/tmp/this/path/cannot/possibly/exist.txt', "contents")
|
|
324
|
+
rescue Net::SCP::Error
|
|
325
|
+
nil
|
|
322
326
|
end
|
|
323
327
|
end
|
|
324
328
|
|
|
@@ -332,8 +336,13 @@ step "Ensure scp errors close the ssh connection" do
|
|
|
332
336
|
# use the Dir.mkdir method in the #download_start_state method.
|
|
333
337
|
# See the source for further info:
|
|
334
338
|
# https://github.com/net-ssh/net-sacp/blob/master/lib/net/scp/download.rb
|
|
335
|
-
|
|
339
|
+
#
|
|
340
|
+
# net-scp 4 no longer raises here, so accept both behaviors.
|
|
341
|
+
# The next step checks the connection is still usable.
|
|
342
|
+
begin
|
|
336
343
|
scp_from default, '/tmp/path/dne/wtf/bbq', '/tmp/path/dne/wtf/bbq'
|
|
344
|
+
rescue Errno::ENOENT
|
|
345
|
+
nil
|
|
337
346
|
end
|
|
338
347
|
end
|
|
339
348
|
|
|
@@ -261,7 +261,8 @@ module Beaker
|
|
|
261
261
|
# @return [Result] Returns the result of the underlying SCP operation.
|
|
262
262
|
def create_remote_file(hosts, file_path, file_content, opts = {})
|
|
263
263
|
Tempfile.open 'beaker' do |tempfile|
|
|
264
|
-
|
|
264
|
+
# Binary mode, so that Ruby on Windows doesn't turn line endings into CRLF
|
|
265
|
+
File.open(tempfile.path, 'wb') { |file| file.puts file_content }
|
|
265
266
|
|
|
266
267
|
opts[:protocol] ||= 'scp'
|
|
267
268
|
case opts[:protocol]
|
|
@@ -2,10 +2,11 @@ module PSWindows::Group
|
|
|
2
2
|
include Beaker::CommandFactory
|
|
3
3
|
|
|
4
4
|
def group_list
|
|
5
|
-
execute('cmd /c echo "" |
|
|
5
|
+
execute('cmd /c echo "" | powershell.exe "Get-LocalGroup | Select-Object -ExpandProperty Name"') do |result|
|
|
6
6
|
groups = []
|
|
7
7
|
result.stdout.each_line do |line|
|
|
8
|
-
|
|
8
|
+
name = line.strip
|
|
9
|
+
groups << name unless name.empty?
|
|
9
10
|
end
|
|
10
11
|
|
|
11
12
|
yield result if block_given?
|
|
@@ -2,10 +2,11 @@ module PSWindows::User
|
|
|
2
2
|
include Beaker::CommandFactory
|
|
3
3
|
|
|
4
4
|
def user_list
|
|
5
|
-
execute('cmd /c echo "" |
|
|
5
|
+
execute('cmd /c echo "" | powershell.exe "Get-LocalUser | Select-Object -ExpandProperty Name"') do |result|
|
|
6
6
|
users = []
|
|
7
7
|
result.stdout.each_line do |line|
|
|
8
|
-
|
|
8
|
+
name = line.strip
|
|
9
|
+
users << name unless name.empty?
|
|
9
10
|
end
|
|
10
11
|
|
|
11
12
|
yield result if block_given?
|
|
@@ -1,25 +1,13 @@
|
|
|
1
1
|
module Windows::Group
|
|
2
2
|
include Beaker::CommandFactory
|
|
3
3
|
|
|
4
|
-
def group_list
|
|
5
|
-
execute('cmd /c echo "" | wmic group where localaccount="true" get name /format:value') do |result|
|
|
6
|
-
groups = []
|
|
7
|
-
result.stdout.each_line do |line|
|
|
8
|
-
groups << (line.match(/^Name=(.+)$/) or next)[1]
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
yield result if block_given?
|
|
12
|
-
|
|
13
|
-
groups
|
|
14
|
-
end
|
|
15
|
-
end
|
|
16
|
-
|
|
17
4
|
# using powershell commands as wmic is deprecated in windows 2025
|
|
18
5
|
def group_list_using_powershell
|
|
19
6
|
execute('cmd /c echo "" | powershell.exe "Get-LocalGroup | Select-Object -ExpandProperty Name"') do |result|
|
|
20
7
|
groups = []
|
|
21
8
|
result.stdout.each_line do |line|
|
|
22
|
-
|
|
9
|
+
name = line.strip
|
|
10
|
+
groups << name unless name.empty?
|
|
23
11
|
end
|
|
24
12
|
|
|
25
13
|
yield result if block_given?
|
|
@@ -28,6 +16,8 @@ module Windows::Group
|
|
|
28
16
|
end
|
|
29
17
|
end
|
|
30
18
|
|
|
19
|
+
alias group_list group_list_using_powershell
|
|
20
|
+
|
|
31
21
|
def group_get(name)
|
|
32
22
|
execute("net localgroup \"#{name}\"") do |result|
|
|
33
23
|
fail_test "failed to get group #{name}" if result.exit_code != 0
|
|
@@ -1,25 +1,13 @@
|
|
|
1
1
|
module Windows::User
|
|
2
2
|
include Beaker::CommandFactory
|
|
3
3
|
|
|
4
|
-
def user_list
|
|
5
|
-
execute('cmd /c echo "" | wmic useraccount where localaccount="true" get name /format:value') do |result|
|
|
6
|
-
users = []
|
|
7
|
-
result.stdout.each_line do |line|
|
|
8
|
-
users << (line.match(/^Name=(.+)/) or next)[1]
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
yield result if block_given?
|
|
12
|
-
|
|
13
|
-
users
|
|
14
|
-
end
|
|
15
|
-
end
|
|
16
|
-
|
|
17
4
|
# using powershell commands as wmic is deprecated in windows 2025
|
|
18
5
|
def user_list_using_powershell
|
|
19
6
|
execute('cmd /c echo "" | powershell.exe "Get-LocalUser | Select-Object -ExpandProperty Name"') do |result|
|
|
20
7
|
users = []
|
|
21
8
|
result.stdout.each_line do |line|
|
|
22
|
-
|
|
9
|
+
name = line.strip
|
|
10
|
+
users << name unless name.empty?
|
|
23
11
|
end
|
|
24
12
|
|
|
25
13
|
yield result if block_given?
|
|
@@ -28,6 +16,8 @@ module Windows::User
|
|
|
28
16
|
end
|
|
29
17
|
end
|
|
30
18
|
|
|
19
|
+
alias user_list user_list_using_powershell
|
|
20
|
+
|
|
31
21
|
def user_get(name)
|
|
32
22
|
execute("net user \"#{name}\"") do |result|
|
|
33
23
|
fail_test "failed to get user #{name}" if result.exit_code != 0
|
|
@@ -34,13 +34,13 @@ module Beaker
|
|
|
34
34
|
ENV.replace(backup)
|
|
35
35
|
end
|
|
36
36
|
|
|
37
|
-
def execute command,
|
|
37
|
+
def execute command, options = {}, stdout_callback = nil, _stderr_callback = stdout_callback
|
|
38
38
|
result = Result.new(@hostname, command)
|
|
39
39
|
envs = {}
|
|
40
40
|
if File.readable?(@ssh_env_file)
|
|
41
41
|
File.foreach(@ssh_env_file) do |line|
|
|
42
|
-
key, value = line.split('=')
|
|
43
|
-
envs[key] = value
|
|
42
|
+
key, value = line.chomp.split('=', 2)
|
|
43
|
+
envs[key] = value if value
|
|
44
44
|
end
|
|
45
45
|
end
|
|
46
46
|
|
|
@@ -48,7 +48,7 @@ module Beaker
|
|
|
48
48
|
clean_env = ENV.reject { |k| /^BUNDLE|^RUBY|^GEM/.match?(k) }
|
|
49
49
|
|
|
50
50
|
with_env(clean_env) do
|
|
51
|
-
std_out, std_err, status = Open3.capture3(envs, command)
|
|
51
|
+
std_out, std_err, status = Open3.capture3(envs, command, stdin_data: options[:stdin].to_s)
|
|
52
52
|
result.stdout << std_out
|
|
53
53
|
result.stderr << std_err
|
|
54
54
|
result.exit_code = status.exitstatus
|
|
@@ -290,6 +290,7 @@ module Beaker
|
|
|
290
290
|
end
|
|
291
291
|
|
|
292
292
|
def scp_to source, target, options = {}
|
|
293
|
+
connect
|
|
293
294
|
local_opts = options.dup
|
|
294
295
|
local_opts[:recursive] = File.directory?(source) if local_opts[:recursive].nil?
|
|
295
296
|
local_opts[:chunk_size] ||= 16384
|
|
@@ -322,6 +323,7 @@ module Beaker
|
|
|
322
323
|
end
|
|
323
324
|
|
|
324
325
|
def scp_from source, target, options = {}
|
|
326
|
+
connect
|
|
325
327
|
local_opts = options.dup
|
|
326
328
|
local_opts[:recursive] = true if local_opts[:recursive].nil?
|
|
327
329
|
local_opts[:chunk_size] ||= 16384
|
data/lib/beaker/version.rb
CHANGED
|
@@ -320,7 +320,7 @@ describe ClassMixedWithDSLHelpers do
|
|
|
320
320
|
|
|
321
321
|
expect(Tempfile).to receive(:open).and_yield(tmpfile)
|
|
322
322
|
|
|
323
|
-
expect(File).to receive(:open)
|
|
323
|
+
expect(File).to receive(:open).with('/local/path/to/blah', 'wb')
|
|
324
324
|
|
|
325
325
|
expect(subject).to receive(:scp_to)
|
|
326
326
|
.with(hosts, '/local/path/to/blah', '/remote/path', my_opts)
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
module Beaker
|
|
4
|
+
describe PSWindows::Group do
|
|
5
|
+
let(:instance) { Class.new { include PSWindows::Group }.new }
|
|
6
|
+
let(:command) { 'cmd /c echo "" | powershell.exe "Get-LocalGroup | Select-Object -ExpandProperty Name"' }
|
|
7
|
+
let(:result) { Beaker::Result.new(double.as_null_object, command) }
|
|
8
|
+
|
|
9
|
+
describe '#group_list' do
|
|
10
|
+
it 'returns the group names without blank lines' do
|
|
11
|
+
result.stdout = <<~OUTPUT
|
|
12
|
+
Administrators
|
|
13
|
+
With Spaces
|
|
14
|
+
|
|
15
|
+
OUTPUT
|
|
16
|
+
expect(instance).to receive(:execute).with(command).and_yield(result)
|
|
17
|
+
expect(instance.group_list).to eq(['Administrators', 'With Spaces'])
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
@@ -5,59 +5,32 @@ class PSWindowsUserTest
|
|
|
5
5
|
end
|
|
6
6
|
|
|
7
7
|
describe PSWindowsUserTest do
|
|
8
|
-
let(:
|
|
8
|
+
let(:powershell_output) do
|
|
9
9
|
<<~EOS
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
Name=bob foo
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
Name=bob-dash
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
Name=bob.foo
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
Name=cyg_server
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
10
|
+
Administrator
|
|
11
|
+
bob foo
|
|
12
|
+
bob-dash
|
|
13
|
+
bob.foo
|
|
14
|
+
cyg_server
|
|
42
15
|
|
|
43
16
|
EOS
|
|
44
17
|
end
|
|
45
|
-
let(:command) { 'cmd /c echo "" |
|
|
18
|
+
let(:command) { 'cmd /c echo "" | powershell.exe "Get-LocalUser | Select-Object -ExpandProperty Name"' }
|
|
46
19
|
let(:host) { double.as_null_object }
|
|
47
20
|
let(:result) { Beaker::Result.new(host, command) }
|
|
48
21
|
|
|
49
22
|
describe '#user_list' do
|
|
50
23
|
it 'returns user names list correctly' do
|
|
51
|
-
result.stdout =
|
|
24
|
+
result.stdout = powershell_output
|
|
52
25
|
expect(subject).to receive(:execute).with(command).and_yield(result)
|
|
53
26
|
expect(subject.user_list).to be === ['Administrator', 'bob foo', 'bob-dash', 'bob.foo', 'cyg_server']
|
|
54
27
|
end
|
|
55
28
|
|
|
56
29
|
it 'yields correctly with the result object' do
|
|
57
|
-
result.stdout =
|
|
30
|
+
result.stdout = powershell_output
|
|
58
31
|
expect(subject).to receive(:execute).and_yield(result)
|
|
59
32
|
subject.user_list do |result|
|
|
60
|
-
expect(result.stdout).to be ===
|
|
33
|
+
expect(result.stdout).to be === powershell_output
|
|
61
34
|
end
|
|
62
35
|
end
|
|
63
36
|
end
|
|
@@ -12,25 +12,20 @@ module Beaker
|
|
|
12
12
|
let(:result) { double(:result, :stdout => group_list_output) }
|
|
13
13
|
let(:group_list_output) do
|
|
14
14
|
<<~EOS
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
Name=Bar6
|
|
19
|
-
|
|
15
|
+
Foo
|
|
16
|
+
Bar6
|
|
20
17
|
|
|
21
18
|
EOS
|
|
22
19
|
end
|
|
23
20
|
|
|
24
21
|
def add_group(group_name)
|
|
25
22
|
group_list_output << <<~EOS
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
23
|
+
#{group_name}
|
|
29
24
|
EOS
|
|
30
25
|
end
|
|
31
26
|
|
|
32
27
|
before do
|
|
33
|
-
expect(instance).to receive(:execute).with(/
|
|
28
|
+
expect(instance).to receive(:execute).with(/powershell.exe "Get-LocalGroup/).and_yield(result)
|
|
34
29
|
end
|
|
35
30
|
|
|
36
31
|
it "gets a group_list" do
|
|
@@ -9,57 +9,30 @@ describe WindowsUserTest do
|
|
|
9
9
|
let(:result) { Beaker::Result.new(host, command) }
|
|
10
10
|
|
|
11
11
|
describe '#user_list' do
|
|
12
|
-
let(:command) { 'cmd /c echo "" |
|
|
12
|
+
let(:command) { 'cmd /c echo "" | powershell.exe "Get-LocalUser | Select-Object -ExpandProperty Name"' }
|
|
13
13
|
|
|
14
|
-
let(:
|
|
14
|
+
let(:powershell_output) do
|
|
15
15
|
<<~EOS
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
Name=bob foo
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
Name=bob-dash
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
Name=bob.foo
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
Name=cyg_server
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
16
|
+
Administrator
|
|
17
|
+
bob foo
|
|
18
|
+
bob-dash
|
|
19
|
+
bob.foo
|
|
20
|
+
cyg_server
|
|
48
21
|
|
|
49
22
|
EOS
|
|
50
23
|
end
|
|
51
24
|
|
|
52
25
|
it 'returns user names list correctly' do
|
|
53
|
-
result.stdout =
|
|
26
|
+
result.stdout = powershell_output
|
|
54
27
|
expect(subject).to receive(:execute).with(command).and_yield(result)
|
|
55
28
|
expect(subject.user_list).to be === ['Administrator', 'bob foo', 'bob-dash', 'bob.foo', 'cyg_server']
|
|
56
29
|
end
|
|
57
30
|
|
|
58
31
|
it 'yields correctly with the result object' do
|
|
59
|
-
result.stdout =
|
|
32
|
+
result.stdout = powershell_output
|
|
60
33
|
expect(subject).to receive(:execute).and_yield(result)
|
|
61
34
|
subject.user_list do |result|
|
|
62
|
-
expect(result.stdout).to be ===
|
|
35
|
+
expect(result.stdout).to be === powershell_output
|
|
63
36
|
end
|
|
64
37
|
end
|
|
65
38
|
end
|
|
@@ -38,11 +38,29 @@ module Beaker
|
|
|
38
38
|
|
|
39
39
|
describe '#execute' do
|
|
40
40
|
it 'calls open3' do
|
|
41
|
-
expect(Open3).to receive(:capture3).with({}, 'my_command')
|
|
41
|
+
expect(Open3).to receive(:capture3).with({}, 'my_command', stdin_data: '')
|
|
42
42
|
connection.connect
|
|
43
43
|
expect(connection.execute('my_command')).to be_a Result
|
|
44
44
|
end
|
|
45
45
|
|
|
46
|
+
it 'passes the stdin option to the command' do
|
|
47
|
+
connection.connect
|
|
48
|
+
result = connection.execute('cat', stdin: 'some input')
|
|
49
|
+
expect(result.stdout).to eq('some input')
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
context 'with an ssh env file' do
|
|
53
|
+
let(:env_file) { Tempfile.new('ssh_env') }
|
|
54
|
+
let(:options) { { :logger => double('logger').as_null_object, :ssh_env_file => env_file.path } }
|
|
55
|
+
|
|
56
|
+
it 'passes its variables to the command' do
|
|
57
|
+
env_file.write("MY_VAR=a=b\n\nOTHER=c\nOTHER\n")
|
|
58
|
+
env_file.flush
|
|
59
|
+
connection.connect
|
|
60
|
+
expect(connection.execute('printf "$MY_VAR $OTHER"').stdout).to eq('a=b c')
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
|
|
46
64
|
it 'sets stdout, stderr and exitcode' do
|
|
47
65
|
allow(Open3).to receive(:capture3).and_return(['stdout', 'stderr', double({ exitstatus: 0 })])
|
|
48
66
|
connection.connect
|
|
@@ -237,6 +237,23 @@ module Beaker
|
|
|
237
237
|
it 'returns a result object' do
|
|
238
238
|
expect(connection.scp_to '', '').to be_a Beaker::Result
|
|
239
239
|
end
|
|
240
|
+
|
|
241
|
+
it 'reconnects when the connection was closed' do
|
|
242
|
+
allow(@mock_ssh).to receive(:closed?).and_return(false)
|
|
243
|
+
allow(@mock_ssh).to receive(:close)
|
|
244
|
+
connection.close
|
|
245
|
+
expect(Net::SSH).to receive(:start).with(ip, user, ssh_opts) { @mock_ssh }
|
|
246
|
+
expect(@mock_scp).to receive(:upload!).once
|
|
247
|
+
connection.scp_to '', ''
|
|
248
|
+
end
|
|
249
|
+
|
|
250
|
+
it 'raises when it cannot reconnect' do
|
|
251
|
+
allow(@mock_ssh).to receive(:closed?).and_return(false)
|
|
252
|
+
allow(@mock_ssh).to receive(:close)
|
|
253
|
+
connection.close
|
|
254
|
+
allow(Net::SSH).to receive(:start).and_return(nil)
|
|
255
|
+
expect { connection.scp_to '', '' }.to raise_error(RuntimeError, /Cannot connect/)
|
|
256
|
+
end
|
|
240
257
|
end
|
|
241
258
|
|
|
242
259
|
describe '#scp_from' do
|
|
@@ -263,6 +280,23 @@ module Beaker
|
|
|
263
280
|
it 'returns a result object' do
|
|
264
281
|
expect(connection.scp_from '', '').to be_a Beaker::Result
|
|
265
282
|
end
|
|
283
|
+
|
|
284
|
+
it 'reconnects when the connection was closed' do
|
|
285
|
+
allow(@mock_ssh).to receive(:closed?).and_return(false)
|
|
286
|
+
allow(@mock_ssh).to receive(:close)
|
|
287
|
+
connection.close
|
|
288
|
+
expect(Net::SSH).to receive(:start).with(ip, user, ssh_opts) { @mock_ssh }
|
|
289
|
+
expect(@mock_scp).to receive(:download!).once
|
|
290
|
+
connection.scp_from '', ''
|
|
291
|
+
end
|
|
292
|
+
|
|
293
|
+
it 'raises when it cannot reconnect' do
|
|
294
|
+
allow(@mock_ssh).to receive(:closed?).and_return(false)
|
|
295
|
+
allow(@mock_ssh).to receive(:close)
|
|
296
|
+
connection.close
|
|
297
|
+
allow(Net::SSH).to receive(:start).and_return(nil)
|
|
298
|
+
expect { connection.scp_from '', '' }.to raise_error(RuntimeError, /Cannot connect/)
|
|
299
|
+
end
|
|
266
300
|
end
|
|
267
301
|
end
|
|
268
302
|
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: beaker
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 7.
|
|
4
|
+
version: 7.9.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Puppet
|
|
@@ -688,6 +688,7 @@ files:
|
|
|
688
688
|
- spec/beaker/host/mac/user_spec.rb
|
|
689
689
|
- spec/beaker/host/pswindows/exec_spec.rb
|
|
690
690
|
- spec/beaker/host/pswindows/file_spec.rb
|
|
691
|
+
- spec/beaker/host/pswindows/group_spec.rb
|
|
691
692
|
- spec/beaker/host/pswindows/user_spec.rb
|
|
692
693
|
- spec/beaker/host/pswindows_spec.rb
|
|
693
694
|
- spec/beaker/host/unix/exec_spec.rb
|