vcloud-core 1.0.0 → 1.0.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.
- data/CHANGELOG.md +13 -1
- data/README.md +13 -8
- data/lib/vcloud/core/version.rb +1 -1
- data/spec/vcloud/core/config_loader_spec.rb +155 -159
- data/spec/vcloud/core/config_validator_spec.rb +615 -619
- data/spec/vcloud/core/edge_gateway_interface_spec.rb +65 -70
- data/spec/vcloud/core/edge_gateway_spec.rb +138 -144
- data/spec/vcloud/core/independent_disk_spec.rb +15 -15
- data/spec/vcloud/core/metadata_helper_spec.rb +73 -77
- data/spec/vcloud/core/org_vdc_network_spec.rb +226 -230
- data/spec/vcloud/core/query_runner_spec.rb +31 -31
- data/spec/vcloud/core/query_spec.rb +1 -1
- data/spec/vcloud/core/vapp_spec.rb +175 -179
- data/spec/vcloud/core/vapp_template_spec.rb +82 -86
- data/spec/vcloud/core/vdc_spec.rb +47 -53
- data/spec/vcloud/core/vm_spec.rb +354 -358
- data/vcloud-core.gemspec +4 -4
- metadata +28 -30
- data/spec/integration/README.md +0 -36
@@ -1,92 +1,88 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
|
4
|
-
module Core
|
5
|
-
describe VappTemplate do
|
6
|
-
|
7
|
-
before(:each) do
|
8
|
-
@id = 'vappTemplate-12345678-1234-1234-1234-000000234121'
|
9
|
-
@mock_fog_interface = StubFogInterface.new
|
10
|
-
allow(Vcloud::Core::Fog::ServiceInterface).to receive(:new).and_return(@mock_fog_interface)
|
11
|
-
end
|
12
|
-
|
13
|
-
context "Class public interface" do
|
14
|
-
it { expect(VappTemplate).to respond_to(:get) }
|
15
|
-
end
|
16
|
-
|
17
|
-
context "Instance public interface" do
|
18
|
-
subject { VappTemplate.new(@id) }
|
19
|
-
it { should respond_to(:id) }
|
20
|
-
it { should respond_to(:vcloud_attributes) }
|
21
|
-
it { should respond_to(:name) }
|
22
|
-
it { should respond_to(:href) }
|
23
|
-
end
|
24
|
-
|
25
|
-
context "#initialize" do
|
26
|
-
|
27
|
-
it "should be constructable from just an id reference" do
|
28
|
-
obj = VappTemplate.new(@id)
|
29
|
-
expect(obj.class).to be(Vcloud::Core::VappTemplate)
|
30
|
-
end
|
31
|
-
|
32
|
-
it "should store the id specified" do
|
33
|
-
obj = VappTemplate.new(@id)
|
34
|
-
expect(obj.id).to eq(@id)
|
35
|
-
end
|
36
|
-
|
37
|
-
it "should raise error if id is not in correct format" do
|
38
|
-
bogus_id = '12314124-ede5-4d07-bad5-000000111111'
|
39
|
-
expect{ VappTemplate.new(bogus_id) }.to raise_error("vappTemplate id : #{bogus_id} is not in correct format" )
|
40
|
-
end
|
41
|
-
|
42
|
-
end
|
43
|
-
|
44
|
-
|
45
|
-
context '#get' do
|
46
|
-
|
47
|
-
it 'should raise a RuntimeError if there is no template' do
|
48
|
-
q_results = [ ]
|
49
|
-
mock_query = double(:query_runner)
|
50
|
-
expect(Vcloud::Core::QueryRunner).to receive(:new).and_return(mock_query)
|
51
|
-
expect(mock_query).to receive(:run).
|
52
|
-
with('vAppTemplate', :filter => "name==test_template;catalogName==test_catalog").
|
53
|
-
and_return(q_results)
|
54
|
-
expect { VappTemplate.get('test_template', 'test_catalog') }.
|
55
|
-
to raise_error('Could not find template vApp')
|
56
|
-
end
|
57
|
-
|
58
|
-
it 'should raise an error if more than one template is returned' do
|
59
|
-
q_results = [
|
60
|
-
{ :name => 'test_template',
|
61
|
-
:href => "/vappTemplate-12345678-90ab-cdef-0123-4567890ab001" },
|
62
|
-
{ :name => 'test_template',
|
63
|
-
:href => "/vappTemplate-12345678-90ab-cdef-0123-4567890ab002" },
|
64
|
-
]
|
65
|
-
mock_query = double(:query_runner)
|
66
|
-
expect(Vcloud::Core::QueryRunner).to receive(:new).and_return(mock_query)
|
67
|
-
expect(mock_query).to receive(:run).
|
68
|
-
with('vAppTemplate', :filter => "name==test_template;catalogName==test_catalog").
|
69
|
-
and_return(q_results)
|
70
|
-
expect { VappTemplate.get('test_template', 'test_catalog') }.
|
71
|
-
to raise_error('Template test_template is not unique in catalog test_catalog')
|
72
|
-
end
|
73
|
-
|
74
|
-
it 'should return a valid template object if it exists' do
|
75
|
-
q_results = [
|
76
|
-
{ :name => 'test_template',
|
77
|
-
:href => "/vappTemplate-12345678-90ab-cdef-0123-4567890abcde" }
|
78
|
-
]
|
79
|
-
mock_query = double(:query)
|
80
|
-
expect(Vcloud::Core::QueryRunner).to receive(:new).and_return(mock_query)
|
81
|
-
expect(mock_query).to receive(:run).
|
82
|
-
with('vAppTemplate', :filter => "name==test_template;catalogName==test_catalog").
|
83
|
-
and_return(q_results)
|
84
|
-
test_template = VappTemplate.get('test_template', 'test_catalog')
|
85
|
-
expect(test_template.id).to eq('vappTemplate-12345678-90ab-cdef-0123-4567890abcde')
|
86
|
-
end
|
87
|
-
|
88
|
-
end
|
3
|
+
describe Vcloud::Core::VappTemplate do
|
89
4
|
|
5
|
+
before(:each) do
|
6
|
+
@id = 'vappTemplate-12345678-1234-1234-1234-000000234121'
|
7
|
+
@mock_fog_interface = StubFogInterface.new
|
8
|
+
allow(Vcloud::Core::Fog::ServiceInterface).to receive(:new).and_return(@mock_fog_interface)
|
9
|
+
end
|
10
|
+
|
11
|
+
context "Class public interface" do
|
12
|
+
it { expect(Vcloud::Core::VappTemplate).to respond_to(:get) }
|
13
|
+
end
|
14
|
+
|
15
|
+
context "Instance public interface" do
|
16
|
+
subject { Vcloud::Core::VappTemplate.new(@id) }
|
17
|
+
it { should respond_to(:id) }
|
18
|
+
it { should respond_to(:vcloud_attributes) }
|
19
|
+
it { should respond_to(:name) }
|
20
|
+
it { should respond_to(:href) }
|
21
|
+
end
|
22
|
+
|
23
|
+
context "#initialize" do
|
24
|
+
|
25
|
+
it "should be constructable from just an id reference" do
|
26
|
+
obj = Vcloud::Core::VappTemplate.new(@id)
|
27
|
+
expect(obj.class).to be(Vcloud::Core::VappTemplate)
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should store the id specified" do
|
31
|
+
obj = Vcloud::Core::VappTemplate.new(@id)
|
32
|
+
expect(obj.id).to eq(@id)
|
90
33
|
end
|
34
|
+
|
35
|
+
it "should raise error if id is not in correct format" do
|
36
|
+
bogus_id = '12314124-ede5-4d07-bad5-000000111111'
|
37
|
+
expect{ Vcloud::Core::VappTemplate.new(bogus_id) }.to raise_error("vappTemplate id : #{bogus_id} is not in correct format" )
|
38
|
+
end
|
39
|
+
|
91
40
|
end
|
41
|
+
|
42
|
+
|
43
|
+
context '#get' do
|
44
|
+
|
45
|
+
it 'should raise a RuntimeError if there is no template' do
|
46
|
+
q_results = [ ]
|
47
|
+
mock_query = double(:query_runner)
|
48
|
+
expect(Vcloud::Core::QueryRunner).to receive(:new).and_return(mock_query)
|
49
|
+
expect(mock_query).to receive(:run).
|
50
|
+
with('vAppTemplate', :filter => "name==test_template;catalogName==test_catalog").
|
51
|
+
and_return(q_results)
|
52
|
+
expect { Vcloud::Core::VappTemplate.get('test_template', 'test_catalog') }.
|
53
|
+
to raise_error('Could not find template vApp')
|
54
|
+
end
|
55
|
+
|
56
|
+
it 'should raise an error if more than one template is returned' do
|
57
|
+
q_results = [
|
58
|
+
{ :name => 'test_template',
|
59
|
+
:href => "/vappTemplate-12345678-90ab-cdef-0123-4567890ab001" },
|
60
|
+
{ :name => 'test_template',
|
61
|
+
:href => "/vappTemplate-12345678-90ab-cdef-0123-4567890ab002" },
|
62
|
+
]
|
63
|
+
mock_query = double(:query_runner)
|
64
|
+
expect(Vcloud::Core::QueryRunner).to receive(:new).and_return(mock_query)
|
65
|
+
expect(mock_query).to receive(:run).
|
66
|
+
with('vAppTemplate', :filter => "name==test_template;catalogName==test_catalog").
|
67
|
+
and_return(q_results)
|
68
|
+
expect { Vcloud::Core::VappTemplate.get('test_template', 'test_catalog') }.
|
69
|
+
to raise_error('Template test_template is not unique in catalog test_catalog')
|
70
|
+
end
|
71
|
+
|
72
|
+
it 'should return a valid template object if it exists' do
|
73
|
+
q_results = [
|
74
|
+
{ :name => 'test_template',
|
75
|
+
:href => "/vappTemplate-12345678-90ab-cdef-0123-4567890abcde" }
|
76
|
+
]
|
77
|
+
mock_query = double(:query)
|
78
|
+
expect(Vcloud::Core::QueryRunner).to receive(:new).and_return(mock_query)
|
79
|
+
expect(mock_query).to receive(:run).
|
80
|
+
with('vAppTemplate', :filter => "name==test_template;catalogName==test_catalog").
|
81
|
+
and_return(q_results)
|
82
|
+
test_template = Vcloud::Core::VappTemplate.get('test_template', 'test_catalog')
|
83
|
+
expect(test_template.id).to eq('vappTemplate-12345678-90ab-cdef-0123-4567890abcde')
|
84
|
+
end
|
85
|
+
|
86
|
+
end
|
87
|
+
|
92
88
|
end
|
@@ -1,68 +1,62 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
|
4
|
-
module Core
|
5
|
-
describe Vdc do
|
3
|
+
describe Vcloud::Core::Vdc do
|
6
4
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
context "Class public interface" do
|
14
|
-
it { expect(Vdc).to respond_to(:get_by_name) }
|
15
|
-
end
|
16
|
-
|
17
|
-
context "Instance public interface" do
|
18
|
-
subject { Vdc.new(@vdc_id) }
|
19
|
-
it { should respond_to(:id) }
|
20
|
-
it { should respond_to(:name) }
|
21
|
-
it { should respond_to(:href) }
|
22
|
-
end
|
23
|
-
|
24
|
-
context "#initialize" do
|
5
|
+
before(:each) do
|
6
|
+
@vdc_id = '12345678-1234-1234-1234-000000111232'
|
7
|
+
@mock_fog_interface = StubFogInterface.new
|
8
|
+
allow(Vcloud::Core::Fog::ServiceInterface).to receive(:new).and_return(@mock_fog_interface)
|
9
|
+
end
|
25
10
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
end
|
11
|
+
context "Class public interface" do
|
12
|
+
it { expect(Vcloud::Core::Vdc).to respond_to(:get_by_name) }
|
13
|
+
end
|
30
14
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
15
|
+
context "Instance public interface" do
|
16
|
+
subject { Vcloud::Core::Vdc.new(@vdc_id) }
|
17
|
+
it { should respond_to(:id) }
|
18
|
+
it { should respond_to(:name) }
|
19
|
+
it { should respond_to(:href) }
|
20
|
+
end
|
35
21
|
|
36
|
-
|
37
|
-
bogus_id = '123123-bogus-id-123445'
|
38
|
-
expect{ Vdc.new(bogus_id) }.to raise_error("vdc id : #{bogus_id} is not in correct format" )
|
39
|
-
end
|
22
|
+
context "#initialize" do
|
40
23
|
|
41
|
-
|
24
|
+
it "should be constructable from just an id reference" do
|
25
|
+
obj = Vcloud::Core::Vdc.new(@vdc_id)
|
26
|
+
expect(obj.class).to be(Vcloud::Core::Vdc)
|
27
|
+
end
|
42
28
|
|
43
|
-
|
29
|
+
it "should store the id specified" do
|
30
|
+
obj = Vcloud::Core::Vdc.new(@vdc_id)
|
31
|
+
expect(obj.id).to eq(@vdc_id)
|
32
|
+
end
|
44
33
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
mock_query = double(:query_runner)
|
50
|
-
expect(Vcloud::Core::QueryRunner).to receive(:new).and_return(mock_query)
|
51
|
-
expect(mock_query).to receive(:run).with('orgVdc', :filter => "name==vdc-test-1").and_return(q_results)
|
52
|
-
obj = Vdc.get_by_name('vdc-test-1')
|
53
|
-
expect(obj.class).to be(Vcloud::Core::Vdc)
|
54
|
-
end
|
34
|
+
it "should raise error if id is not in correct format" do
|
35
|
+
bogus_id = '123123-bogus-id-123445'
|
36
|
+
expect{ Vcloud::Core::Vdc.new(bogus_id) }.to raise_error("vdc id : #{bogus_id} is not in correct format" )
|
37
|
+
end
|
55
38
|
|
56
|
-
|
57
|
-
q_results = [ ]
|
58
|
-
mock_query = double(:query_runner)
|
59
|
-
expect(Vcloud::Core::QueryRunner).to receive(:new).and_return(mock_query)
|
60
|
-
expect(mock_query).to receive(:run).with('orgVdc', :filter => "name==vdc-test-1").and_return(q_results)
|
61
|
-
expect{ Vdc.get_by_name('vdc-test-1') }.to raise_exception(RuntimeError, "vDc vdc-test-1 not found")
|
62
|
-
end
|
39
|
+
end
|
63
40
|
|
64
|
-
|
41
|
+
context "#get_by_name" do
|
42
|
+
|
43
|
+
it "should return a Vcloud::Core::Vdc object if name exists" do
|
44
|
+
q_results = [
|
45
|
+
{ :name => 'vdc-test-1', :href => @vdc_id }
|
46
|
+
]
|
47
|
+
mock_query = double(:query_runner)
|
48
|
+
expect(Vcloud::Core::QueryRunner).to receive(:new).and_return(mock_query)
|
49
|
+
expect(mock_query).to receive(:run).with('orgVdc', :filter => "name==vdc-test-1").and_return(q_results)
|
50
|
+
obj = Vcloud::Core::Vdc.get_by_name('vdc-test-1')
|
51
|
+
expect(obj.class).to be(Vcloud::Core::Vdc)
|
52
|
+
end
|
65
53
|
|
54
|
+
it "should raise an error if no vDC with that name exists" do
|
55
|
+
q_results = [ ]
|
56
|
+
mock_query = double(:query_runner)
|
57
|
+
expect(Vcloud::Core::QueryRunner).to receive(:new).and_return(mock_query)
|
58
|
+
expect(mock_query).to receive(:run).with('orgVdc', :filter => "name==vdc-test-1").and_return(q_results)
|
59
|
+
expect{ Vcloud::Core::Vdc.get_by_name('vdc-test-1') }.to raise_exception(RuntimeError, "vDc vdc-test-1 not found")
|
66
60
|
end
|
67
61
|
|
68
62
|
end
|
data/spec/vcloud/core/vm_spec.rb
CHANGED
@@ -1,377 +1,373 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
let(:preamble) do
|
128
|
-
<<-'EOF'
|
3
|
+
describe Vcloud::Core::Vm do
|
4
|
+
|
5
|
+
before(:each) do
|
6
|
+
@vm_id = 'vm-1234'
|
7
|
+
@vapp_id = 'vapp-4321'
|
8
|
+
@vapp_name = 'test-vapp-1'
|
9
|
+
@vm_name = 'test-vm-1'
|
10
|
+
@data_dir = File.join(File.dirname(__FILE__), "/data")
|
11
|
+
@mock_vm_memory_size = 1024
|
12
|
+
@mock_metadata = {
|
13
|
+
:foo => "bar",
|
14
|
+
:false_thing => false,
|
15
|
+
:true_thing => true,
|
16
|
+
:number => 53,
|
17
|
+
:zero => 0,
|
18
|
+
}
|
19
|
+
@mock_vm_cpu_count = 1
|
20
|
+
@fog_interface = StubFogInterface.new
|
21
|
+
@mock_vapp = double(:vappm, :name => @vapp_name, :id => @vapp_id)
|
22
|
+
allow(Vcloud::Core::Fog::ServiceInterface).to receive(:new).and_return(@fog_interface)
|
23
|
+
allow(@fog_interface).to receive(:get_vapp).with(@vm_id).and_return({
|
24
|
+
:name => "#{@vm_name}",
|
25
|
+
:href => "vm-href/#{@vm_id}",
|
26
|
+
:'ovf:VirtualHardwareSection' => {
|
27
|
+
:'ovf:Item' => [
|
28
|
+
{
|
29
|
+
:'rasd:ResourceType' => '4',
|
30
|
+
:'rasd:VirtualQuantity' => "#{@mock_vm_memory_size}",
|
31
|
+
},
|
32
|
+
{
|
33
|
+
:'rasd:ResourceType' => '3',
|
34
|
+
:'rasd:VirtualQuantity' => "#{@mock_vm_cpu_count}",
|
35
|
+
}
|
36
|
+
]
|
37
|
+
}
|
38
|
+
})
|
39
|
+
@vm = Vcloud::Core::Vm.new(@vm_id, @mock_vapp)
|
40
|
+
end
|
41
|
+
|
42
|
+
context "Class public interface" do
|
43
|
+
end
|
44
|
+
|
45
|
+
context "Instance public interface" do
|
46
|
+
subject { Vcloud::Core::Vm.new(@vm_id, @mock_vapp) }
|
47
|
+
it { should respond_to(:id) }
|
48
|
+
it { should respond_to(:vcloud_attributes) }
|
49
|
+
it { should respond_to(:name) }
|
50
|
+
it { should respond_to(:href) }
|
51
|
+
it { should respond_to(:vapp_name) }
|
52
|
+
it { should respond_to(:update_name) }
|
53
|
+
it { should respond_to(:update_cpu_count) }
|
54
|
+
it { should respond_to(:update_metadata) }
|
55
|
+
it { should respond_to(:update_storage_profile) }
|
56
|
+
it { should respond_to(:add_extra_disks) }
|
57
|
+
it { should respond_to(:attach_independent_disks) }
|
58
|
+
it { should respond_to(:detach_independent_disks) }
|
59
|
+
it { should respond_to(:configure_network_interfaces) }
|
60
|
+
it { should respond_to(:configure_guest_customization_section) }
|
61
|
+
end
|
62
|
+
|
63
|
+
context "#initialize" do
|
64
|
+
|
65
|
+
it "should be constructable from just an id reference & Vapp object" do
|
66
|
+
obj = Vcloud::Core::Vm.new(@vm_id, @mock_vapp)
|
67
|
+
expect(obj.class).to be(Vcloud::Core::Vm)
|
68
|
+
end
|
69
|
+
|
70
|
+
it "should store the id specified" do
|
71
|
+
obj = Vcloud::Core::Vm.new(@vm_id, @mock_vapp)
|
72
|
+
expect(obj.id).to eq(@vm_id)
|
73
|
+
end
|
74
|
+
|
75
|
+
it "should raise error if id is not in correct format" do
|
76
|
+
bogus_id = '12314124-ede5-4d07-bad5-000000111111'
|
77
|
+
expect{ Vcloud::Core::Vm.new(bogus_id, @mock_vapp) }.to raise_error("vm id : #{bogus_id} is not in correct format" )
|
78
|
+
end
|
79
|
+
|
80
|
+
end
|
81
|
+
|
82
|
+
context "update memory in VM" do
|
83
|
+
it "should not allow memory size < 64MB" do
|
84
|
+
expect(@fog_interface).not_to receive(:put_memory)
|
85
|
+
@vm.update_memory_size_in_mb(63)
|
86
|
+
end
|
87
|
+
it "should not update memory if is size has not changed" do
|
88
|
+
expect(@fog_interface).not_to receive(:put_memory)
|
89
|
+
@vm.update_memory_size_in_mb(@mock_vm_memory_size)
|
90
|
+
end
|
91
|
+
it "should gracefully handle a nil memory size" do
|
92
|
+
expect(@fog_interface).not_to receive(:put_memory)
|
93
|
+
@vm.update_memory_size_in_mb(nil)
|
94
|
+
end
|
95
|
+
it "should set memory size 64MB" do
|
96
|
+
expect(@fog_interface).to receive(:put_memory).with(@vm_id, 64)
|
97
|
+
@vm.update_memory_size_in_mb(64)
|
98
|
+
end
|
99
|
+
it "should set memory size 4096MB" do
|
100
|
+
expect(@fog_interface).to receive(:put_memory).with(@vm_id, 4096)
|
101
|
+
@vm.update_memory_size_in_mb(4096)
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
context "update the number of cpus in vm" do
|
106
|
+
it "should gracefully handle nil cpu count" do
|
107
|
+
expect(@fog_interface).not_to receive(:put_cpu)
|
108
|
+
@vm.update_cpu_count(nil)
|
109
|
+
end
|
110
|
+
it "should not update cpu if is count has not changed" do
|
111
|
+
expect(@fog_interface).not_to receive(:put_cpu)
|
112
|
+
@vm.update_cpu_count(@mock_vm_cpu_count)
|
113
|
+
end
|
114
|
+
it "should not allow a zero cpu count" do
|
115
|
+
expect(@fog_interface).not_to receive(:put_cpu)
|
116
|
+
@vm.update_cpu_count(0)
|
117
|
+
end
|
118
|
+
it "should update cpu count in input is ok" do
|
119
|
+
expect(@fog_interface).to receive(:put_cpu).with(@vm_id, 2)
|
120
|
+
@vm.update_cpu_count(2)
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
context '#configure_guest_customization_section' do
|
125
|
+
let(:preamble) do
|
126
|
+
<<-'EOF'
|
129
127
|
#!/usr/bin/env bash
|
130
128
|
echo "Hello World"
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
129
|
+
EOF
|
130
|
+
end
|
131
|
+
|
132
|
+
it 'passes a pre-generated preamble to fog' do
|
133
|
+
expect(@fog_interface).to receive(:put_guest_customization_section).with(@vm_id, @vapp_name, preamble)
|
134
|
+
|
135
|
+
@vm.configure_guest_customization_section(preamble)
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
context "update metadata" do
|
140
|
+
it "should handle empty metadata hash" do
|
141
|
+
expect(@fog_interface).not_to receive(:put_vapp_metadata_value)
|
142
|
+
@vm.update_metadata(nil)
|
143
|
+
end
|
144
|
+
it "should handle metadata of multiple types" do
|
145
|
+
expect(@fog_interface).to receive(:put_vapp_metadata_value).with(@vm_id, :foo, 'bar')
|
146
|
+
expect(@fog_interface).to receive(:put_vapp_metadata_value).with(@vm_id, :false_thing, false)
|
147
|
+
expect(@fog_interface).to receive(:put_vapp_metadata_value).with(@vm_id, :true_thing, true)
|
148
|
+
expect(@fog_interface).to receive(:put_vapp_metadata_value).with(@vm_id, :number, 53)
|
149
|
+
expect(@fog_interface).to receive(:put_vapp_metadata_value).with(@vm_id, :zero, 0)
|
150
|
+
expect(@fog_interface).to receive(:put_vapp_metadata_value).with(@vapp_id, :foo, 'bar')
|
151
|
+
expect(@fog_interface).to receive(:put_vapp_metadata_value).with(@vapp_id, :false_thing, false)
|
152
|
+
expect(@fog_interface).to receive(:put_vapp_metadata_value).with(@vapp_id, :true_thing, true)
|
153
|
+
expect(@fog_interface).to receive(:put_vapp_metadata_value).with(@vapp_id, :number, 53)
|
154
|
+
expect(@fog_interface).to receive(:put_vapp_metadata_value).with(@vapp_id, :zero, 0)
|
155
|
+
@vm.update_metadata(@mock_metadata)
|
156
|
+
end
|
157
|
+
end
|
158
|
+
|
159
|
+
context "configure vm network interfaces" do
|
160
|
+
it "should configure single nic without an IP" do
|
161
|
+
network_config = [{:name => 'Default'}]
|
162
|
+
expect(@fog_interface).to receive(:put_network_connection_system_section_vapp).with(@vm_id, {
|
163
|
+
:PrimaryNetworkConnectionIndex => 0,
|
164
|
+
:NetworkConnection => [
|
165
|
+
{
|
166
|
+
:network => 'Default',
|
167
|
+
:needsCustomization => true,
|
168
|
+
:NetworkConnectionIndex => 0,
|
169
|
+
:IsConnected => true,
|
170
|
+
:IpAddressAllocationMode => "DHCP"
|
171
|
+
}
|
172
|
+
]})
|
173
|
+
@vm.configure_network_interfaces(network_config)
|
174
|
+
end
|
175
|
+
|
176
|
+
it "should configure nic from pool" do
|
177
|
+
network_config = [{:name => 'Default', :allocation_mode => 'pool'}]
|
178
|
+
expect(@fog_interface).to receive(:put_network_connection_system_section_vapp).with(@vm_id, {
|
179
|
+
:PrimaryNetworkConnectionIndex => 0,
|
180
|
+
:NetworkConnection => [
|
181
|
+
{
|
182
|
+
:network => 'Default',
|
183
|
+
:needsCustomization => true,
|
184
|
+
:NetworkConnectionIndex => 0,
|
185
|
+
:IsConnected => true,
|
186
|
+
:IpAddressAllocationMode => "POOL"
|
187
|
+
}
|
188
|
+
]})
|
189
|
+
@vm.configure_network_interfaces(network_config)
|
190
|
+
end
|
191
|
+
|
192
|
+
it "should prefer configuring nic with static address" do
|
193
|
+
network_config = [{:name => 'Default', :allocation_mode => 'dhcp', :ip_address => '192.168.1.1'}]
|
194
|
+
expect(@fog_interface).to receive(:put_network_connection_system_section_vapp).with(@vm_id, {
|
195
|
+
:PrimaryNetworkConnectionIndex => 0,
|
196
|
+
:NetworkConnection => [
|
197
|
+
{
|
198
|
+
:network => 'Default',
|
199
|
+
:needsCustomization => true,
|
200
|
+
:NetworkConnectionIndex => 0,
|
201
|
+
:IsConnected => true,
|
202
|
+
:IpAddress => "192.168.1.1",
|
203
|
+
:IpAddressAllocationMode => "MANUAL"
|
204
|
+
}
|
205
|
+
]})
|
206
|
+
@vm.configure_network_interfaces(network_config)
|
207
|
+
end
|
208
|
+
|
209
|
+
it "should configure single nic" do
|
210
|
+
network_config = [{:name => 'Default', :ip_address => '192.168.1.1'}]
|
211
|
+
expect(@fog_interface).to receive(:put_network_connection_system_section_vapp).with(@vm_id, {
|
212
|
+
:PrimaryNetworkConnectionIndex => 0,
|
213
|
+
:NetworkConnection => [
|
214
|
+
{
|
215
|
+
:network => 'Default',
|
216
|
+
:needsCustomization => true,
|
217
|
+
:NetworkConnectionIndex => 0,
|
218
|
+
:IsConnected => true,
|
219
|
+
:IpAddress => "192.168.1.1",
|
220
|
+
:IpAddressAllocationMode => "MANUAL"
|
221
|
+
}
|
222
|
+
]})
|
223
|
+
@vm.configure_network_interfaces(network_config)
|
224
|
+
end
|
225
|
+
|
226
|
+
it "should configure multiple nics" do
|
227
|
+
network_config = [
|
228
|
+
{:name => 'Default', :ip_address => '192.168.1.1'},
|
229
|
+
{:name => 'Monitoring', :ip_address => '192.168.2.1'}
|
230
|
+
]
|
231
|
+
|
232
|
+
expect(@fog_interface).to receive(:put_network_connection_system_section_vapp).with(@vm_id, {
|
233
|
+
:PrimaryNetworkConnectionIndex => 0,
|
234
|
+
:NetworkConnection => [
|
235
|
+
{
|
236
|
+
:network => 'Default',
|
237
|
+
:needsCustomization => true,
|
238
|
+
:NetworkConnectionIndex => 0,
|
239
|
+
:IsConnected => true,
|
240
|
+
:IpAddress => "192.168.1.1",
|
241
|
+
:IpAddressAllocationMode => "MANUAL"
|
242
|
+
},
|
243
|
+
{
|
244
|
+
:network => 'Monitoring',
|
245
|
+
:needsCustomization => true,
|
246
|
+
:NetworkConnectionIndex => 1,
|
247
|
+
:IsConnected => true,
|
248
|
+
:IpAddress => "192.168.2.1",
|
249
|
+
:IpAddressAllocationMode => "MANUAL"
|
250
|
+
},
|
251
|
+
]})
|
252
|
+
@vm.configure_network_interfaces(network_config)
|
253
|
+
end
|
254
|
+
|
255
|
+
it "should configure no nics" do
|
256
|
+
network_config = nil
|
257
|
+
expect(@fog_interface).not_to receive(:put_network_connection_system_section_vapp)
|
258
|
+
@vm.configure_network_interfaces(network_config)
|
259
|
+
end
|
260
|
+
|
261
|
+
end
|
262
|
+
|
263
|
+
context "update storage profiles" do
|
264
|
+
it "should update the storage profile" do
|
265
|
+
storage_profile = 'storage_profile_name'
|
266
|
+
vdc_results = [
|
267
|
+
{ :vdcName => 'vdc-test-1' }
|
268
|
+
]
|
269
|
+
mock_vdc_query = double(:query_runner)
|
270
|
+
|
271
|
+
storage_profile_results = [
|
272
|
+
{ :href => 'test-href' }
|
273
|
+
]
|
274
|
+
mock_sp_query = double(:query_runner)
|
275
|
+
|
276
|
+
expect(Vcloud::Core::QueryRunner).to receive(:new).and_return(mock_vdc_query)
|
277
|
+
expect(mock_vdc_query).to receive(:run).with('vApp', :filter => "name==#{@vapp_name}").and_return(vdc_results)
|
278
|
+
expect(Vcloud::Core::QueryRunner).to receive(:new).and_return(mock_sp_query)
|
279
|
+
expect(mock_sp_query).to receive(:run).
|
280
|
+
with('orgVdcStorageProfile', :filter => "name==storage_profile_name;vdcName==vdc-test-1").
|
281
|
+
and_return(storage_profile_results)
|
282
|
+
|
283
|
+
generated_storage_profile = { name: 'storage_profile_name', href: 'test-href' }
|
284
|
+
expect(@fog_interface).to receive(:put_vm).with(@vm_id, @vm_name, { :StorageProfile => generated_storage_profile} ).and_return(true)
|
285
|
+
expect(@vm.update_storage_profile(storage_profile)).to eq(true)
|
286
|
+
end
|
287
|
+
|
288
|
+
it "should raise an error if storage profile is not found" do
|
289
|
+
storage_profile = 'storage_profile_name'
|
290
|
+
vdc_results = [
|
291
|
+
{ :vdcName => 'vdc-test-1' }
|
292
|
+
]
|
293
|
+
mock_vdc_query = double(:query_runner)
|
294
|
+
|
295
|
+
storage_profile_results = []
|
296
|
+
mock_sp_query = double(:query_runner)
|
297
|
+
|
298
|
+
expect(Vcloud::Core::QueryRunner).to receive(:new).and_return(mock_vdc_query)
|
299
|
+
expect(mock_vdc_query).to receive(:run).with('vApp', :filter => "name==#{@vapp_name}").and_return(vdc_results)
|
300
|
+
expect(Vcloud::Core::QueryRunner).to receive(:new).and_return(mock_sp_query)
|
301
|
+
expect(mock_sp_query).to receive(:run).
|
302
|
+
with('orgVdcStorageProfile', :filter => "name==storage_profile_name;vdcName==vdc-test-1").
|
303
|
+
and_return(storage_profile_results)
|
304
|
+
|
305
|
+
expect{ @vm.update_storage_profile(storage_profile) }.to raise_error("storage profile not found" )
|
306
|
+
end
|
307
|
+
|
308
|
+
it "should raise an error if storage profile id is in unexpected format" do
|
309
|
+
storage_profile = 'storage_profile_name'
|
310
|
+
vdc_results = [
|
311
|
+
{ :vdcName => 'vdc-test-1' }
|
312
|
+
]
|
313
|
+
mock_vdc_query = double(:query_runner)
|
314
|
+
|
315
|
+
storage_profile_results = [ { :id => 'test-href' }]
|
316
|
+
mock_sp_query = double(:query_runner)
|
317
|
+
|
318
|
+
expect(Vcloud::Core::QueryRunner).to receive(:new).and_return(mock_vdc_query)
|
319
|
+
expect(mock_vdc_query).to receive(:run).with('vApp', :filter => "name==#{@vapp_name}").and_return(vdc_results)
|
320
|
+
expect(Vcloud::Core::QueryRunner).to receive(:new).and_return(mock_sp_query)
|
321
|
+
expect(mock_sp_query).to receive(:run).
|
322
|
+
with('orgVdcStorageProfile', :filter => "name==storage_profile_name;vdcName==vdc-test-1").
|
323
|
+
and_return(storage_profile_results)
|
324
|
+
|
325
|
+
expect{ @vm.update_storage_profile(storage_profile) }.to raise_error("storage profile not found" )
|
326
|
+
end
|
327
|
+
|
328
|
+
end
|
329
|
+
|
330
|
+
context "#attach_independent_disks" do
|
331
|
+
|
332
|
+
let(:disk1) { double(:disk, :name => 'test-disk-1',
|
335
333
|
:id => '12341234-1234-1234-1234-12345678900')
|
336
|
-
|
337
|
-
|
334
|
+
}
|
335
|
+
let(:disk2) { double(:disk, :name => 'test-disk-2',
|
338
336
|
:id => '12341234-1234-1234-1234-12345678901')
|
339
|
-
|
340
|
-
|
337
|
+
}
|
338
|
+
let(:disk3) { double(:disk, :name => 'test-disk-3',
|
341
339
|
:id => '12341234-1234-1234-1234-12345678902')
|
342
|
-
|
340
|
+
}
|
343
341
|
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
342
|
+
it "handles attaching an array of Independent Disk objects" do
|
343
|
+
vm = Vcloud::Core::Vm.new(@vm_id, @mock_vapp)
|
344
|
+
disk_array = [disk1, disk2, disk3]
|
345
|
+
expect(@fog_interface).to receive(:post_attach_disk).exactly(disk_array.size).times
|
346
|
+
vm.attach_independent_disks(disk_array)
|
347
|
+
end
|
350
348
|
|
351
|
-
|
349
|
+
end
|
352
350
|
|
353
|
-
|
351
|
+
context "#detach_independent_disks" do
|
354
352
|
|
355
|
-
|
353
|
+
let(:disk1) { double(:disk, :name => 'test-disk-1',
|
356
354
|
:id => '12341234-1234-1234-1234-12345678900')
|
357
|
-
|
358
|
-
|
355
|
+
}
|
356
|
+
let(:disk2) { double(:disk, :name => 'test-disk-2',
|
359
357
|
:id => '12341234-1234-1234-1234-12345678901')
|
360
|
-
|
361
|
-
|
358
|
+
}
|
359
|
+
let(:disk3) { double(:disk, :name => 'test-disk-3',
|
362
360
|
:id => '12341234-1234-1234-1234-12345678902')
|
363
|
-
|
364
|
-
|
365
|
-
it "handles detaching an array of Independent Disk objects" do
|
366
|
-
vm = Vm.new(@vm_id, @mock_vapp)
|
367
|
-
disk_array = [disk1, disk2, disk3]
|
368
|
-
expect(@fog_interface).to receive(:post_detach_disk).exactly(disk_array.size).times
|
369
|
-
vm.detach_independent_disks(disk_array)
|
370
|
-
end
|
371
|
-
|
372
|
-
end
|
361
|
+
}
|
373
362
|
|
363
|
+
it "handles detaching an array of Independent Disk objects" do
|
364
|
+
vm = Vcloud::Core::Vm.new(@vm_id, @mock_vapp)
|
365
|
+
disk_array = [disk1, disk2, disk3]
|
366
|
+
expect(@fog_interface).to receive(:post_detach_disk).exactly(disk_array.size).times
|
367
|
+
vm.detach_independent_disks(disk_array)
|
374
368
|
end
|
369
|
+
|
375
370
|
end
|
371
|
+
|
376
372
|
end
|
377
373
|
|