beaker-vmware 1.0.0 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/dependabot.yml +9 -0
- data/.github/workflows/release.yml +1 -1
- data/.github/workflows/test.yml +27 -6
- data/.rubocop.yml +5 -0
- data/.rubocop_todo.yml +266 -0
- data/.simplecov +1 -1
- data/CHANGELOG.md +20 -0
- data/Gemfile +4 -23
- data/Rakefile +26 -125
- data/beaker-vmware.gemspec +20 -21
- data/bin/beaker-vmware +1 -3
- data/lib/beaker/hypervisor/fusion.rb +21 -23
- data/lib/beaker/hypervisor/vsphere.rb +23 -24
- data/lib/beaker/hypervisor/vsphere_helper.rb +78 -81
- data/lib/beaker-vmware/version.rb +1 -1
- data/spec/beaker/hypervisor/fusion_spec.rb +14 -16
- data/spec/beaker/hypervisor/vsphere_helper_spec.rb +120 -124
- data/spec/beaker/hypervisor/vsphere_spec.rb +28 -40
- data/spec/mock_fission.rb +63 -0
- data/spec/mock_vsphere.rb +284 -0
- data/spec/mock_vsphere_helper.rb +167 -0
- data/spec/spec_helper.rb +9 -7
- metadata +77 -32
@@ -2,162 +2,158 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
module Beaker
|
4
4
|
describe VsphereHelper do
|
5
|
-
let(
|
6
|
-
let(
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
5
|
+
let(:logger) { double('logger').as_null_object }
|
6
|
+
let(:vInfo) do
|
7
|
+
{ server: 'vsphere.labs.net', user: 'vsphere@labs.com', pass: 'supersekritpassword' }
|
8
|
+
end
|
9
|
+
let(:vsphere_helper) { VsphereHelper.new(vInfo.merge({ logger: logger })) }
|
10
|
+
let(:snaplist) do
|
11
|
+
{ 'snap1' => { 'snap1sub1' => nil,
|
12
|
+
'snap1sub2' => nil, },
|
13
|
+
'snap2' => nil,
|
14
|
+
'snap3' => { 'snap3sub1' => nil,
|
15
|
+
'snap3sub2' => nil,
|
16
|
+
'snap3sub3' => nil, }, }
|
17
|
+
end
|
18
|
+
let(:vms) do
|
19
|
+
[MockRbVmomiVM.new('mockvm1', snaplist),
|
20
|
+
MockRbVmomiVM.new('mockvm2', snaplist),
|
21
|
+
MockRbVmomiVM.new('mockvm3', snaplist),]
|
20
22
|
end
|
21
23
|
|
22
|
-
|
24
|
+
before do
|
25
|
+
stub_const('RbVmomi', MockRbVmomi)
|
26
|
+
end
|
23
27
|
|
28
|
+
describe '#load_config' do
|
24
29
|
it 'can load a .fog file' do
|
25
|
-
allow(
|
26
|
-
allow(
|
27
|
-
|
28
|
-
expect( VsphereHelper.load_config ).to be === vInfo
|
30
|
+
allow(File).to receive(:exist?).and_return(true)
|
31
|
+
allow(YAML).to receive(:load_file).and_return(fog_file_contents)
|
29
32
|
|
33
|
+
expect(VsphereHelper.load_config).to be === vInfo
|
30
34
|
end
|
31
35
|
|
32
36
|
it 'raises an error when the .fog file is missing' do
|
33
|
-
allow(
|
34
|
-
|
35
|
-
expect{ VsphereHelper.load_config }.to raise_error( ArgumentError )
|
37
|
+
allow(File).to receive(:exist?).and_return(false)
|
36
38
|
|
39
|
+
expect { VsphereHelper.load_config }.to raise_error(ArgumentError)
|
37
40
|
end
|
38
|
-
|
39
41
|
end
|
40
42
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
expect( vsphere_helper.find_snapshot( mockvm, 'snap2' ) ).to be === mockvm.get_snapshot( 'snap2' )
|
46
|
-
|
47
|
-
end
|
48
|
-
|
49
|
-
end
|
43
|
+
describe '#find_snapshot' do
|
44
|
+
it 'can find a given snapshot name' do
|
45
|
+
mockvm = MockRbVmomiVM.new('mockvm', snaplist)
|
50
46
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
expect( vsphere_helper.find_customization( 'name' ) ).to be === true
|
55
|
-
|
56
|
-
end
|
57
|
-
|
58
|
-
end
|
59
|
-
|
60
|
-
describe "#find_vms" do
|
61
|
-
it 'finds the list of vms' do
|
62
|
-
connection = vsphere_helper.instance_variable_get( :@connection )
|
63
|
-
connection.set_info( vms )
|
64
|
-
|
65
|
-
expect( vsphere_helper.find_vms( 'mockvm1' ) ).to be === {vms[0].name => vms[0]}
|
66
|
-
end
|
47
|
+
expect(vsphere_helper.find_snapshot(mockvm, 'snap2')).to be === mockvm.get_snapshot('snap2')
|
48
|
+
end
|
49
|
+
end
|
67
50
|
|
68
|
-
|
69
|
-
|
70
|
-
|
51
|
+
describe '#find_customization' do
|
52
|
+
it 'returns the customization spec' do
|
53
|
+
expect(vsphere_helper.find_customization('name')).to be === true
|
54
|
+
end
|
55
|
+
end
|
71
56
|
|
72
|
-
|
73
|
-
|
57
|
+
describe '#find_vms' do
|
58
|
+
it 'finds the list of vms' do
|
59
|
+
connection = vsphere_helper.instance_variable_get(:@connection)
|
60
|
+
connection.set_info(vms)
|
74
61
|
|
75
|
-
|
62
|
+
expect(vsphere_helper.find_vms('mockvm1')).to be === { vms[0].name => vms[0] }
|
63
|
+
end
|
76
64
|
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
dc = connection.serviceInstance.find_datacenter('testdc')
|
81
|
-
expect(vsphere_helper.find_datastore( dc,'datastorename' ) ).to be === true
|
82
|
-
end
|
65
|
+
it 'returns {} when no vm is found' do
|
66
|
+
connection = vsphere_helper.instance_variable_get(:@connection)
|
67
|
+
connection.set_info(vms)
|
83
68
|
|
84
|
-
|
69
|
+
expect(vsphere_helper.find_vms('novm')).to be === {}
|
70
|
+
end
|
71
|
+
end
|
85
72
|
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
73
|
+
describe '#find_datastore' do
|
74
|
+
it 'finds the datastore from the connection object' do
|
75
|
+
connection = vsphere_helper.instance_variable_get(:@connection)
|
76
|
+
dc = connection.serviceInstance.find_datacenter('testdc')
|
77
|
+
expect(vsphere_helper.find_datastore(dc, 'datastorename')).to be === true
|
78
|
+
end
|
79
|
+
end
|
91
80
|
|
92
|
-
|
81
|
+
describe '#find_folder' do
|
82
|
+
it 'can find a folder in the datacenter' do
|
83
|
+
connection = vsphere_helper.instance_variable_get(:@connection)
|
84
|
+
expect(vsphere_helper.find_folder('testdc',
|
85
|
+
'root')).to be === connection.serviceInstance.find_datacenter('testdc').vmFolder
|
86
|
+
end
|
87
|
+
end
|
93
88
|
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
89
|
+
describe '#find_pool' do
|
90
|
+
it 'can find a pool in a folder in the datacenter' do
|
91
|
+
connection = vsphere_helper.instance_variable_get(:@connection)
|
92
|
+
dc = connection.serviceInstance.find_datacenter('testdc')
|
93
|
+
dc.hostFolder = MockRbVmomi::VIM::Folder.new
|
94
|
+
dc.hostFolder.name = '/root'
|
100
95
|
|
101
|
-
|
96
|
+
expect(vsphere_helper.find_pool('testdc',
|
97
|
+
'root')).to be === connection.serviceInstance.find_datacenter('testdc').hostFolder
|
98
|
+
end
|
102
99
|
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
dc.hostFolder.name = "/root"
|
100
|
+
it 'can find a pool in a clustercomputeresource in the datacenter' do
|
101
|
+
connection = vsphere_helper.instance_variable_get(:@connection)
|
102
|
+
dc = connection.serviceInstance.find_datacenter('testdc')
|
103
|
+
dc.hostFolder = MockRbVmomi::VIM::ClusterComputeResource.new
|
104
|
+
dc.hostFolder.name = '/root'
|
109
105
|
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
connection = vsphere_helper.instance_variable_get( :@connection )
|
114
|
-
dc = connection.serviceInstance.find_datacenter('testdc')
|
115
|
-
dc.hostFolder = MockRbVmomi::VIM::ResourcePool.new
|
116
|
-
dc.hostFolder.name = "/root"
|
106
|
+
expect(vsphere_helper.find_pool('testdc',
|
107
|
+
'root')).to be === connection.serviceInstance.find_datacenter('testdc').hostFolder
|
108
|
+
end
|
117
109
|
|
118
|
-
|
119
|
-
|
110
|
+
it 'can find a pool in a resourcepool in the datacenter' do
|
111
|
+
connection = vsphere_helper.instance_variable_get(:@connection)
|
112
|
+
dc = connection.serviceInstance.find_datacenter('testdc')
|
113
|
+
dc.hostFolder = MockRbVmomi::VIM::ResourcePool.new
|
114
|
+
dc.hostFolder.name = '/root'
|
120
115
|
|
121
|
-
|
116
|
+
expect(vsphere_helper.find_pool('testdc',
|
117
|
+
'root')).to be === connection.serviceInstance.find_datacenter('testdc').hostFolder
|
118
|
+
end
|
119
|
+
end
|
122
120
|
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
121
|
+
describe '#wait_for_tasks' do
|
122
|
+
it 'can wait for tasks to error' do
|
123
|
+
allow(vsphere_helper).to receive(:sleep).and_return(true)
|
124
|
+
vms.each do |vm|
|
125
|
+
vm.info.state = 'error'
|
126
|
+
end
|
129
127
|
|
130
|
-
|
131
|
-
|
128
|
+
expect(vsphere_helper.wait_for_tasks(vms, 0, 5)).to be === vms
|
129
|
+
end
|
132
130
|
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
131
|
+
it 'can wait for tasks to succeed' do
|
132
|
+
allow(vsphere_helper).to receive(:sleep).and_return(true)
|
133
|
+
vms.each do |vm|
|
134
|
+
vm.info.state = 'success'
|
135
|
+
end
|
138
136
|
|
139
|
-
|
140
|
-
|
137
|
+
expect(vsphere_helper.wait_for_tasks(vms, 0, 5)).to be === vms
|
138
|
+
end
|
141
139
|
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
140
|
+
it 'errors when tasks fail to error/success before timing out' do
|
141
|
+
allow(vsphere_helper).to receive(:sleep).and_return(true)
|
142
|
+
vms.each do |vm|
|
143
|
+
vm.info.state = 'nope'
|
144
|
+
end
|
147
145
|
|
148
|
-
|
149
|
-
|
146
|
+
expect { vsphere_helper.wait_for_tasks(vms, 0, 5) }.to raise_error
|
147
|
+
end
|
148
|
+
end
|
150
149
|
|
151
|
-
|
150
|
+
describe '#close' do
|
151
|
+
it 'closes the connection' do
|
152
|
+
connection = vsphere_helper.instance_variable_get(:@connection)
|
153
|
+
expect(connection).to receive(:close).once
|
152
154
|
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
vsphere_helper.close
|
159
|
-
end
|
160
|
-
end
|
161
|
-
|
162
|
-
end
|
155
|
+
vsphere_helper.close
|
156
|
+
end
|
157
|
+
end
|
158
|
+
end
|
163
159
|
end
|
@@ -2,89 +2,77 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
module Beaker
|
4
4
|
describe Vsphere do
|
5
|
-
|
6
|
-
|
7
|
-
MockVsphereHelper.
|
8
|
-
|
9
|
-
stub_const( "VsphereHelper", MockVsphereHelper )
|
5
|
+
before do
|
6
|
+
MockVsphereHelper.set_config(fog_file_contents)
|
7
|
+
MockVsphereHelper.set_vms(make_hosts)
|
8
|
+
stub_const('VsphereHelper', MockVsphereHelper)
|
10
9
|
end
|
11
10
|
|
12
|
-
describe
|
13
|
-
|
14
|
-
it 'provisions hosts' do
|
11
|
+
describe '#provision' do
|
12
|
+
it 'provisions hosts' do
|
15
13
|
MockVsphereHelper.powerOff
|
16
|
-
vsphere = Beaker::Vsphere.new(
|
14
|
+
vsphere = Beaker::Vsphere.new(make_hosts, make_opts)
|
17
15
|
|
18
16
|
vsphere.provision
|
19
17
|
|
20
|
-
hosts =
|
18
|
+
hosts = vsphere.instance_variable_get(:@hosts)
|
21
19
|
hosts.each do |host|
|
22
|
-
expect(
|
20
|
+
expect(MockVsphereHelper.find_vm(host.name).powerState) == 'poweredOn'
|
23
21
|
end
|
24
|
-
|
25
22
|
end
|
26
23
|
|
27
24
|
it 'raises an error if a vm is missing in Vsphere' do
|
28
25
|
MockVsphereHelper.powerOff
|
29
|
-
hosts = make_hosts
|
26
|
+
hosts = make_hosts
|
30
27
|
hosts[0][:vmname] = 'unknown'
|
31
|
-
vsphere = Beaker::Vsphere.new(
|
32
|
-
|
33
|
-
expect{ vsphere.provision }.to raise_error
|
28
|
+
vsphere = Beaker::Vsphere.new(hosts, make_opts)
|
34
29
|
|
30
|
+
expect { vsphere.provision }.to raise_error
|
35
31
|
end
|
36
32
|
|
37
33
|
it 'raises an error if a vm does not have a given snapshot name' do
|
38
34
|
MockVsphereHelper.powerOff
|
39
|
-
hosts = make_hosts
|
40
|
-
hosts[0][
|
41
|
-
vsphere = Beaker::Vsphere.new(
|
42
|
-
|
43
|
-
expect{ vsphere.provision }.to raise_error
|
35
|
+
hosts = make_hosts
|
36
|
+
hosts[0]['snapshot'] = 'unknown'
|
37
|
+
vsphere = Beaker::Vsphere.new(hosts, make_opts)
|
44
38
|
|
39
|
+
expect { vsphere.provision }.to raise_error
|
45
40
|
end
|
46
41
|
|
47
42
|
it 'provisions hosts if no snapshot is provided' do
|
48
43
|
MockVsphereHelper.powerOff
|
49
|
-
hosts = make_hosts
|
50
|
-
hosts[0][
|
51
|
-
vsphere = Beaker::Vsphere.new(
|
44
|
+
hosts = make_hosts
|
45
|
+
hosts[0]['snapshot'] = nil
|
46
|
+
vsphere = Beaker::Vsphere.new(hosts, make_opts)
|
52
47
|
|
53
48
|
vsphere.provision
|
54
49
|
|
55
50
|
hosts.each do |host|
|
56
|
-
expect(
|
51
|
+
expect(MockVsphereHelper.find_vm(host.name).powerState) == 'poweredOn'
|
57
52
|
end
|
58
|
-
|
59
53
|
end
|
60
|
-
|
61
54
|
end
|
62
55
|
|
63
|
-
describe
|
64
|
-
|
65
|
-
it "cleans up" do
|
56
|
+
describe '#cleanup' do
|
57
|
+
it 'cleans up' do
|
66
58
|
MockVsphereHelper.powerOn
|
67
|
-
vsphere = Beaker::Vsphere.new(
|
59
|
+
vsphere = Beaker::Vsphere.new(make_hosts, make_opts)
|
68
60
|
vsphere.cleanup
|
69
61
|
|
70
|
-
hosts =
|
62
|
+
hosts = vsphere.instance_variable_get(:@hosts)
|
71
63
|
hosts.each do |host|
|
72
|
-
expect(
|
64
|
+
expect(MockVsphereHelper.find_vm(host.name).powerState) == 'poweredOff'
|
73
65
|
end
|
74
66
|
end
|
75
67
|
|
76
68
|
it 'raises an error if a vm is missing in Vsphere' do
|
77
69
|
MockVsphereHelper.powerOn
|
78
|
-
hosts = make_hosts
|
70
|
+
hosts = make_hosts
|
79
71
|
hosts[0][:vmname] = 'unknown'
|
80
|
-
vsphere = Beaker::Vsphere.new(
|
81
|
-
|
82
|
-
expect{ vsphere.cleanup }.to raise_error
|
72
|
+
vsphere = Beaker::Vsphere.new(hosts, make_opts)
|
83
73
|
|
74
|
+
expect { vsphere.cleanup }.to raise_error
|
84
75
|
end
|
85
|
-
|
86
76
|
end
|
87
|
-
|
88
77
|
end
|
89
|
-
|
90
78
|
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
class Response
|
2
|
+
attr_accessor :code, :message, :data
|
3
|
+
|
4
|
+
def initialize(code = 0, message = '', data = nil)
|
5
|
+
@code = code
|
6
|
+
@message = message
|
7
|
+
@data = data
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
class MockFissionVM
|
12
|
+
attr_accessor :name
|
13
|
+
|
14
|
+
@@snaps = []
|
15
|
+
def initialize(name)
|
16
|
+
@name = name
|
17
|
+
@running = true
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.set_snapshots(snaps)
|
21
|
+
@@snaps = snaps
|
22
|
+
end
|
23
|
+
|
24
|
+
def snapshots
|
25
|
+
Response.new(0, '', @@snaps)
|
26
|
+
end
|
27
|
+
|
28
|
+
def revert_to_snapshot(_name)
|
29
|
+
@running = false
|
30
|
+
end
|
31
|
+
|
32
|
+
def running?
|
33
|
+
Response.new(0, '', @running)
|
34
|
+
end
|
35
|
+
|
36
|
+
def start(_opt)
|
37
|
+
@running = true
|
38
|
+
end
|
39
|
+
|
40
|
+
def exists?
|
41
|
+
true
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
class MockFission
|
46
|
+
@@vms = []
|
47
|
+
def self.presets(hosts)
|
48
|
+
snaps = []
|
49
|
+
hosts.each do |host|
|
50
|
+
@@vms << MockFissionVM.new(host.name)
|
51
|
+
snaps << host[:snapshot]
|
52
|
+
end
|
53
|
+
MockFissionVM.set_snapshots(snaps)
|
54
|
+
end
|
55
|
+
|
56
|
+
def self.all
|
57
|
+
Response.new(0, '', @@vms)
|
58
|
+
end
|
59
|
+
|
60
|
+
def self.new(name)
|
61
|
+
MockFissionVM.new(name)
|
62
|
+
end
|
63
|
+
end
|