chef-provisioning-vsphere 0.4.2 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +1 -1
- data/LICENSE +20 -0
- data/chef-provisioning-vsphere.gemspec +1 -1
- data/lib/chef/provisioning/vsphere_driver.rb +4 -3
- data/lib/chef/provisioning/vsphere_driver/driver.rb +288 -212
- data/lib/chef/provisioning/vsphere_driver/version.rb +1 -1
- data/lib/chef/provisioning/vsphere_driver/vsphere_url.rb +39 -25
- data/spec/integration_tests/vsphere_driver_spec.rb +135 -133
- data/spec/unit_tests/VsphereDriver_spec.rb +163 -203
- data/spec/unit_tests/VsphereUrl_spec.rb +7 -1
- metadata +5 -4
@@ -1,31 +1,45 @@
|
|
1
1
|
require 'uri'
|
2
2
|
|
3
3
|
module URI
|
4
|
-
|
5
|
-
|
6
|
-
|
4
|
+
class VsphereUrl < Generic
|
5
|
+
DEFAULT_PORT = 443
|
6
|
+
DEFAULT_PATH = '/sdk'
|
7
7
|
|
8
|
-
|
9
|
-
|
10
|
-
|
8
|
+
def self.from_config(options)
|
9
|
+
parts = []
|
10
|
+
parts << 'vsphere://'
|
11
|
+
parts << options[:host]
|
12
|
+
parts << ':'
|
13
|
+
parts << (options[:port] || DEFAULT_PORT)
|
14
|
+
parts << (options[:path] || DEFAULT_PATH)
|
15
|
+
parts << '?use_ssl='
|
16
|
+
parts << (options[:use_ssl] == false ? false : true)
|
17
|
+
parts << '&insecure='
|
18
|
+
parts << (options[:insecure] || false)
|
19
|
+
URI parts.join
|
20
|
+
end
|
11
21
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
22
|
+
def use_ssl
|
23
|
+
if query
|
24
|
+
ssl_query = query.split('&').each.select do |q|
|
25
|
+
q.start_with?('use_ssl=')
|
26
|
+
end.first
|
27
|
+
ssl_query == 'use_ssl=true'
|
28
|
+
else
|
29
|
+
true
|
30
|
+
end
|
31
|
+
end
|
20
32
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
end
|
33
|
+
def insecure
|
34
|
+
if query
|
35
|
+
insecure_query = query.split('&').each.select do |q|
|
36
|
+
q.start_with?('insecure=')
|
37
|
+
end.first
|
38
|
+
insecure_query == 'insecure=true'
|
39
|
+
else
|
40
|
+
false
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
@@schemes['VSPHERE'] = VsphereUrl
|
45
|
+
end
|
@@ -1,147 +1,149 @@
|
|
1
1
|
require 'chef/provisioning/vsphere_driver'
|
2
2
|
require 'chef/provisioning/machine_spec'
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
# :create_timeout => 600,
|
4
|
+
# A file named config.rb in the same directory as this spec file
|
5
|
+
# must exist containing the driver options to use for the test.
|
6
|
+
# Here is an example:
|
7
|
+
# {
|
8
|
+
# :driver_options => {
|
9
|
+
# :host => '213.45.67.88',
|
10
|
+
# :user => 'vmapi',
|
11
|
+
# :password => 'SuperSecureP@ssw0rd',
|
12
|
+
# :insecure => true
|
13
|
+
# },
|
14
|
+
# :machine_options => {
|
15
|
+
# :start_timeout => 600,
|
16
|
+
# :create_timeout => 600,
|
17
17
|
# :bootstrap_options => {
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
18
|
+
# :datacenter => 'QA1',
|
19
|
+
# :template_name => 'UBUNTU-12-64-TEMPLATE',
|
20
|
+
# :vm_folder => 'DLAB',
|
21
|
+
# :num_cpus => 2,
|
22
|
+
# :network_name => 'vlan152_172.21.152',
|
23
|
+
# :memory_mb => 4096,
|
24
|
+
# :resource_pool => 'CLSTR02/DLAB',
|
25
|
+
# :ssh => {
|
26
|
+
# :user => 'root',
|
27
|
+
# :password => 'SuperSecureP@ssw0rd',
|
28
|
+
# :paranoid => false,
|
29
|
+
# :port => 22
|
30
|
+
# },
|
31
|
+
# :convergence_options => {}
|
32
|
+
# }
|
33
|
+
# }
|
34
|
+
# }
|
35
35
|
|
36
36
|
describe "vsphere_driver" do
|
37
|
-
|
37
|
+
include ChefProvisioningVsphere::Helpers
|
38
38
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
39
|
+
before :all do
|
40
|
+
@vm_name = "cmvd-test-#{SecureRandom.hex}"
|
41
|
+
@metal_config = eval File.read(File.expand_path('../config.rb', __FILE__))
|
42
|
+
Cheffish.honor_local_mode do
|
43
|
+
chef_server = Cheffish.default_chef_server
|
44
|
+
@machine_spec = Chef::Provisioning.chef_managed_entry_store(chef_server).new_entry(:machine, @vm_name)
|
45
|
+
url = URI::VsphereUrl.from_config(@metal_config[:driver_options]).to_s
|
46
|
+
@driver = Chef::Provisioning.driver_for_url(url, @metal_config)
|
47
|
+
action_handler = Chef::Provisioning::ActionHandler.new
|
48
|
+
@driver.allocate_machine(action_handler, @machine_spec, @metal_config[:machine_options])
|
49
|
+
@metal_config[:machine_options][:convergence_options] = {:chef_server => chef_server}
|
50
|
+
machine = @driver.ready_machine(action_handler, @machine_spec, @metal_config[:machine_options])
|
51
|
+
@server_id = @machine_spec.location['server_id']
|
52
|
+
@connection = vim(@metal_config[:driver_options])
|
53
|
+
@vm = find_vm_by_id(@server_id, @connection)
|
54
|
+
end
|
55
|
+
end
|
55
56
|
|
56
57
|
|
57
|
-
|
58
|
+
context 'when allocating a machine' do
|
58
59
|
|
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
|
-
end
|
93
|
-
it "is in the correct host" do
|
94
|
-
if @metal_config[:machine_options][:bootstrap_options].has_key?(:host)
|
95
|
-
expect(@vm.runtime.host.name).to eq(@metal_config[:machine_options][:bootstrap_options][:host].split('/')[1])
|
96
|
-
end
|
97
|
-
end
|
98
|
-
it "is in the correct cluster" do
|
99
|
-
if @metal_config[:machine_options][:bootstrap_options].has_key?(:resource_pool)
|
100
|
-
expect(@vm.resourcePool.owner.name).to eq(@metal_config[:machine_options][:bootstrap_options][:resource_pool].split('/')[0])
|
101
|
-
end
|
102
|
-
end
|
103
|
-
it "is in the correct datacenter" do
|
104
|
-
expect(@connection.serviceInstance.find_datacenter(@metal_config[:machine_options][:bootstrap_options][:datacenter]).find_vm("#{@vm.parent.name}/#{@vm_name}")).not_to eq(nil)
|
105
|
-
end
|
106
|
-
it "has an added disk of the correct size" do
|
107
|
-
disk_count = @vm.disks.count
|
108
|
-
expect(@vm.disks[disk_count-1].capacityInKB).to eq(@metal_config[:machine_options][:bootstrap_options][:additional_disk_size_gb] * 1024 * 1024)
|
109
|
-
end
|
110
|
-
it "has hot add cpu enabled" do
|
111
|
-
expect(@vm.config.cpuHotAddEnabled).to eq(true)
|
112
|
-
end
|
113
|
-
it "has hot remove cpu enabled" do
|
114
|
-
expect(@vm.config.cpuHotRemoveEnabled).to eq(true)
|
115
|
-
end
|
116
|
-
it "has hot add memory enabled" do
|
117
|
-
expect(@vm.config.memoryHotAddEnabled).to eq(true)
|
118
|
-
end
|
119
|
-
it "has the correct IP address" do
|
120
|
-
if @vm.guest.toolsRunningStatus != "guestToolsRunning"
|
121
|
-
now = Time.now.utc
|
122
|
-
until (Time.now.utc - now) > 30 || (@vm.guest.toolsRunningStatus == "guestToolsRunning" && @vm.guest.net.count == 2 && @vm.guest.net[1].ipAddress[1] == @metal_config[:machine_options][:bootstrap_options][:customization_spec][:ipsettings][:ip]) do
|
123
|
-
print "."
|
124
|
-
sleep 5
|
125
|
-
end
|
126
|
-
end
|
127
|
-
expect(@vm.guest.net.map { |net| net.ipAddress}.flatten).to include(@metal_config[:machine_options][:bootstrap_options][:customization_spec][:ipsettings][:ip])
|
128
|
-
end
|
60
|
+
it "adds machine to the correct folder" do
|
61
|
+
expect(@vm.parent.name).to eq(@metal_config[:machine_options][:bootstrap_options][:vm_folder])
|
62
|
+
end
|
63
|
+
it "has a matching id with the machine_spec" do
|
64
|
+
expect(@vm.config.instanceUuid).to eq(@machine_spec.location['server_id'])
|
65
|
+
end
|
66
|
+
it "has the correct name" do
|
67
|
+
now = Time.now.utc
|
68
|
+
trimmed_name = @vm.config.guestId.start_with?('win') ? @vm_name.byteslice(0,15) : @vm_name
|
69
|
+
expected_name="#{trimmed_name}.#{@metal_config[:machine_options][:bootstrap_options][:customization_spec][:domain]}"
|
70
|
+
until (Time.now.utc - now) > 30 || (@vm.guest.hostName == expected_name) do
|
71
|
+
print "."
|
72
|
+
sleep 5
|
73
|
+
end
|
74
|
+
expect(@vm.guest.hostName).to eq(expected_name)
|
75
|
+
end
|
76
|
+
it "has the correct number of CPUs" do
|
77
|
+
expect(@vm.config.hardware.numCPU).to eq(@metal_config[:machine_options][:bootstrap_options][:num_cpus])
|
78
|
+
end
|
79
|
+
it "has the correct amount of memory" do
|
80
|
+
expect(@vm.config.hardware.memoryMB).to eq(@metal_config[:machine_options][:bootstrap_options][:memory_mb])
|
81
|
+
end
|
82
|
+
it "is on the correct networks" do
|
83
|
+
expect(@vm.network.map {|n| n.name}).to include(@metal_config[:machine_options][:bootstrap_options][:network_name][0])
|
84
|
+
expect(@vm.network.map {|n| n.name}).to include(@metal_config[:machine_options][:bootstrap_options][:network_name][1])
|
85
|
+
end
|
86
|
+
it "is on the correct datastore" do
|
87
|
+
expect(@vm.datastore[0].name).to eq(@metal_config[:machine_options][:bootstrap_options][:datastore])
|
88
|
+
end
|
89
|
+
it "is in the correct resource pool" do
|
90
|
+
if @metal_config[:machine_options][:bootstrap_options].has_key?(:resource_pool)
|
91
|
+
expect(@vm.resourcePool.name).to eq(@metal_config[:machine_options][:bootstrap_options][:resource_pool].split('/')[1])
|
92
|
+
end
|
129
93
|
end
|
94
|
+
it "is in the correct host" do
|
95
|
+
if @metal_config[:machine_options][:bootstrap_options].has_key?(:host)
|
96
|
+
expect(@vm.runtime.host.name).to eq(@metal_config[:machine_options][:bootstrap_options][:host].split('/')[1])
|
97
|
+
end
|
98
|
+
end
|
99
|
+
it "is in the correct cluster" do
|
100
|
+
if @metal_config[:machine_options][:bootstrap_options].has_key?(:resource_pool)
|
101
|
+
expect(@vm.resourcePool.owner.name).to eq(@metal_config[:machine_options][:bootstrap_options][:resource_pool].split('/')[0])
|
102
|
+
end
|
103
|
+
end
|
104
|
+
it "is in the correct datacenter" do
|
105
|
+
expect(@connection.serviceInstance.find_datacenter(@metal_config[:machine_options][:bootstrap_options][:datacenter]).find_vm("#{@vm.parent.name}/#{@vm_name}")).not_to eq(nil)
|
106
|
+
end
|
107
|
+
it "has an added disk of the correct size" do
|
108
|
+
disk_count = @vm.disks.count
|
109
|
+
expect(@vm.disks[disk_count-1].capacityInKB).to eq(@metal_config[:machine_options][:bootstrap_options][:additional_disk_size_gb] * 1024 * 1024)
|
110
|
+
end
|
111
|
+
it "has hot add cpu enabled" do
|
112
|
+
expect(@vm.config.cpuHotAddEnabled).to eq(true)
|
113
|
+
end
|
114
|
+
it "has hot remove cpu enabled" do
|
115
|
+
expect(@vm.config.cpuHotRemoveEnabled).to eq(true)
|
116
|
+
end
|
117
|
+
it "has hot add memory enabled" do
|
118
|
+
expect(@vm.config.memoryHotAddEnabled).to eq(true)
|
119
|
+
end
|
120
|
+
it "has the correct IP address" do
|
121
|
+
now = Time.now.utc
|
122
|
+
until (Time.now.utc - now) > 30 || (@vm.guest.toolsRunningStatus == "guestToolsRunning" && @vm.guest.net.count == 2 && @vm.guest.net[1].ipAddress[1] == @metal_config[:machine_options][:bootstrap_options][:customization_spec][:ipsettings][:ip]) do
|
123
|
+
print "."
|
124
|
+
sleep 5
|
125
|
+
end
|
126
|
+
expect(@vm.guest.net.map { |net| net.ipAddress}.flatten).to include(@metal_config[:machine_options][:bootstrap_options][:customization_spec][:ipsettings][:ip])
|
127
|
+
end
|
128
|
+
end
|
130
129
|
|
131
|
-
|
130
|
+
context "destroy_machine" do
|
132
131
|
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
132
|
+
it "removes the machine" do
|
133
|
+
Cheffish.honor_local_mode do
|
134
|
+
chef_server = Cheffish.default_chef_server
|
135
|
+
url = URI::VsphereUrl.from_config(@metal_config[:driver_options]).to_s
|
136
|
+
driver = Chef::Provisioning.driver_for_url(url, @metal_config)
|
137
|
+
action_handler = Chef::Provisioning::ActionHandler.new
|
138
|
+
machine_spec = Chef::Provisioning.chef_managed_entry_store(chef_server).new_entry(:machine, @vm_name)
|
139
|
+
machine_spec.location = {
|
140
|
+
'driver_url' => driver.driver_url,
|
141
|
+
'server_id' => @server_id
|
142
|
+
}
|
143
|
+
driver.destroy_machine(action_handler, machine_spec, @metal_config[:machine_options])
|
144
|
+
end
|
145
|
+
vm = find_vm_by_id(@server_id, @connection)
|
146
|
+
expect(vm).to eq(nil)
|
147
|
+
end
|
148
|
+
end
|
147
149
|
end
|
@@ -1,206 +1,166 @@
|
|
1
1
|
require 'chef/provisioning/vsphere_driver'
|
2
2
|
|
3
|
-
describe
|
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
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
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
|
-
end
|
167
|
-
|
168
|
-
context "when missing host" do
|
169
|
-
metal_config = {
|
170
|
-
:driver_options => {
|
171
|
-
:user => 'vmapi',
|
172
|
-
:password => '<password>',
|
173
|
-
}
|
174
|
-
}
|
175
|
-
|
176
|
-
it "should raise an error" do
|
177
|
-
expect{ChefProvisioningVsphere::VsphereDriver.canonicalize_url(nil,metal_config)}.to raise_error(RuntimeError)
|
178
|
-
end
|
179
|
-
end
|
180
|
-
|
181
|
-
context "when missing user" do
|
182
|
-
metal_config = {
|
183
|
-
:driver_options => {
|
184
|
-
:host => 'host',
|
185
|
-
:password => '<password>',
|
186
|
-
}
|
187
|
-
}
|
188
|
-
|
189
|
-
it "should raise an error" do
|
190
|
-
expect{ChefProvisioningVsphere::VsphereDriver.canonicalize_url(nil,metal_config)}.to raise_error(RuntimeError)
|
191
|
-
end
|
192
|
-
end
|
193
|
-
|
194
|
-
context "when missing password" do
|
195
|
-
metal_config = {
|
196
|
-
:driver_options => {
|
197
|
-
:host => 'host',
|
198
|
-
:user => 'user',
|
199
|
-
}
|
200
|
-
}
|
201
|
-
|
202
|
-
it "should raise an error" do
|
203
|
-
expect{ChefProvisioningVsphere::VsphereDriver.canonicalize_url(nil,metal_config)}.to raise_error(RuntimeError)
|
204
|
-
end
|
205
|
-
end
|
3
|
+
describe ChefProvisioningVsphere::VsphereDriver do
|
4
|
+
subject do
|
5
|
+
Chef::Provisioning.driver_for_url(
|
6
|
+
'vsphere://3.3.3.3:999/crazyapi?use_ssl=false&insecure=true',
|
7
|
+
metal_config
|
8
|
+
)
|
9
|
+
end
|
10
|
+
|
11
|
+
context "when config does not include the properties included in the url" do
|
12
|
+
let(:metal_config) do
|
13
|
+
{
|
14
|
+
:driver_options => {
|
15
|
+
:user => 'vmapi',
|
16
|
+
:password => '<password>'
|
17
|
+
},
|
18
|
+
:machine_options => {
|
19
|
+
:ssh => {
|
20
|
+
:password => '<password>',
|
21
|
+
:paranoid => false
|
22
|
+
},
|
23
|
+
:bootstrap_options => {
|
24
|
+
:datacenter => 'QA1',
|
25
|
+
:template_name => 'UBUNTU-12-64-TEMPLATE',
|
26
|
+
:vm_folder => 'DLAB',
|
27
|
+
:num_cpus => 2,
|
28
|
+
:memory_mb => 4096,
|
29
|
+
:resource_pool => 'CLSTR02/DLAB'
|
30
|
+
}
|
31
|
+
},
|
32
|
+
:log_level => :debug
|
33
|
+
}
|
34
|
+
end
|
35
|
+
|
36
|
+
it "populates the connect options with correct host from the driver url" do
|
37
|
+
expect(subject.connect_options[:host]).to eq('3.3.3.3')
|
38
|
+
end
|
39
|
+
it "populates the connect options with correct port from the driver url" do
|
40
|
+
expect(subject.connect_options[:port]).to eq(999)
|
41
|
+
end
|
42
|
+
it "populates the connect options with correct path from the driver url" do
|
43
|
+
expect(subject.connect_options[:path]).to eq('/crazyapi')
|
44
|
+
end
|
45
|
+
it "populates the connect options with correct use_ssl setting from the driver url" do
|
46
|
+
expect(subject.connect_options[:use_ssl]).to eq(false)
|
47
|
+
end
|
48
|
+
it "populates the connect options with correct insecure setting from the driver url" do
|
49
|
+
expect(subject.connect_options[:insecure]).to eq(true)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
context "when config keys are stringified" do
|
54
|
+
let(:metal_config) do
|
55
|
+
{
|
56
|
+
'driver_options' => {
|
57
|
+
'user' => 'vmapi',
|
58
|
+
'password' => '<driver_password>'
|
59
|
+
},
|
60
|
+
'bootstrap_options' => {
|
61
|
+
'machine_options' => {
|
62
|
+
'datacenter' => 'QA1',
|
63
|
+
'ssh' => {
|
64
|
+
'password' => '<machine_password>'
|
65
|
+
}
|
66
|
+
}
|
67
|
+
}
|
68
|
+
}
|
69
|
+
end
|
70
|
+
|
71
|
+
it "will symbolize user" do
|
72
|
+
expect(subject.connect_options[:user]).to eq('vmapi')
|
73
|
+
end
|
74
|
+
it "will symbolize password" do
|
75
|
+
expect(subject.connect_options[:password]).to eq('<driver_password>')
|
76
|
+
end
|
77
|
+
it "will symbolize ssh password" do
|
78
|
+
expect(subject.config[:bootstrap_options][:machine_options][:ssh][:password]).to eq('<machine_password>')
|
79
|
+
end
|
80
|
+
it "will symbolize ssh bootstrap options" do
|
81
|
+
expect(subject.config[:bootstrap_options][:machine_options][:datacenter]).to eq('QA1')
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
describe 'canonicalize_url' do
|
86
|
+
context "when no url is in the config" do
|
87
|
+
let(:metal_config) do
|
88
|
+
{
|
89
|
+
:driver_options => {
|
90
|
+
:user => 'vmapi',
|
91
|
+
:password => '<password>',
|
92
|
+
:host => '4.4.4.4',
|
93
|
+
:port => 888,
|
94
|
+
:path => '/yoda',
|
95
|
+
:use_ssl => false,
|
96
|
+
:insecure => true
|
97
|
+
},
|
98
|
+
:machine_options => {
|
99
|
+
:ssh => {
|
100
|
+
:password => '<password>',
|
101
|
+
:paranoid => false
|
102
|
+
},
|
103
|
+
:bootstrap_options => {
|
104
|
+
:datacenter => 'QA1',
|
105
|
+
:template_name => 'UBUNTU-12-64-TEMPLATE',
|
106
|
+
:vm_folder => 'DLAB',
|
107
|
+
:num_cpus => 2,
|
108
|
+
:memory_mb => 4096,
|
109
|
+
:resource_pool => 'CLSTR02/DLAB'
|
110
|
+
}
|
111
|
+
},
|
112
|
+
:log_level => :debug
|
113
|
+
}
|
114
|
+
end
|
115
|
+
|
116
|
+
subject do
|
117
|
+
ChefProvisioningVsphere::VsphereDriver.canonicalize_url(
|
118
|
+
nil,
|
119
|
+
metal_config
|
120
|
+
)
|
121
|
+
end
|
122
|
+
|
123
|
+
it "creates the correct driver url from config settings" do
|
124
|
+
expect(subject[0]).to eq('vsphere://4.4.4.4:888/yoda?use_ssl=false&insecure=true')
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
context "when no url is in the config and config is missing defaulted values" do
|
129
|
+
let(:metal_config) do
|
130
|
+
{
|
131
|
+
:driver_options => {
|
132
|
+
:user => 'vmapi',
|
133
|
+
:password => '<password>',
|
134
|
+
:host => '4.4.4.4'
|
135
|
+
},
|
136
|
+
:machine_options => {
|
137
|
+
:bootstrap_options => {
|
138
|
+
:datacenter => 'QA1',
|
139
|
+
:template_name => 'UBUNTU-12-64-TEMPLATE',
|
140
|
+
:vm_folder => 'DLAB',
|
141
|
+
:num_cpus => 2,
|
142
|
+
:memory_mb => 4096,
|
143
|
+
:resource_pool => 'CLSTR02/DLAB',
|
144
|
+
:ssh => {
|
145
|
+
:password => '<password>',
|
146
|
+
:paranoid => false
|
147
|
+
}
|
148
|
+
}
|
149
|
+
},
|
150
|
+
:log_level => :debug
|
151
|
+
}
|
152
|
+
end
|
153
|
+
|
154
|
+
subject do
|
155
|
+
ChefProvisioningVsphere::VsphereDriver.canonicalize_url(
|
156
|
+
nil,
|
157
|
+
metal_config
|
158
|
+
)
|
159
|
+
end
|
160
|
+
|
161
|
+
it "creates the correct driver url from default settings" do
|
162
|
+
expect(subject[0]).to eq('vsphere://4.4.4.4/sdk?use_ssl=true&insecure=false')
|
163
|
+
end
|
164
|
+
end
|
165
|
+
end
|
206
166
|
end
|