clc-chef-metal-vsphere 0.3.67 → 0.3.77

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 34ad1c100d44092d3dd2eca5f1f39656da3a4980
4
- data.tar.gz: 4f62daeff98060413fc99a3af19151d25b503be9
3
+ metadata.gz: 70b737e146fc06425bc7e06afb4b0e0da717adbb
4
+ data.tar.gz: ef0e6156688e989f3d3d26f0cbdf0fe5dd6c6442
5
5
  SHA512:
6
- metadata.gz: 115c2b68dcb87a8f8b4aa19d221be1b07fc72df46a5f332db4b5f19890558c4de6c20b631b4c0e716684270969ede47557d9a32017a45e99b4fe87fbb41c5020
7
- data.tar.gz: 5537d58010da22da92967c884294c1c191f94553450e8710bb118412e768dc139a5ccafdfd8d35c9fa3b6bfd123a3e9fde172db8d7656fe555d6c225d4fb67e7
6
+ metadata.gz: ad9b91f224f03b815e1360aab2eeac730cf1aa1a59a425f3799efe8617a08ce476c8837c7ebbb327d391ba0ee0c42098c6f279a3cf650f0edd7420d94363d1f2
7
+ data.tar.gz: bb6ea68e822464035932b3b7f464b5505d190e0724dfe3d42119ee93b66a2eec784c2acbb9c08700a16a4a2b9fbf9d68deff07a108f97383eed2536bde1785f1
data/Rakefile CHANGED
@@ -1,30 +1,17 @@
1
- require 'bundler'
2
1
  require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
3
 
4
- def gem_server
5
- @gem_server ||= ENV['GEM_SERVER'] || 'rubygems.org'
6
- end
7
-
8
- module Bundler
9
- class GemHelper
10
- unless gem_server == 'rubygems.org'
11
- unless method_defined?(:rubygem_push)
12
- raise NoMethodError, "Monkey patching Bundler::GemHelper#rubygem_push failed: did the Bundler API change???"
13
- end
14
-
15
- def rubygem_push(path)
16
- print "Username: "
17
- username = STDIN.gets.chomp
18
- print "Password: "
19
- password = STDIN.gets.chomp
4
+ $:.unshift(File.dirname(__FILE__) + '/lib')
5
+ require 'chef_metal_vsphere/version'
20
6
 
21
- gem_server_url = "https://#{username}:#{password}@#{gem_server}/"
22
- sh %{gem push #{path} --host #{gem_server_url}}
7
+ RSpec::Core::RakeTask.new(:unit) do |task|
8
+ task.pattern = 'spec/unit_tests/*_spec.rb'
9
+ task.rspec_opts = ['--color', '-f documentation']
10
+ end
23
11
 
24
- Bundler.ui.confirm "Pushed #{name} #{version} to #{gem_server}"
25
- end
12
+ RSpec::Core::RakeTask.new(:integration) do |task|
13
+ task.pattern = 'spec/integration_tests/*_spec.rb'
14
+ task.rspec_opts = ['--color', '-f documentation']
15
+ end
26
16
 
27
- puts "Monkey patched Bundler::GemHelper#rubygem_push to push to #{gem_server}."
28
- end
29
- end
30
- end
17
+ task :default => [:unit]
@@ -1,3 +1,3 @@
1
1
  module ChefMetalVsphere
2
- VERSION = '0.3.67'
2
+ VERSION = '0.3.77'
3
3
  end
@@ -286,9 +286,14 @@ module ChefMetalVsphere
286
286
  vm = vm_for(machine_spec)
287
287
  if vm
288
288
  action_handler.perform_action "Delete VM [#{vm.parent.name}/#{vm.name}]" do
289
- vm.PowerOffVM_Task.wait_for_completion unless vm.runtime.powerState == 'poweredOff'
290
- vm.Destroy_Task.wait_for_completion
291
- machine_spec.location = nil
289
+ begin
290
+ vm.PowerOffVM_Task.wait_for_completion unless vm.runtime.powerState == 'poweredOff'
291
+ vm.Destroy_Task.wait_for_completion
292
+ rescue RbVmomi::Fault => fault
293
+ raise fault unless fault.fault.class.wsdl_name == "ManagedObjectNotFound"
294
+ ensure
295
+ machine_spec.location = nil
296
+ end
292
297
  end
293
298
  end
294
299
  strategy = convergence_strategy_for(machine_spec, machine_options)
@@ -339,7 +344,7 @@ module ChefMetalVsphere
339
344
  Chef::Log.info "Ubuntu version 12.04 or greater. Need to patch DNS."
340
345
  interfaces_file = "/etc/network/interfaces"
341
346
  nameservers = bootstrap_options[:customization_spec][:ipsettings][:dnsServerList].join(' ')
342
- machine.execute_always("if ! cat #{interfaces_file} | grep -q dns-search ; then echo 'dns-search #{machine_spec.name}' >> #{interfaces_file} ; fi")
347
+ machine.execute_always("if ! cat #{interfaces_file} | grep -q dns-search ; then echo 'dns-search #{bootstrap_options[:customization_spec][:domain]}' >> #{interfaces_file} ; fi")
343
348
  machine.execute_always("if ! cat #{interfaces_file} | grep -q dns-nameservers ; then echo 'dns-nameservers #{nameservers}' >> #{interfaces_file} ; fi")
344
349
  machine.execute_always('/etc/init.d/networking restart')
345
350
  machine.execute_always('apt-get -qq update')
@@ -489,7 +494,13 @@ module ChefMetalVsphere
489
494
  bootstrap_options = bootstrap_options_for(machine_spec, machine_options)
490
495
  ssh_options = bootstrap_options[:ssh]
491
496
  remote_host = machine_spec.location['ipaddress'] || ip_for(bootstrap_options, vm)
492
- winrm_options = {:user => "#{ssh_options[:user]}", :pass => ssh_options[:password], :basic_auth_only => true}
497
+
498
+ winrm_options = {:user => "#{ssh_options[:user]}", :pass => ssh_options[:password]}
499
+ if ssh_options[:user].include?("\\")
500
+ winrm_options[:disable_sspi] = true
501
+ else
502
+ winrm_options[:basic_auth_only] = true
503
+ end
493
504
 
494
505
  ChefMetal::Transport::WinRM.new("http://#{remote_host}:5985/wsman", :plaintext, winrm_options, config)
495
506
  end
@@ -106,23 +106,22 @@ module ChefMetalVsphere
106
106
  end
107
107
 
108
108
  def dc(dc_name)
109
- vim.serviceInstance.find_datacenter(dc_name) or raise("vSphere Datacenter not found [#{datacenter}]")
109
+ vim.serviceInstance.find_datacenter(dc_name) or raise("vSphere Datacenter not found [#{dc_name}]")
110
110
  end
111
111
 
112
- def network_adapter_for(operation, network_name, network_label, device_key)
113
- nic_backing_info = RbVmomi::VIM::VirtualEthernetCardNetworkBackingInfo(:deviceName => network_name)
114
- connectable = RbVmomi::VIM::VirtualDeviceConnectInfo(
115
- :allowGuestControl => true,
116
- :connected => true,
117
- :startConnected => true)
118
- device = RbVmomi::VIM::VirtualVmxnet3(
119
- :backing => nic_backing_info,
120
- :deviceInfo => RbVmomi::VIM::Description(:label => network_label, :summary => network_name),
121
- :key => device_key,
122
- :connectable => connectable)
123
- RbVmomi::VIM::VirtualDeviceConfigSpec(
124
- :operation => operation,
125
- :device => device)
112
+ def network_adapter_for(operation, network_name, network_label, device_key, backing_info)
113
+ connectable = RbVmomi::VIM::VirtualDeviceConnectInfo(
114
+ :allowGuestControl => true,
115
+ :connected => true,
116
+ :startConnected => true)
117
+ device = RbVmomi::VIM::VirtualVmxnet3(
118
+ :backing => backing_info,
119
+ :deviceInfo => RbVmomi::VIM::Description(:label => network_label, :summary => network_name),
120
+ :key => device_key,
121
+ :connectable => connectable)
122
+ RbVmomi::VIM::VirtualDeviceConfigSpec(
123
+ :operation => operation,
124
+ :device => device)
126
125
  end
127
126
 
128
127
  def find_ethernet_cards_for(vm)
@@ -182,8 +181,8 @@ module ChefMetalVsphere
182
181
  deviceAdditions, changes = network_device_changes(action_handler, vm_template, options)
183
182
 
184
183
  if deviceAdditions.count > 0
185
- current_networks = find_ethernet_cards_for(vm).map{|card| card.backing.deviceName}
186
- new_devices = deviceAdditions.select { |device| !current_networks.include?(device.device.backing.deviceName)}
184
+ current_networks = find_ethernet_cards_for(vm).map{|card| network_id_for(card.backing)}
185
+ new_devices = deviceAdditions.select { |device| !current_networks.include?(network_id_for(device.device.backing))}
187
186
 
188
187
  if new_devices.count > 0
189
188
  action_handler.report_progress "Adding extra NICs"
@@ -194,6 +193,14 @@ module ChefMetalVsphere
194
193
  end
195
194
  end
196
195
 
196
+ def network_id_for(backing_info)
197
+ if backing_info.is_a?(RbVmomi::VIM::VirtualEthernetCardDistributedVirtualPortBackingInfo)
198
+ backing_info.port.portgroupKey
199
+ else
200
+ backing_info.network
201
+ end
202
+ end
203
+
197
204
  def relocate_spec_for(dc_name, vm_template, options)
198
205
  datacenter = dc(dc_name)
199
206
  if options.has_key?(:host)
@@ -276,23 +283,42 @@ module ChefMetalVsphere
276
283
  key = 4000
277
284
  networks.each_index do | i |
278
285
  label = "Ethernet #{i+1}"
286
+ backing_info = backing_info_for(action_handler, dc(options[:datacenter]), networks[i])
279
287
  if card = cards.shift
280
288
  key = card.key
281
289
  operation = RbVmomi::VIM::VirtualDeviceConfigSpecOperation('edit')
282
290
  action_handler.report_progress "changing template nic for #{networks[i]}"
283
291
  changes.push(
284
- network_adapter_for(operation, networks[i], label, key))
292
+ network_adapter_for(operation, networks[i], label, key, backing_info))
285
293
  else
286
294
  key = key + 1
287
295
  operation = RbVmomi::VIM::VirtualDeviceConfigSpecOperation('add')
288
296
  action_handler.report_progress "will be adding nic for #{networks[i]}"
289
297
  additions.push(
290
- network_adapter_for(operation, networks[i], label, key))
298
+ network_adapter_for(operation, networks[i], label, key, backing_info))
291
299
  end
292
300
  end
293
301
  [additions, changes]
294
302
  end
295
303
 
304
+ def backing_info_for(action_handler, datacenter, network_name)
305
+ networks = datacenter.network.select {|net| net.name == network_name}
306
+ if networks.count > 0
307
+ dpg = networks.select { |net| net.is_a?(RbVmomi::VIM::DistributedVirtualPortgroup) }
308
+ networks = dpg unless dpg.empty?
309
+ end
310
+ action_handler.report_progress "network: #{network_name} is a #{networks[0].class}}"
311
+ if networks[0].is_a?(RbVmomi::VIM::DistributedVirtualPortgroup)
312
+ port = RbVmomi::VIM::DistributedVirtualSwitchPortConnection(
313
+ :switchUuid => networks[0].config.distributedVirtualSwitch.uuid,
314
+ :portgroupKey => networks[0].key
315
+ )
316
+ RbVmomi::VIM::VirtualEthernetCardDistributedVirtualPortBackingInfo(:port => port)
317
+ else
318
+ RbVmomi::VIM::VirtualEthernetCardNetworkBackingInfo(:deviceName => network_name)
319
+ end
320
+ end
321
+
296
322
  def find_datastore(dc, datastore_name)
297
323
  baseEntity = dc.datastore
298
324
  baseEntity.find { |f| f.info.name == datastore_name } or raise "no such datastore #{datastore_name}"
@@ -37,7 +37,7 @@ module Kitchen
37
37
  state[:vsphere_name] = config[:server_name]
38
38
  end
39
39
 
40
- node_dir = File.join(instance.busser[:test_base_path], "nodes")
40
+ node_dir = File.join(instance.verifier[:test_base_path], "nodes")
41
41
  Dir.mkdir(node_dir) unless Dir.exist?(node_dir)
42
42
  node_file = File.join(node_dir, "#{instance.suite.name}.json")
43
43
  node = {
@@ -65,7 +65,7 @@ module Kitchen
65
65
  state.delete(:hostname)
66
66
  state.delete(:vsphere_name)
67
67
 
68
- node_file = File.join(instance.busser[:test_base_path], "nodes/#{instance.suite.name}.json")
68
+ node_file = File.join(instance.verifier[:test_base_path], "nodes/#{instance.suite.name}.json")
69
69
  File.delete(node_file) if File.exist?(node_file)
70
70
  end
71
71
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: clc-chef-metal-vsphere
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.67
4
+ version: 0.3.77
5
5
  platform: ruby
6
6
  authors:
7
7
  - CenturyLink Cloud
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-14 00:00:00.000000000 Z
11
+ date: 2015-04-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rbvmomi
@@ -36,28 +36,34 @@ dependencies:
36
36
  requirements:
37
37
  - - '='
38
38
  - !ruby/object:Gem::Version
39
- version: 0.14.alpha.8
39
+ version: 0.14.alpha.10
40
40
  type: :runtime
41
41
  prerelease: false
42
42
  version_requirements: !ruby/object:Gem::Requirement
43
43
  requirements:
44
44
  - - '='
45
45
  - !ruby/object:Gem::Version
46
- version: 0.14.alpha.8
46
+ version: 0.14.alpha.10
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: rubyzip
49
49
  requirement: !ruby/object:Gem::Requirement
50
50
  requirements:
51
- - - '='
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: 1.1.0
54
+ - - ">="
52
55
  - !ruby/object:Gem::Version
53
- version: 1.1.6
56
+ version: 1.1.7
54
57
  type: :runtime
55
58
  prerelease: false
56
59
  version_requirements: !ruby/object:Gem::Requirement
57
60
  requirements:
58
- - - '='
61
+ - - "~>"
62
+ - !ruby/object:Gem::Version
63
+ version: 1.1.0
64
+ - - ">="
59
65
  - !ruby/object:Gem::Version
60
- version: 1.1.6
66
+ version: 1.1.7
61
67
  - !ruby/object:Gem::Dependency
62
68
  name: rspec
63
69
  requirement: !ruby/object:Gem::Requirement
@@ -102,11 +108,6 @@ files:
102
108
  - lib/chef_metal_vsphere/vsphere_helpers.rb
103
109
  - lib/chef_metal_vsphere/vsphere_url.rb
104
110
  - lib/kitchen/driver/vsphere.rb
105
- - spec/integration_tests/.gitignore
106
- - spec/integration_tests/config.rb
107
- - spec/integration_tests/vsphere_driver_spec.rb
108
- - spec/unit_tests/VsphereDriver_spec.rb
109
- - spec/unit_tests/VsphereUrl_spec.rb
110
111
  homepage: https://github.com/RallySoftware-cookbooks/chef-metal-vsphere
111
112
  licenses:
112
113
  - MIT
@@ -1 +0,0 @@
1
- config.rb
@@ -1,148 +0,0 @@
1
- require 'chef_metal_vsphere/vsphere_driver'
2
- require 'chef_metal/chef_machine_spec'
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,
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
- # }
35
-
36
- describe "vsphere_driver" do
37
- include ChefMetalVsphere::Helpers
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(Cheffish.profiled_config)
44
- puts "chef server:#{chef_server}"
45
- @machine_spec = ChefMetal::ChefMachineSpec.new({'name' => @vm_name}, chef_server)
46
- @driver = ChefMetal.driver_for_url("vsphere://#{@metal_config[:driver_options][:host]}", @metal_config)
47
- action_handler = ChefMetal::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
56
-
57
-
58
- context 'when allocating a machine' do
59
-
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
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
- if @vm.guest.toolsRunningStatus != "guestToolsRunning"
122
- now = Time.now.utc
123
- 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
124
- print "."
125
- sleep 5
126
- end
127
- end
128
- expect(@vm.guest.net.map { |net| net.ipAddress}.flatten).to include(@metal_config[:machine_options][:bootstrap_options][:customization_spec][:ipsettings][:ip])
129
- end
130
- end
131
-
132
- context "destroy_machine" do
133
-
134
- it "removes the machine" do
135
- Cheffish.honor_local_mode do
136
- chef_server = Cheffish.default_chef_server(Cheffish.profiled_config)
137
- driver = ChefMetal.driver_for_url("vsphere://#{@metal_config[:driver_options][:host]}", @metal_config)
138
- action_handler = ChefMetal::ActionHandler.new
139
- machine_spec = ChefMetal::ChefMachineSpec.new({'name' => @vm_name}, chef_server)
140
- machine_spec.location = { 'driver_url' => driver.driver_url,
141
- 'server_id' => @server_id}
142
- driver.destroy_machine(action_handler, machine_spec, @metal_config[:machine_options])
143
- end
144
- vm = find_vm_by_id(@server_id, @connection)
145
- expect(vm).to eq(nil)
146
- end
147
- end
148
- end
@@ -1,206 +0,0 @@
1
- require 'chef_metal_vsphere/vsphere_driver'
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
- ChefMetalVsphere::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
- ChefMetalVsphere::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
- ChefMetalVsphere::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
- ChefMetalVsphere::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{ChefMetalVsphere::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{ChefMetalVsphere::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{ChefMetalVsphere::VsphereDriver.canonicalize_url(nil,metal_config)}.to raise_error(RuntimeError)
204
- end
205
- end
206
- end
@@ -1,60 +0,0 @@
1
- require_relative '../../lib/chef_metal_vsphere/vsphere_url.rb'
2
-
3
- describe 'VsphereUrl' do
4
- expected_host='1.1.1.1'
5
- expected_port=1818
6
- expected_path='/path'
7
-
8
- let(:url) {URI("vsphere://#{expected_host}:#{expected_port}#{expected_path}")}
9
-
10
- it "has the vsphere scheme" do
11
- expect(url.scheme).to eq('vsphere')
12
- end
13
- it "has the expected host" do
14
- expect(url.host).to eq(expected_host)
15
- end
16
- it "has the expected port" do
17
- expect(url.port).to eq(expected_port)
18
- end
19
- it "has the expected path" do
20
- expect(url.path).to eq(expected_path)
21
- end
22
- it "has the the default ssl setting" do
23
- expect(url.use_ssl).to eq(true)
24
- end
25
- it "has the the default insecure setting" do
26
- expect(url.insecure).to eq(false)
27
- end
28
-
29
- context "when setting from a hash" do
30
- let(:url) {URI::VsphereUrl.from_config({:host => '2.2.2.2', :port => 2345, :path => "/hoooo", :use_ssl => false, :insecure => true})}
31
-
32
- it "asigns the correct url" do
33
- expect(url.to_s).to eq('vsphere://2.2.2.2:2345/hoooo?use_ssl=false&insecure=true')
34
- end
35
- end
36
- context "when ssl is enabled" do
37
- it "retuns an ssl value of true" do
38
- url = URI("vsphere://#{expected_host}:#{expected_port}#{expected_path}?use_ssl=true")
39
- expect(url.use_ssl).to eq(true)
40
- end
41
- end
42
- context "when ssl is disabled" do
43
- it "retuns an ssl value of true" do
44
- url = URI("vsphere://#{expected_host}:#{expected_port}#{expected_path}?use_ssl=false")
45
- expect(url.use_ssl).to eq(false)
46
- end
47
- end
48
- context "when insecure is enabled" do
49
- it "retuns an insecure value of true" do
50
- url = URI("vsphere://#{expected_host}:#{expected_port}#{expected_path}?insecure=true")
51
- expect(url.insecure).to eq(true)
52
- end
53
- end
54
- context "when insecure is disabled" do
55
- it "retuns an insecure value of true" do
56
- url = URI("vsphere://#{expected_host}:#{expected_port}#{expected_path}?insecure=false")
57
- expect(url.insecure).to eq(false)
58
- end
59
- end
60
- end