chef-provisioning-vsphere 0.4.2 → 0.5.0

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,3 +1,3 @@
1
1
  module ChefProvisioningVsphere
2
- VERSION = '0.4.2'
2
+ VERSION = '0.5.0'
3
3
  end
@@ -1,31 +1,45 @@
1
1
  require 'uri'
2
2
 
3
3
  module URI
4
- class VsphereUrl < Generic
5
- DEFAULT_PORT = 443
6
- DEFAULT_PATH = '/sdk'
4
+ class VsphereUrl < Generic
5
+ DEFAULT_PORT = 443
6
+ DEFAULT_PATH = '/sdk'
7
7
 
8
- def self.from_config(options)
9
- URI("vsphere://#{options[:host]}:#{options[:port]}#{options[:path]}?use_ssl=#{options[:use_ssl]}&insecure=#{options[:insecure]}")
10
- end
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
- def use_ssl
13
- if query
14
- ssl_query = query.split('&').each.select{|q| q.start_with?('use_ssl=')}.first
15
- ssl_query == 'use_ssl=true'
16
- else
17
- true
18
- end
19
- end
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
- def insecure
22
- if query
23
- insecure_query = query.split('&').each.select{|q| q.start_with?('insecure=')}.first
24
- insecure_query == 'insecure=true'
25
- else
26
- false
27
- end
28
- end
29
- end
30
- @@schemes['VSPHERE'] = VsphereUrl
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
- # 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,
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
- # :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
- # }
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
- include ChefProvisioningVsphere::Helpers
37
+ include ChefProvisioningVsphere::Helpers
38
38
 
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
- @driver = Chef::Provisioning.driver_for_url("vsphere://#{@metal_config[:driver_options][:host]}", @metal_config)
46
- action_handler = Chef::Provisioning::ActionHandler.new
47
- @driver.allocate_machine(action_handler, @machine_spec, @metal_config[:machine_options])
48
- @metal_config[:machine_options][:convergence_options] = {:chef_server => chef_server}
49
- machine = @driver.ready_machine(action_handler, @machine_spec, @metal_config[:machine_options])
50
- @server_id = @machine_spec.location['server_id']
51
- @connection = vim(@metal_config[:driver_options])
52
- @vm = find_vm_by_id(@server_id, @connection)
53
- end
54
- end
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
- context 'when allocating a machine' do
58
+ context 'when allocating a machine' do
58
59
 
59
- it "adds machine to the correct folder" do
60
- expect(@vm.parent.name).to eq(@metal_config[:machine_options][:bootstrap_options][:vm_folder])
61
- end
62
- it "has a matching id with the machine_spec" do
63
- expect(@vm.config.instanceUuid).to eq(@machine_spec.location['server_id'])
64
- end
65
- it "has the correct name" do
66
- now = Time.now.utc
67
- trimmed_name = @vm.config.guestId.start_with?('win') ? @vm_name.byteslice(0,15) : @vm_name
68
- expected_name="#{trimmed_name}.#{@metal_config[:machine_options][:bootstrap_options][:customization_spec][:domain]}"
69
- until (Time.now.utc - now) > 30 || (@vm.guest.hostName == expected_name) do
70
- print "."
71
- sleep 5
72
- end
73
- expect(@vm.guest.hostName).to eq(expected_name)
74
- end
75
- it "has the correct number of CPUs" do
76
- expect(@vm.config.hardware.numCPU).to eq(@metal_config[:machine_options][:bootstrap_options][:num_cpus])
77
- end
78
- it "has the correct amount of memory" do
79
- expect(@vm.config.hardware.memoryMB).to eq(@metal_config[:machine_options][:bootstrap_options][:memory_mb])
80
- end
81
- it "is on the correct networks" do
82
- expect(@vm.network.map {|n| n.name}).to include(@metal_config[:machine_options][:bootstrap_options][:network_name][0])
83
- expect(@vm.network.map {|n| n.name}).to include(@metal_config[:machine_options][:bootstrap_options][:network_name][1])
84
- end
85
- it "is on the correct datastore" do
86
- expect(@vm.datastore[0].name).to eq(@metal_config[:machine_options][:bootstrap_options][:datastore])
87
- end
88
- it "is in the correct resource pool" do
89
- if @metal_config[:machine_options][:bootstrap_options].has_key?(:resource_pool)
90
- expect(@vm.resourcePool.name).to eq(@metal_config[:machine_options][:bootstrap_options][:resource_pool].split('/')[1])
91
- end
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
- context "destroy_machine" do
130
+ context "destroy_machine" do
132
131
 
133
- it "removes the machine" do
134
- Cheffish.honor_local_mode do
135
- chef_server = Cheffish.default_chef_server
136
- driver = Chef::Provisioning.driver_for_url("vsphere://#{@metal_config[:driver_options][:host]}", @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 = { 'driver_url' => driver.driver_url,
140
- 'server_id' => @server_id}
141
- driver.destroy_machine(action_handler, machine_spec, @metal_config[:machine_options])
142
- end
143
- vm = find_vm_by_id(@server_id, @connection)
144
- expect(vm).to eq(nil)
145
- end
146
- end
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 "canonicalize_url" do
4
-
5
- context "when config does not include the properties included in the url" do
6
- metal_config = {
7
- :driver_options => {
8
- :user => 'vmapi',
9
- :password => '<password>'
10
- },
11
- :machine_options => {
12
- :ssh => {
13
- :password => '<password>',
14
- :paranoid => false
15
- },
16
- :bootstrap_options => {
17
- :datacenter => 'QA1',
18
- :template_name => 'UBUNTU-12-64-TEMPLATE',
19
- :vm_folder => 'DLAB',
20
- :num_cpus => 2,
21
- :memory_mb => 4096,
22
- :resource_pool => 'CLSTR02/DLAB'
23
- }
24
- },
25
- :log_level => :debug
26
- }
27
-
28
- let(:results) {
29
- ChefProvisioningVsphere::VsphereDriver.canonicalize_url('vsphere://3.3.3.3:999/crazyapi?use_ssl=false&insecure=true', metal_config)
30
- }
31
-
32
- it "populates the config with correct host from the driver url" do
33
- expect(results[1][:driver_options][:connect_options][:host]).to eq('3.3.3.3')
34
- end
35
- it "populates the config with correct port from the driver url" do
36
- expect(results[1][:driver_options][:connect_options][:port]).to eq(999)
37
- end
38
- it "populates the config with correct path from the driver url" do
39
- expect(results[1][:driver_options][:connect_options][:path]).to eq('/crazyapi')
40
- end
41
- it "populates the config with correct use_ssl setting from the driver url" do
42
- expect(results[1][:driver_options][:connect_options][:use_ssl]).to eq(false)
43
- end
44
- it "populates the config with correct insecure setting from the driver url" do
45
- expect(results[1][:driver_options][:connect_options][:insecure]).to eq(true)
46
- end
47
- end
48
-
49
- context "when config keys are stringified" do
50
- metal_config = {
51
- 'driver_options' => {
52
- 'user' => 'vmapi',
53
- 'password' => '<password>'
54
- },
55
- 'machine_options' => {
56
- 'ssh' => {
57
- 'password' => '<password>'
58
- },
59
- 'bootstrap_options' => {
60
- 'datacenter' => 'QA1'
61
- }
62
- }
63
- }
64
-
65
- let(:results) {
66
- ChefProvisioningVsphere::VsphereDriver.canonicalize_url('vsphere://3.3.3.3:999/crazyapi?use_ssl=false&insecure=true', metal_config)
67
- }
68
-
69
- it "will symbolize user" do
70
- expect(results[1][:driver_options][:connect_options][:user]).to eq('vmapi')
71
- end
72
- it "will symbolize password" do
73
- expect(results[1][:driver_options][:connect_options][:password]).to eq('<password>')
74
- end
75
- it "will symbolize ssh password" do
76
- expect(results[1][:machine_options][:ssh][:password]).to eq('<password>')
77
- end
78
- it "will symbolize ssh bootstrap options" do
79
- expect(results[1][:machine_options][:bootstrap_options][:datacenter]).to eq('QA1')
80
- end
81
- end
82
-
83
- context "when no url is in the config" do
84
- metal_config = {
85
- :driver_options => {
86
- :user => 'vmapi',
87
- :password => '<password>',
88
- :host => '4.4.4.4',
89
- :port => 888,
90
- :path => '/yoda',
91
- :use_ssl => 'false',
92
- :insecure => 'true'
93
- },
94
- :machine_options => {
95
- :ssh => {
96
- :password => '<password>',
97
- :paranoid => false
98
- },
99
- :bootstrap_options => {
100
- :datacenter => 'QA1',
101
- :template_name => 'UBUNTU-12-64-TEMPLATE',
102
- :vm_folder => 'DLAB',
103
- :num_cpus => 2,
104
- :memory_mb => 4096,
105
- :resource_pool => 'CLSTR02/DLAB'
106
- }
107
- },
108
- :log_level => :debug
109
- }
110
-
111
- let(:results) {
112
- ChefProvisioningVsphere::VsphereDriver.canonicalize_url(nil, metal_config)
113
- }
114
-
115
- it "creates the correct driver url from config settings" do
116
- expect(results[0]).to eq('vsphere://4.4.4.4:888/yoda?use_ssl=false&insecure=true')
117
- end
118
- end
119
-
120
- context "when no url is in the config and config is missing defaulted values" do
121
- metal_config = {
122
- :driver_options => {
123
- :user => 'vmapi',
124
- :password => '<password>',
125
- :host => '4.4.4.4'
126
- },
127
- :machine_options => {
128
- :bootstrap_options => {
129
- :datacenter => 'QA1',
130
- :template_name => 'UBUNTU-12-64-TEMPLATE',
131
- :vm_folder => 'DLAB',
132
- :num_cpus => 2,
133
- :memory_mb => 4096,
134
- :resource_pool => 'CLSTR02/DLAB',
135
- :ssh => {
136
- :password => '<password>',
137
- :paranoid => false
138
- }
139
- }
140
- },
141
- :log_level => :debug
142
- }
143
-
144
- let(:results) {
145
- ChefProvisioningVsphere::VsphereDriver.canonicalize_url(nil, metal_config)
146
- }
147
-
148
- it "creates the correct driver url from default settings" do
149
- expect(results[0]).to eq('vsphere://4.4.4.4/sdk?use_ssl=true&insecure=false')
150
- end
151
- it "populates the config with correct port from default settings" do
152
- expect(results[1][:driver_options][:connect_options][:port]).to eq(443)
153
- end
154
- it "populates the config with correct path from default settings" do
155
- expect(results[1][:driver_options][:connect_options][:path]).to eq('/sdk')
156
- end
157
- it "populates the config with correct use_ssl setting from default settings" do
158
- expect(results[1][:driver_options][:connect_options][:use_ssl]).to eq(true)
159
- end
160
- it "populates the config with correct insecure setting from default settings" do
161
- expect(results[1][:driver_options][:connect_options][:insecure]).to eq(false)
162
- end
163
- it "populates the config with correct ssh port from default settings" do
164
- expect(results[1][:machine_options][:bootstrap_options][:ssh][:port]).to eq(22)
165
- end
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