beaker 3.21.0 → 3.21.1
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 +8 -8
- data/lib/beaker/host.rb +1 -1
- data/lib/beaker/hypervisor.rb +1 -24
- data/lib/beaker/ssh_connection.rb +15 -8
- data/lib/beaker/version.rb +1 -1
- data/spec/beaker/hypervisor/hypervisor_spec.rb +4 -25
- data/spec/beaker/ssh_connection_spec.rb +19 -18
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
NTU2YTkyMzA2NzA5NmZhMzNjNDY1ODc1YjhiZTQ5NzdhZDM1OTlmNA==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
OTRiN2MxOGUxNGQ2N2UwMDhjYjQyNTBkMzY3YjA5Mjc0Mzk0MGUxMA==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
OTRkYmJlYTViOTgyNTY1Mjk0NjQ1ODM0NDJhZjkyNDc2ZGM2M2RlNzg2NDJj
|
10
|
+
MGE3MDIxYzFkMjgzYjZjMzc4NzU0M2Y0MjdjOTAyNmFkYmIyMWU0Yjg4MmY3
|
11
|
+
OGNmOTUyMTZhY2MwMGI4OWFlZTAxZTdkOTU1MDZjOGEyMzJkODc=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
NGJmNDJiOTAwNzFjYmU3Y2VhYmZiMGJiMmMxODVmNDA1Yzg3ZTY5YTg2MWM2
|
14
|
+
YjIxMzhkYzliNjc2MTA5M2VmMjVjZmQ0ODhkNTU3MGEzMjcxODZjODhjZWI4
|
15
|
+
YWRlYjE4NjgyNmUxNjkwNDlkNTRjMDlhNWE3ZTUxNGM1ODY2YjE=
|
data/lib/beaker/host.rb
CHANGED
@@ -276,7 +276,7 @@ module Beaker
|
|
276
276
|
# create new connection object if necessary
|
277
277
|
@connection ||= SshConnection.connect( { :ip => self['ip'], :vmhostname => self['vmhostname'], :hostname => @name },
|
278
278
|
self['user'],
|
279
|
-
self['ssh'], { :logger => @logger
|
279
|
+
self['ssh'], { :logger => @logger } )
|
280
280
|
# update connection information
|
281
281
|
if self['ip'] && (@connection.ip != self['ip'])
|
282
282
|
@connection.ip = self['ip']
|
data/lib/beaker/hypervisor.rb
CHANGED
@@ -45,8 +45,8 @@ module Beaker
|
|
45
45
|
end
|
46
46
|
|
47
47
|
hypervisor = hyper_class.new(hosts_to_provision, options)
|
48
|
-
self.set_ssh_connection_preference(hosts_to_provision, hypervisor)
|
49
48
|
hypervisor.provision if options[:provision]
|
49
|
+
|
50
50
|
hypervisor
|
51
51
|
end
|
52
52
|
|
@@ -65,29 +65,6 @@ module Beaker
|
|
65
65
|
nil
|
66
66
|
end
|
67
67
|
|
68
|
-
DEFAULT_CONNECTION_PREFERENCE = ['ip', 'vmhostname', 'hostname']
|
69
|
-
#SSH connection method preference. Can be overwritten by hypervisor to change the order
|
70
|
-
def connection_preference
|
71
|
-
DEFAULT_CONNECTION_PREFERENCE
|
72
|
-
end
|
73
|
-
|
74
|
-
#Check if overriding method returns correct array with ip, vmhostname hostname as elements
|
75
|
-
def self.set_ssh_connection_preference(hosts_to_provision, hypervisor)
|
76
|
-
if hypervisor.connection_preference.sort == DEFAULT_CONNECTION_PREFERENCE.sort
|
77
|
-
hosts_to_provision.each{ |h| h[:ssh_connection_preference] = hypervisor.connection_preference}
|
78
|
-
else
|
79
|
-
raise ArgumentError, <<-HEREDOC
|
80
|
-
Hypervisor's overriding connection_pereference method is not matching the API.
|
81
|
-
|
82
|
-
Make sure your hypervisor's connection_preference returns an array
|
83
|
-
containing the following elements in any order you prefer:
|
84
|
-
"ip", "hostname", "vmhostname"
|
85
|
-
|
86
|
-
Please check hypervisor.rb file's "self.connection_preference" method for an example
|
87
|
-
HEREDOC
|
88
|
-
end
|
89
|
-
end
|
90
|
-
|
91
68
|
#Proxy package managers on tests hosts created by this hypervisor, runs before validation and configuration.
|
92
69
|
def proxy_package_manager
|
93
70
|
if @options[:package_proxy]
|
@@ -6,7 +6,7 @@ module Beaker
|
|
6
6
|
class SshConnection
|
7
7
|
|
8
8
|
attr_accessor :logger
|
9
|
-
attr_accessor :ip, :vmhostname, :hostname
|
9
|
+
attr_accessor :ip, :vmhostname, :hostname
|
10
10
|
|
11
11
|
RETRYABLE_EXCEPTIONS = [
|
12
12
|
SocketError,
|
@@ -33,7 +33,6 @@ module Beaker
|
|
33
33
|
@ssh_opts = ssh_opts
|
34
34
|
@logger = options[:logger]
|
35
35
|
@options = options
|
36
|
-
@ssh_connection_preference = @options[:ssh_connection_preference]
|
37
36
|
end
|
38
37
|
|
39
38
|
def self.connect name_hash, user = 'root', ssh_opts = {}, options = {}
|
@@ -67,13 +66,21 @@ module Beaker
|
|
67
66
|
# connect to the host
|
68
67
|
def connect
|
69
68
|
#try three ways to connect to host (vmhostname, ip, hostname)
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
69
|
+
methods = []
|
70
|
+
if @vmhostname
|
71
|
+
@ssh ||= connect_block(@vmhostname, @user, @ssh_opts)
|
72
|
+
methods << "vmhostname (#{@vmhostname})"
|
74
73
|
end
|
75
|
-
|
76
|
-
@
|
74
|
+
if @ip && !@ssh
|
75
|
+
@ssh ||= connect_block(@ip, @user, @ssh_opts)
|
76
|
+
methods << "ip (#{@ip})"
|
77
|
+
end
|
78
|
+
if @hostname && !@ssh
|
79
|
+
@ssh ||= connect_block(@hostname, @user, @ssh_opts)
|
80
|
+
methods << "hostname (#{@hostname})"
|
81
|
+
end
|
82
|
+
if not @ssh
|
83
|
+
@logger.error "Failed to connect to #{@hostname}, attempted #{methods.join(', ')}"
|
77
84
|
raise RuntimeError, "Cannot connect to #{@hostname}"
|
78
85
|
end
|
79
86
|
@ssh
|
data/lib/beaker/version.rb
CHANGED
@@ -2,36 +2,15 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
module Beaker
|
4
4
|
describe Hypervisor do
|
5
|
-
let( :
|
6
|
-
|
7
|
-
context "#create" do
|
8
|
-
let( :hypervisor ) { Beaker::Hypervisor }
|
9
|
-
|
10
|
-
it "includes custom hypervisor and call set_ssh_connection_preference" do
|
11
|
-
allow(hypervisor).to receive(:set_ssh_connection_preference).with([], hypervisor)
|
12
|
-
expect{ hypervisor.create('custom_hypervisor', [], make_opts() )}.to raise_error(RuntimeError, "Invalid hypervisor: custom_hypervisor")
|
13
|
-
end
|
14
|
-
|
15
|
-
it "sets ssh connection preference if connection_preference method is not overwritten" do
|
16
|
-
hypervisor.create('none', hosts, make_opts())
|
17
|
-
expect(hosts[0][:ssh_connection_preference]).to eq(['ip', 'vmhostname', 'hostname'])
|
18
|
-
end
|
19
|
-
|
20
|
-
it "tests ssh connection methods array for valid elements" do
|
21
|
-
allow(hypervisor).to receive(:connection_preference).and_return(['my', 'invalid', 'method_name'])
|
22
|
-
expect{ hypervisor.set_ssh_connection_preference(hosts, hypervisor)}.to raise_error(ArgumentError, /overriding/)
|
23
|
-
end
|
24
|
-
|
25
|
-
it "sets to new preference if connection_preference is overridden" do
|
26
|
-
allow(hypervisor).to receive(:connection_preference).and_return(['vmhostname', 'hostname', 'ip'])
|
27
|
-
hypervisor.set_ssh_connection_preference(hosts, hypervisor)
|
28
|
-
expect(hosts[0][:ssh_connection_preference]).to eq(['vmhostname', 'hostname', 'ip'])
|
29
|
-
end
|
5
|
+
let( :hypervisor ) { Beaker::Hypervisor }
|
30
6
|
|
7
|
+
it "includes custom hypervisor" do
|
8
|
+
expect{ hypervisor.create('custom_hypervisor', [], make_opts() )}.to raise_error(RuntimeError, "Invalid hypervisor: custom_hypervisor")
|
31
9
|
end
|
32
10
|
|
33
11
|
context "#configure" do
|
34
12
|
let( :options ) { make_opts.merge({ 'logger' => double().as_null_object }) }
|
13
|
+
let( :hosts ) { make_hosts( { :platform => 'el-5' } ) }
|
35
14
|
let( :hypervisor ) { Beaker::Hypervisor.new( hosts, options ) }
|
36
15
|
|
37
16
|
context 'if :timesync option set true on host' do
|
@@ -5,7 +5,7 @@ module Beaker
|
|
5
5
|
describe SshConnection do
|
6
6
|
let( :user ) { 'root' }
|
7
7
|
let( :ssh_opts ) { { keepalive: true, keepalive_interval: 2 } }
|
8
|
-
let( :options ) { { :logger => double('logger').as_null_object
|
8
|
+
let( :options ) { { :logger => double('logger').as_null_object } }
|
9
9
|
let( :ip ) { "default.ip.address" }
|
10
10
|
let( :vmhostname ){ "vmhostname" }
|
11
11
|
let( :hostname) { "my_host" }
|
@@ -18,24 +18,25 @@ module Beaker
|
|
18
18
|
|
19
19
|
it 'self.connect creates connects and returns a proxy for that connection' do
|
20
20
|
# grrr
|
21
|
-
expect( Net::SSH ).to receive(:start).with(
|
21
|
+
expect( Net::SSH ).to receive(:start).with( vmhostname, user, ssh_opts ).and_return(true)
|
22
22
|
connection_constructor = SshConnection.connect name_hash, user, ssh_opts, options
|
23
23
|
expect( connection_constructor ).to be_a_kind_of SshConnection
|
24
24
|
end
|
25
25
|
|
26
26
|
it 'connect creates a new connection' do
|
27
|
-
expect( Net::SSH ).to receive( :start ).with(
|
27
|
+
expect( Net::SSH ).to receive( :start ).with( vmhostname, user, ssh_opts).and_return(true)
|
28
28
|
connection.connect
|
29
29
|
end
|
30
30
|
|
31
31
|
it 'connect caches its connection' do
|
32
|
-
expect( Net::SSH ).to receive( :start ).with(
|
32
|
+
expect( Net::SSH ).to receive( :start ).with( vmhostname, user, ssh_opts ).once.and_return true
|
33
|
+
connection.connect
|
33
34
|
connection.connect
|
34
35
|
end
|
35
36
|
|
36
|
-
it 'attempts to connect by
|
37
|
-
expect( Net::SSH ).to receive( :start ).with(
|
38
|
-
expect( Net::SSH ).to receive( :start ).with(
|
37
|
+
it 'attempts to connect by ip address if vmhostname connection fails' do
|
38
|
+
expect( Net::SSH ).to receive( :start ).with( vmhostname, user, ssh_opts).and_return(false)
|
39
|
+
expect( Net::SSH ).to receive( :start ).with( ip, user, ssh_opts).and_return(true).once
|
39
40
|
expect( Net::SSH ).to receive( :start ).with( hostname, user, ssh_opts).never
|
40
41
|
connection.connect
|
41
42
|
end
|
@@ -52,7 +53,7 @@ module Beaker
|
|
52
53
|
|
53
54
|
it 'runs ssh close' do
|
54
55
|
mock_ssh = Object.new
|
55
|
-
expect( Net::SSH ).to receive( :start ).with(
|
56
|
+
expect( Net::SSH ).to receive( :start ).with( vmhostname, user, ssh_opts) { mock_ssh }
|
56
57
|
connection.connect
|
57
58
|
|
58
59
|
allow( mock_ssh).to receive( :closed? ).once.and_return(false)
|
@@ -62,7 +63,7 @@ module Beaker
|
|
62
63
|
|
63
64
|
it 'sets the @ssh variable to nil' do
|
64
65
|
mock_ssh = Object.new
|
65
|
-
expect( Net::SSH ).to receive( :start ).with(
|
66
|
+
expect( Net::SSH ).to receive( :start ).with( vmhostname, user, ssh_opts) { mock_ssh }
|
66
67
|
connection.connect
|
67
68
|
|
68
69
|
allow( mock_ssh).to receive( :closed? ).once.and_return(false)
|
@@ -75,7 +76,7 @@ module Beaker
|
|
75
76
|
it 'calls ssh shutdown & re-raises if ssh close fails with an unexpected Error' do
|
76
77
|
mock_ssh = Object.new
|
77
78
|
allow( mock_ssh ).to receive( :close ) { raise StandardError }
|
78
|
-
expect( Net::SSH ).to receive( :start ).with(
|
79
|
+
expect( Net::SSH ).to receive( :start ).with( vmhostname, user, ssh_opts) { mock_ssh }
|
79
80
|
connection.connect
|
80
81
|
|
81
82
|
allow( mock_ssh).to receive( :closed? ).once.and_return(false)
|
@@ -89,7 +90,7 @@ module Beaker
|
|
89
90
|
describe '#execute' do
|
90
91
|
it 'retries if failed with a retryable exception' do
|
91
92
|
mock_ssh = Object.new
|
92
|
-
expect( Net::SSH ).to receive( :start ).with(
|
93
|
+
expect( Net::SSH ).to receive( :start ).with( vmhostname, user, ssh_opts) { mock_ssh }
|
93
94
|
connection.connect
|
94
95
|
|
95
96
|
allow( subject ).to receive( :close )
|
@@ -101,7 +102,7 @@ module Beaker
|
|
101
102
|
|
102
103
|
it 'raises an error if it fails both times' do
|
103
104
|
mock_ssh = Object.new
|
104
|
-
expect( Net::SSH ).to receive( :start ).with(
|
105
|
+
expect( Net::SSH ).to receive( :start ).with( vmhostname, user, ssh_opts) { mock_ssh }
|
105
106
|
connection.connect
|
106
107
|
|
107
108
|
allow( subject ).to receive( :close )
|
@@ -114,7 +115,7 @@ module Beaker
|
|
114
115
|
describe '#request_terminal_for' do
|
115
116
|
it 'fails correctly by raising Net::SSH::Exception' do
|
116
117
|
mock_ssh = Object.new
|
117
|
-
expect( Net::SSH ).to receive( :start ).with(
|
118
|
+
expect( Net::SSH ).to receive( :start ).with( vmhostname, user, ssh_opts) { mock_ssh }
|
118
119
|
connection.connect
|
119
120
|
|
120
121
|
mock_channel = Object.new
|
@@ -127,7 +128,7 @@ module Beaker
|
|
127
128
|
describe '#register_stdout_for' do
|
128
129
|
before :each do
|
129
130
|
@mock_ssh = Object.new
|
130
|
-
expect( Net::SSH ).to receive( :start ).with(
|
131
|
+
expect( Net::SSH ).to receive( :start ).with( vmhostname, user, ssh_opts) { @mock_ssh }
|
131
132
|
connection.connect
|
132
133
|
|
133
134
|
@data = '7 of clubs'
|
@@ -163,7 +164,7 @@ module Beaker
|
|
163
164
|
|
164
165
|
before :each do
|
165
166
|
@mock_ssh = Object.new
|
166
|
-
expect( Net::SSH ).to receive( :start ).with(
|
167
|
+
expect( Net::SSH ).to receive( :start ).with( vmhostname, user, ssh_opts) { @mock_ssh }
|
167
168
|
connection.connect
|
168
169
|
|
169
170
|
@data = '3 of spades'
|
@@ -202,7 +203,7 @@ module Beaker
|
|
202
203
|
|
203
204
|
it 'assigns the output\'s exit code correctly from the data' do
|
204
205
|
mock_ssh = Object.new
|
205
|
-
expect( Net::SSH ).to receive( :start ).with(
|
206
|
+
expect( Net::SSH ).to receive( :start ).with( vmhostname, user, ssh_opts) { mock_ssh }
|
206
207
|
connection.connect
|
207
208
|
|
208
209
|
data = '10 of jeromes'
|
@@ -235,7 +236,7 @@ module Beaker
|
|
235
236
|
@mock_scp = Object.new
|
236
237
|
allow( @mock_scp ).to receive( :upload! )
|
237
238
|
allow( @mock_ssh ).to receive( :scp ).and_return( @mock_scp )
|
238
|
-
expect( Net::SSH ).to receive( :start ).with(
|
239
|
+
expect( Net::SSH ).to receive( :start ).with( vmhostname, user, ssh_opts) { @mock_ssh }
|
239
240
|
connection.connect
|
240
241
|
end
|
241
242
|
|
@@ -262,7 +263,7 @@ module Beaker
|
|
262
263
|
@mock_scp = Object.new
|
263
264
|
allow( @mock_scp ).to receive( :download! )
|
264
265
|
allow( @mock_ssh ).to receive( :scp ).and_return( @mock_scp )
|
265
|
-
expect( Net::SSH ).to receive( :start ).with(
|
266
|
+
expect( Net::SSH ).to receive( :start ).with( vmhostname, user, ssh_opts) { @mock_ssh }
|
266
267
|
connection.connect
|
267
268
|
end
|
268
269
|
|