chef-provisioning-vsphere 0.8.4 → 0.9.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,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('/').last)
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
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chef-provisioning-vsphere
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.4
4
+ version: 0.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - CenturyLink Cloud
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-03-09 00:00:00.000000000 Z
11
+ date: 2016-07-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rbvmomi
@@ -44,6 +44,20 @@ dependencies:
44
44
  - - "~>"
45
45
  - !ruby/object:Gem::Version
46
46
  version: '1.1'
47
+ - !ruby/object:Gem::Dependency
48
+ name: winrm
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '1.6'
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: '1.6'
47
61
  - !ruby/object:Gem::Dependency
48
62
  name: rspec
49
63
  requirement: !ruby/object:Gem::Requirement
@@ -136,7 +150,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
136
150
  version: '0'
137
151
  requirements: []
138
152
  rubyforge_project:
139
- rubygems_version: 2.5.2
153
+ rubygems_version: 2.6.6
140
154
  signing_key:
141
155
  specification_version: 4
142
156
  summary: Provisioner for creating vSphere VM instances in Chef Provisioning.