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