chef-provisioning-vsphere 0.8.1 → 0.8.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,45 +1,45 @@
1
- require 'uri'
2
-
3
- module URI
4
- class VsphereUrl < Generic
5
- DEFAULT_PORT = 443
6
- DEFAULT_PATH = '/sdk'
7
-
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
21
-
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
32
-
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
+ require 'uri'
2
+
3
+ module URI
4
+ class VsphereUrl < Generic
5
+ DEFAULT_PORT = 443
6
+ DEFAULT_PATH = '/sdk'
7
+
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
21
+
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
32
+
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,100 +1,104 @@
1
- require 'json'
2
- require 'kitchen'
3
- require 'chef/provisioning/vsphere_driver'
4
- require 'chef/provisioning/machine_spec'
5
-
6
- module Kitchen
7
- module Driver
8
- class Vsphere < Kitchen::Driver::Base
9
-
10
- @@chef_zero_server = false
11
-
12
- default_config :machine_options,
13
- :start_timeout => 600,
14
- :create_timeout => 600,
15
- :stop_timeout => 600,
16
- :ready_timeout => 90,
17
- :bootstrap_options => {
18
- :use_linked_clone => true,
19
- :ssh => {
20
- :user => 'root',
21
- :paranoid => false,
22
- :port => 22
23
- },
24
- :convergence_options => {},
25
- :customization_spec => {
26
- :domain => 'local'
27
- }
28
- }
29
-
30
- def create(state)
31
- state[:vsphere_name] ||= "kitchen-#{SecureRandom.hex(4)}"
32
- state[:username] = config[:machine_options][:bootstrap_options][:ssh][:user]
33
- state[:password] = config[:machine_options][:bootstrap_options][:ssh][:password]
34
- config[:server_name] = state[:vsphere_name]
35
-
36
- machine = with_provisioning_driver(state) do | action_handler, driver, machine_spec|
37
- driver.allocate_machine(action_handler, machine_spec, config[:machine_options])
38
- driver.ready_machine(action_handler, machine_spec, config[:machine_options])
39
- state[:server_id] = machine_spec.location['server_id']
40
- state[:hostname] = machine_spec.location['ipaddress']
41
- machine_spec.save(action_handler)
42
- end
43
- end
44
-
45
- def destroy(state)
46
- return if state[:server_id].nil?
47
-
48
- with_provisioning_driver(state) do | action_handler, driver, machine_spec|
49
- machine_spec.location = { 'driver_url' => driver.driver_url,
50
- 'server_id' => state[:server_id]}
51
- driver.destroy_machine(action_handler, machine_spec, config[:machine_options])
52
- end
53
-
54
- state.delete(:server_id)
55
- state.delete(:hostname)
56
- state.delete(:vsphere_name)
57
- end
58
-
59
- def with_provisioning_driver(state, &block)
60
- config[:machine_options][:convergence_options] = {:chef_server => chef_server}
61
- machine_spec = Chef::Provisioning.chef_managed_entry_store(chef_server).get(:machine, state[:vsphere_name])
62
- if machine_spec.nil?
63
- machine_spec = Chef::Provisioning.chef_managed_entry_store(chef_server)
64
- .new_entry(:machine, state[:vsphere_name])
65
- end
66
- url = URI::VsphereUrl.from_config(@config[:driver_options]).to_s
67
- driver = Chef::Provisioning.driver_for_url(url, config)
68
- action_handler = Chef::Provisioning::ActionHandler.new
69
- block.call(action_handler, driver, machine_spec)
70
- end
71
-
72
- def chef_server
73
- if !@@chef_zero_server
74
- vsphere_mutex.synchronize do
75
- if !@@chef_zero_server
76
- Chef::Config.local_mode = true
77
- Chef::Config.chef_repo_path = Chef::Config.find_chef_repo_path(Dir.pwd)
78
- require 'chef/local_mode'
79
- Chef::LocalMode.setup_server_connectivity
80
- @@chef_zero_server = true
81
- end
82
- end
83
- end
84
-
85
- Cheffish.default_chef_server
86
- end
87
-
88
- def vsphere_mutex
89
- @@vsphere_mutex ||= begin
90
- Kitchen.mutex.synchronize do
91
- instance.class.mutexes ||= Hash.new
92
- instance.class.mutexes[self.class] = Mutex.new
93
- end
94
-
95
- instance.class.mutexes[self.class]
96
- end
97
- end
98
- end
99
- end
100
- end
1
+ require 'json'
2
+ require 'kitchen'
3
+ require 'chef/provisioning/vsphere_driver'
4
+ require 'chef/provisioning/machine_spec'
5
+
6
+ module Kitchen
7
+ module Driver
8
+ class Vsphere < Kitchen::Driver::Base
9
+
10
+ @@chef_zero_server = false
11
+
12
+ default_config :machine_options,
13
+ :start_timeout => 600,
14
+ :create_timeout => 600,
15
+ :stop_timeout => 600,
16
+ :ready_timeout => 90,
17
+ :bootstrap_options => {
18
+ :use_linked_clone => true,
19
+ :ssh => {
20
+ :user => 'root',
21
+ :paranoid => false,
22
+ :port => 22
23
+ },
24
+ :convergence_options => {},
25
+ :customization_spec => {
26
+ :domain => 'local'
27
+ }
28
+ }
29
+
30
+ default_config(:vsphere_name) do |driver|
31
+ "#{driver.instance.name}-#{SecureRandom.hex(4)}"
32
+ end
33
+
34
+ def create(state)
35
+ state[:vsphere_name] = config[:vsphere_name]
36
+ state[:username] = config[:machine_options][:bootstrap_options][:ssh][:user]
37
+ state[:password] = config[:machine_options][:bootstrap_options][:ssh][:password]
38
+ config[:server_name] = state[:vsphere_name]
39
+
40
+ machine = with_provisioning_driver(state) do | action_handler, driver, machine_spec|
41
+ driver.allocate_machine(action_handler, machine_spec, config[:machine_options])
42
+ driver.ready_machine(action_handler, machine_spec, config[:machine_options])
43
+ state[:server_id] = machine_spec.location['server_id']
44
+ state[:hostname] = machine_spec.location['ipaddress']
45
+ machine_spec.save(action_handler)
46
+ end
47
+ end
48
+
49
+ def destroy(state)
50
+ return if state[:server_id].nil?
51
+
52
+ with_provisioning_driver(state) do | action_handler, driver, machine_spec|
53
+ machine_spec.location = { 'driver_url' => driver.driver_url,
54
+ 'server_id' => state[:server_id]}
55
+ driver.destroy_machine(action_handler, machine_spec, config[:machine_options])
56
+ end
57
+
58
+ state.delete(:server_id)
59
+ state.delete(:hostname)
60
+ state.delete(:vsphere_name)
61
+ end
62
+
63
+ def with_provisioning_driver(state, &block)
64
+ config[:machine_options][:convergence_options] = {:chef_server => chef_server}
65
+ machine_spec = Chef::Provisioning.chef_managed_entry_store(chef_server).get(:machine, state[:vsphere_name])
66
+ if machine_spec.nil?
67
+ machine_spec = Chef::Provisioning.chef_managed_entry_store(chef_server)
68
+ .new_entry(:machine, state[:vsphere_name])
69
+ end
70
+ url = URI::VsphereUrl.from_config(@config[:driver_options]).to_s
71
+ driver = Chef::Provisioning.driver_for_url(url, config)
72
+ action_handler = Chef::Provisioning::ActionHandler.new
73
+ block.call(action_handler, driver, machine_spec)
74
+ end
75
+
76
+ def chef_server
77
+ if !@@chef_zero_server
78
+ vsphere_mutex.synchronize do
79
+ if !@@chef_zero_server
80
+ Chef::Config.local_mode = true
81
+ Chef::Config.chef_repo_path = Chef::Config.find_chef_repo_path(Dir.pwd)
82
+ require 'chef/local_mode'
83
+ Chef::LocalMode.setup_server_connectivity
84
+ @@chef_zero_server = true
85
+ end
86
+ end
87
+ end
88
+
89
+ Cheffish.default_chef_server
90
+ end
91
+
92
+ def vsphere_mutex
93
+ @@vsphere_mutex ||= begin
94
+ Kitchen.mutex.synchronize do
95
+ instance.class.mutexes ||= Hash.new
96
+ instance.class.mutexes[self.class] = Mutex.new
97
+ end
98
+
99
+ instance.class.mutexes[self.class]
100
+ end
101
+ end
102
+ end
103
+ end
104
+ end
@@ -1 +1 @@
1
- config.rb
1
+ config.rb
@@ -1,158 +1,158 @@
1
- require 'chef/provisioning/vsphere_driver'
2
- require 'chef/provisioning/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
- before :all do
38
- @vm_name = "cmvd-test-#{SecureRandom.hex}"
39
- @metal_config = eval File.read(File.expand_path('../config.rb', __FILE__))
40
- Cheffish.honor_local_mode do
41
- Chef::Log.level = :debug
42
- chef_server = Cheffish.default_chef_server
43
- @machine_spec = Chef::Provisioning.chef_managed_entry_store(chef_server).new_entry(:machine, @vm_name)
44
- url = URI::VsphereUrl.from_config(@metal_config[:driver_options]).to_s
45
- @driver = Chef::Provisioning.driver_for_url(url, @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
- @vsphere_helper = ChefProvisioningVsphere::VsphereHelper.new(
52
- @metal_config[:driver_options],
53
- @metal_config[:machine_options][:bootstrap_options][:datacenter]
54
- )
55
- @vm = @vsphere_helper.find_vm_by_id(@server_id)
56
- end
57
- end
58
-
59
- context 'when allocating a machine' do
60
-
61
- it 'adds machine to the correct folder' do
62
- expect(@vm.parent.name).to eq(@metal_config[:machine_options][:bootstrap_options][:vm_folder])
63
- end
64
- it 'has a matching id with the machine_spec' do
65
- expect(@vm.config.instanceUuid).to eq(@machine_spec.location['server_id'])
66
- end
67
- it 'has the correct name' do
68
- now = Time.now.utc
69
- trimmed_name = @vm.config.guestId.start_with?('win') ? @vm_name.byteslice(0,15) : @vm_name
70
- expected_name="#{trimmed_name}.#{@metal_config[:machine_options][:bootstrap_options][:customization_spec][:domain]}"
71
- until (Time.now.utc - now) > 30 || (@vm.guest.hostName == expected_name) do
72
- print '.'
73
- sleep 5
74
- end
75
- expect(@vm.guest.hostName).to eq(expected_name)
76
- end
77
- it 'has the correct number of CPUs' do
78
- expect(@vm.config.hardware.numCPU).to eq(@metal_config[:machine_options][:bootstrap_options][:num_cpus])
79
- end
80
- it 'has the correct amount of memory' do
81
- expect(@vm.config.hardware.memoryMB).to eq(@metal_config[:machine_options][:bootstrap_options][:memory_mb])
82
- end
83
- it 'is on the correct networks' do
84
- expect(@vm.network.map {|n| n.name}).to include(@metal_config[:machine_options][:bootstrap_options][:network_name][0])
85
- expect(@vm.network.map {|n| n.name}).to include(@metal_config[:machine_options][:bootstrap_options][:network_name][1])
86
- end
87
- it 'is on the correct datastore' do
88
- expect(@vm.datastore[0].name).to eq(@metal_config[:machine_options][:bootstrap_options][:datastore])
89
- end
90
- it 'is in the correct resource pool' do
91
- if @metal_config[:machine_options][:bootstrap_options].has_key?(:resource_pool)
92
- expect(@vm.resourcePool.name).to eq(@metal_config[:machine_options][:bootstrap_options][:resource_pool].split('/')[1])
93
- end
94
- end
95
- it 'is in the correct host' do
96
- if @metal_config[:machine_options][:bootstrap_options].has_key?(:host)
97
- expect(@vm.runtime.host.name).to eq(@metal_config[:machine_options][:bootstrap_options][:host].split('/')[1])
98
- end
99
- end
100
- it 'is in the correct cluster' do
101
- if @metal_config[:machine_options][:bootstrap_options].has_key?(:resource_pool)
102
- expect(@vm.resourcePool.owner.name).to eq(@metal_config[:machine_options][:bootstrap_options][:resource_pool].split('/')[0])
103
- end
104
- end
105
- it 'is in the correct datacenter' do
106
- expect(@vsphere_helper.vim.serviceInstance.find_datacenter(@metal_config[:machine_options][:bootstrap_options][:datacenter]).find_vm("#{@vm.parent.name}/#{@vm_name}")).not_to eq(nil)
107
- end
108
- it 'has an added disk of the correct size' do
109
- disk_count = @vm.disks.count
110
- expect(@vm.disks[disk_count-1].capacityInKB).to eq(@metal_config[:machine_options][:bootstrap_options][:additional_disk_size_gb][1] * 1024 * 1024)
111
- end
112
- it 'has the correct number of disks' do
113
- expect(@vm.disks.count).to eq(3)
114
- end
115
- it 'has hot add cpu enabled' do
116
- expect(@vm.config.cpuHotAddEnabled).to eq(true)
117
- end
118
- it 'has hot remove cpu enabled' do
119
- expect(@vm.config.cpuHotRemoveEnabled).to eq(true)
120
- end
121
- it 'has hot add memory enabled' do
122
- expect(@vm.config.memoryHotAddEnabled).to eq(true)
123
- end
124
- it 'has the correct IP address' do
125
- now = Time.now.utc
126
- 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
127
- print '.'
128
- sleep 5
129
- end
130
- expect(@vm.guest.net.map { |net| net.ipAddress}.flatten).to include(@metal_config[:machine_options][:bootstrap_options][:customization_spec][:ipsettings][:ip])
131
- end
132
- end
133
-
134
- context 'destroy_machine' do
135
-
136
- it 'removes the machine' do
137
- Cheffish.honor_local_mode do
138
- chef_server = Cheffish.default_chef_server
139
- url = URI::VsphereUrl.from_config(@metal_config[:driver_options]).to_s
140
- driver = Chef::Provisioning.driver_for_url(url, @metal_config)
141
- action_handler = Chef::Provisioning::ActionHandler.new
142
- machine_spec = Chef::Provisioning.chef_managed_entry_store(chef_server)
143
- .new_entry(:machine, @vm_name)
144
- machine_spec.location = {
145
- 'driver_url' => driver.driver_url,
146
- 'server_id' => @server_id
147
- }
148
- driver.destroy_machine(
149
- action_handler,
150
- machine_spec,
151
- @metal_config[:machine_options]
152
- )
153
- end
154
- vm = @vsphere_helper.find_vm_by_id(@server_id)
155
- expect(vm).to eq(nil)
156
- end
157
- end
158
- end
1
+ require 'chef/provisioning/vsphere_driver'
2
+ require 'chef/provisioning/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
+ before :all do
38
+ @vm_name = "cmvd-test-#{SecureRandom.hex}"
39
+ @metal_config = eval File.read(File.expand_path('../config.rb', __FILE__))
40
+ Cheffish.honor_local_mode do
41
+ Chef::Log.level = :debug
42
+ chef_server = Cheffish.default_chef_server
43
+ @machine_spec = Chef::Provisioning.chef_managed_entry_store(chef_server).new_entry(:machine, @vm_name)
44
+ url = URI::VsphereUrl.from_config(@metal_config[:driver_options]).to_s
45
+ @driver = Chef::Provisioning.driver_for_url(url, @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
+ @vsphere_helper = ChefProvisioningVsphere::VsphereHelper.new(
52
+ @metal_config[:driver_options],
53
+ @metal_config[:machine_options][:bootstrap_options][:datacenter]
54
+ )
55
+ @vm = @vsphere_helper.find_vm_by_id(@server_id)
56
+ end
57
+ end
58
+
59
+ context 'when allocating a machine' do
60
+
61
+ it 'adds machine to the correct folder' do
62
+ expect(@vm.parent.name).to eq(@metal_config[:machine_options][:bootstrap_options][:vm_folder])
63
+ end
64
+ it 'has a matching id with the machine_spec' do
65
+ expect(@vm.config.instanceUuid).to eq(@machine_spec.location['server_id'])
66
+ end
67
+ it 'has the correct name' do
68
+ now = Time.now.utc
69
+ trimmed_name = @vm.config.guestId.start_with?('win') ? @vm_name.byteslice(0,15) : @vm_name
70
+ expected_name="#{trimmed_name}.#{@metal_config[:machine_options][:bootstrap_options][:customization_spec][:domain]}"
71
+ until (Time.now.utc - now) > 30 || (@vm.guest.hostName == expected_name) do
72
+ print '.'
73
+ sleep 5
74
+ end
75
+ expect(@vm.guest.hostName).to eq(expected_name)
76
+ end
77
+ it 'has the correct number of CPUs' do
78
+ expect(@vm.config.hardware.numCPU).to eq(@metal_config[:machine_options][:bootstrap_options][:num_cpus])
79
+ end
80
+ it 'has the correct amount of memory' do
81
+ expect(@vm.config.hardware.memoryMB).to eq(@metal_config[:machine_options][:bootstrap_options][:memory_mb])
82
+ end
83
+ it 'is on the correct networks' do
84
+ expect(@vm.network.map {|n| n.name}).to include(@metal_config[:machine_options][:bootstrap_options][:network_name][0])
85
+ expect(@vm.network.map {|n| n.name}).to include(@metal_config[:machine_options][:bootstrap_options][:network_name][1])
86
+ end
87
+ it 'is on the correct datastore' do
88
+ expect(@vm.datastore[0].name).to eq(@metal_config[:machine_options][:bootstrap_options][:datastore])
89
+ end
90
+ it 'is in the correct resource pool' do
91
+ if @metal_config[:machine_options][:bootstrap_options].has_key?(:resource_pool)
92
+ expect(@vm.resourcePool.name).to eq(@metal_config[:machine_options][:bootstrap_options][:resource_pool].split('/')[1])
93
+ end
94
+ end
95
+ it 'is in the correct host' do
96
+ if @metal_config[:machine_options][:bootstrap_options].has_key?(:host)
97
+ expect(@vm.runtime.host.name).to eq(@metal_config[:machine_options][:bootstrap_options][:host].split('/')[1])
98
+ end
99
+ end
100
+ it 'is in the correct cluster' do
101
+ if @metal_config[:machine_options][:bootstrap_options].has_key?(:resource_pool)
102
+ expect(@vm.resourcePool.owner.name).to eq(@metal_config[:machine_options][:bootstrap_options][:resource_pool].split('/')[0])
103
+ end
104
+ end
105
+ it 'is in the correct datacenter' do
106
+ expect(@vsphere_helper.vim.serviceInstance.find_datacenter(@metal_config[:machine_options][:bootstrap_options][:datacenter]).find_vm("#{@vm.parent.name}/#{@vm_name}")).not_to eq(nil)
107
+ end
108
+ it 'has an added disk of the correct size' do
109
+ disk_count = @vm.disks.count
110
+ expect(@vm.disks[disk_count-1].capacityInKB).to eq(@metal_config[:machine_options][:bootstrap_options][:additional_disk_size_gb][1] * 1024 * 1024)
111
+ end
112
+ it 'has the correct number of disks' do
113
+ expect(@vm.disks.count).to eq(3)
114
+ end
115
+ it 'has hot add cpu enabled' do
116
+ expect(@vm.config.cpuHotAddEnabled).to eq(true)
117
+ end
118
+ it 'has hot remove cpu enabled' do
119
+ expect(@vm.config.cpuHotRemoveEnabled).to eq(true)
120
+ end
121
+ it 'has hot add memory enabled' do
122
+ expect(@vm.config.memoryHotAddEnabled).to eq(true)
123
+ end
124
+ it 'has the correct IP address' do
125
+ now = Time.now.utc
126
+ 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
127
+ print '.'
128
+ sleep 5
129
+ end
130
+ expect(@vm.guest.net.map { |net| net.ipAddress}.flatten).to include(@metal_config[:machine_options][:bootstrap_options][:customization_spec][:ipsettings][:ip])
131
+ end
132
+ end
133
+
134
+ context 'destroy_machine' do
135
+
136
+ it 'removes the machine' do
137
+ Cheffish.honor_local_mode do
138
+ chef_server = Cheffish.default_chef_server
139
+ url = URI::VsphereUrl.from_config(@metal_config[:driver_options]).to_s
140
+ driver = Chef::Provisioning.driver_for_url(url, @metal_config)
141
+ action_handler = Chef::Provisioning::ActionHandler.new
142
+ machine_spec = Chef::Provisioning.chef_managed_entry_store(chef_server)
143
+ .new_entry(:machine, @vm_name)
144
+ machine_spec.location = {
145
+ 'driver_url' => driver.driver_url,
146
+ 'server_id' => @server_id
147
+ }
148
+ driver.destroy_machine(
149
+ action_handler,
150
+ machine_spec,
151
+ @metal_config[:machine_options]
152
+ )
153
+ end
154
+ vm = @vsphere_helper.find_vm_by_id(@server_id)
155
+ expect(vm).to eq(nil)
156
+ end
157
+ end
158
+ end