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.
- checksums.yaml +4 -4
- data/.gitignore +2 -2
- data/Gemfile +5 -5
- data/LICENSE +19 -19
- data/LICENSE-Rally +20 -20
- data/README.md +269 -269
- data/Rakefile +22 -22
- data/chef-provisioning-vsphere.gemspec +28 -28
- data/contribution-notice +7 -7
- data/lib/chef/provisioning/driver_init/vsphere.rb +2 -2
- data/lib/chef/provisioning/vsphere_driver.rb +14 -14
- data/lib/chef/provisioning/vsphere_driver/clone_spec_builder.rb +205 -205
- data/lib/chef/provisioning/vsphere_driver/driver.rb +671 -671
- data/lib/chef/provisioning/vsphere_driver/version.rb +3 -3
- data/lib/chef/provisioning/vsphere_driver/vsphere_helpers.rb +341 -341
- data/lib/chef/provisioning/vsphere_driver/vsphere_url.rb +45 -45
- data/lib/kitchen/driver/vsphere.rb +104 -100
- data/spec/integration_tests/.gitignore +1 -1
- data/spec/integration_tests/vsphere_driver_spec.rb +158 -158
- data/spec/unit_tests/VsphereDriver_spec.rb +132 -132
- data/spec/unit_tests/VsphereUrl_spec.rb +65 -65
- data/spec/unit_tests/clone_spec_builder_spec.rb +161 -161
- data/spec/unit_tests/support/fake_action_handler.rb +7 -7
- data/spec/unit_tests/support/vsphere_helper_stub.rb +52 -52
- metadata +3 -3
@@ -1,132 +1,132 @@
|
|
1
|
-
require 'chef/provisioning/vsphere_driver'
|
2
|
-
|
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
|
-
:user => 'vmapi',
|
90
|
-
:password => '<password>',
|
91
|
-
:host => '4.4.4.4',
|
92
|
-
:port => 888,
|
93
|
-
:path => '/yoda',
|
94
|
-
:use_ssl => false,
|
95
|
-
:insecure => true
|
96
|
-
}
|
97
|
-
end
|
98
|
-
|
99
|
-
subject do
|
100
|
-
ChefProvisioningVsphere::VsphereDriver.canonicalize_url(
|
101
|
-
nil,
|
102
|
-
metal_config
|
103
|
-
)
|
104
|
-
end
|
105
|
-
|
106
|
-
it "creates the correct driver url from config settings" do
|
107
|
-
expect(subject[0]).to eq('vsphere://4.4.4.4:888/yoda?use_ssl=false&insecure=true')
|
108
|
-
end
|
109
|
-
end
|
110
|
-
|
111
|
-
context "when no url is in the config and config is missing defaulted values" do
|
112
|
-
let(:metal_config) do
|
113
|
-
{
|
114
|
-
:user => 'vmapi',
|
115
|
-
:password => '<password>',
|
116
|
-
:host => '4.4.4.4'
|
117
|
-
}
|
118
|
-
end
|
119
|
-
|
120
|
-
subject do
|
121
|
-
ChefProvisioningVsphere::VsphereDriver.canonicalize_url(
|
122
|
-
nil,
|
123
|
-
metal_config
|
124
|
-
)
|
125
|
-
end
|
126
|
-
|
127
|
-
it "creates the correct driver url from default settings" do
|
128
|
-
expect(subject[0]).to eq('vsphere://4.4.4.4/sdk?use_ssl=true&insecure=false')
|
129
|
-
end
|
130
|
-
end
|
131
|
-
end
|
132
|
-
end
|
1
|
+
require 'chef/provisioning/vsphere_driver'
|
2
|
+
|
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
|
+
:user => 'vmapi',
|
90
|
+
:password => '<password>',
|
91
|
+
:host => '4.4.4.4',
|
92
|
+
:port => 888,
|
93
|
+
:path => '/yoda',
|
94
|
+
:use_ssl => false,
|
95
|
+
:insecure => true
|
96
|
+
}
|
97
|
+
end
|
98
|
+
|
99
|
+
subject do
|
100
|
+
ChefProvisioningVsphere::VsphereDriver.canonicalize_url(
|
101
|
+
nil,
|
102
|
+
metal_config
|
103
|
+
)
|
104
|
+
end
|
105
|
+
|
106
|
+
it "creates the correct driver url from config settings" do
|
107
|
+
expect(subject[0]).to eq('vsphere://4.4.4.4:888/yoda?use_ssl=false&insecure=true')
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
context "when no url is in the config and config is missing defaulted values" do
|
112
|
+
let(:metal_config) do
|
113
|
+
{
|
114
|
+
:user => 'vmapi',
|
115
|
+
:password => '<password>',
|
116
|
+
:host => '4.4.4.4'
|
117
|
+
}
|
118
|
+
end
|
119
|
+
|
120
|
+
subject do
|
121
|
+
ChefProvisioningVsphere::VsphereDriver.canonicalize_url(
|
122
|
+
nil,
|
123
|
+
metal_config
|
124
|
+
)
|
125
|
+
end
|
126
|
+
|
127
|
+
it "creates the correct driver url from default settings" do
|
128
|
+
expect(subject[0]).to eq('vsphere://4.4.4.4/sdk?use_ssl=true&insecure=false')
|
129
|
+
end
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end
|
@@ -1,66 +1,66 @@
|
|
1
|
-
require_relative '../../lib/chef/provisioning/vsphere_driver/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({
|
31
|
-
:host => '2.2.2.2',
|
32
|
-
:port => 2345,
|
33
|
-
:path => "/hoooo",
|
34
|
-
:use_ssl => false,
|
35
|
-
:insecure => true
|
36
|
-
}) }
|
37
|
-
|
38
|
-
it "asigns the correct url" do
|
39
|
-
expect(url.to_s).to eq('vsphere://2.2.2.2:2345/hoooo?use_ssl=false&insecure=true')
|
40
|
-
end
|
41
|
-
end
|
42
|
-
context "when ssl is enabled" do
|
43
|
-
it "retuns an ssl value of true" do
|
44
|
-
url = URI("vsphere://#{expected_host}:#{expected_port}#{expected_path}?use_ssl=true")
|
45
|
-
expect(url.use_ssl).to eq(true)
|
46
|
-
end
|
47
|
-
end
|
48
|
-
context "when ssl is disabled" do
|
49
|
-
it "retuns an ssl value of true" do
|
50
|
-
url = URI("vsphere://#{expected_host}:#{expected_port}#{expected_path}?use_ssl=false")
|
51
|
-
expect(url.use_ssl).to eq(false)
|
52
|
-
end
|
53
|
-
end
|
54
|
-
context "when insecure is enabled" do
|
55
|
-
it "retuns an insecure value of true" do
|
56
|
-
url = URI("vsphere://#{expected_host}:#{expected_port}#{expected_path}?insecure=true")
|
57
|
-
expect(url.insecure).to eq(true)
|
58
|
-
end
|
59
|
-
end
|
60
|
-
context "when insecure is disabled" do
|
61
|
-
it "retuns an insecure value of true" do
|
62
|
-
url = URI("vsphere://#{expected_host}:#{expected_port}#{expected_path}?insecure=false")
|
63
|
-
expect(url.insecure).to eq(false)
|
64
|
-
end
|
65
|
-
end
|
1
|
+
require_relative '../../lib/chef/provisioning/vsphere_driver/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({
|
31
|
+
:host => '2.2.2.2',
|
32
|
+
:port => 2345,
|
33
|
+
:path => "/hoooo",
|
34
|
+
:use_ssl => false,
|
35
|
+
:insecure => true
|
36
|
+
}) }
|
37
|
+
|
38
|
+
it "asigns the correct url" do
|
39
|
+
expect(url.to_s).to eq('vsphere://2.2.2.2:2345/hoooo?use_ssl=false&insecure=true')
|
40
|
+
end
|
41
|
+
end
|
42
|
+
context "when ssl is enabled" do
|
43
|
+
it "retuns an ssl value of true" do
|
44
|
+
url = URI("vsphere://#{expected_host}:#{expected_port}#{expected_path}?use_ssl=true")
|
45
|
+
expect(url.use_ssl).to eq(true)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
context "when ssl is disabled" do
|
49
|
+
it "retuns an ssl value of true" do
|
50
|
+
url = URI("vsphere://#{expected_host}:#{expected_port}#{expected_path}?use_ssl=false")
|
51
|
+
expect(url.use_ssl).to eq(false)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
context "when insecure is enabled" do
|
55
|
+
it "retuns an insecure value of true" do
|
56
|
+
url = URI("vsphere://#{expected_host}:#{expected_port}#{expected_path}?insecure=true")
|
57
|
+
expect(url.insecure).to eq(true)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
context "when insecure is disabled" do
|
61
|
+
it "retuns an insecure value of true" do
|
62
|
+
url = URI("vsphere://#{expected_host}:#{expected_port}#{expected_path}?insecure=false")
|
63
|
+
expect(url.insecure).to eq(false)
|
64
|
+
end
|
65
|
+
end
|
66
66
|
end
|
@@ -1,161 +1,161 @@
|
|
1
|
-
require 'chef/provisioning/vsphere_driver'
|
2
|
-
require_relative 'support/fake_action_handler'
|
3
|
-
require_relative 'support/vsphere_helper_stub'
|
4
|
-
|
5
|
-
describe ChefProvisioningVsphere::CloneSpecBuilder do
|
6
|
-
let(:options) { Hash.new }
|
7
|
-
let(:vm_template) { double('template') }
|
8
|
-
|
9
|
-
before do
|
10
|
-
allow(vm_template).to receive_message_chain(:config, :guestId)
|
11
|
-
.and_return('guest')
|
12
|
-
allow(vm_template).to receive_message_chain(:config, :template)
|
13
|
-
.and_return(false)
|
14
|
-
end
|
15
|
-
|
16
|
-
subject do
|
17
|
-
builder = ChefProvisioningVsphere::CloneSpecBuilder.new(
|
18
|
-
ChefProvisioningVsphereStubs::VsphereHelperStub.new,
|
19
|
-
ChefProvisioningVsphereStubs::FakeActionHandler.new
|
20
|
-
)
|
21
|
-
builder.build(vm_template, 'machine_name', options)
|
22
|
-
end
|
23
|
-
|
24
|
-
context 'using linked clones' do
|
25
|
-
before { options[:use_linked_clone] = true }
|
26
|
-
|
27
|
-
it 'sets the disk move type of the relocation spec' do
|
28
|
-
expect(subject.location.diskMoveType).to be :moveChildMostDiskBacking
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
context 'using linked clone on a template source' do
|
33
|
-
before do
|
34
|
-
options[:use_linked_clone] = true
|
35
|
-
options[:host] = 'host'
|
36
|
-
allow(vm_template).to receive_message_chain(:config, :template)
|
37
|
-
.and_return(true)
|
38
|
-
end
|
39
|
-
|
40
|
-
it 'does not set the disk move type of the relocation spec' do
|
41
|
-
expect(subject.location.diskMoveType).to be nil
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
context 'not using linked clones' do
|
46
|
-
before { options[:use_linked_clone] = false }
|
47
|
-
|
48
|
-
it 'does not set the disk move type of the relocation spec' do
|
49
|
-
expect(subject.location.diskMoveType).to be nil
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
context 'specifying a host' do
|
54
|
-
before { options[:host] = 'host' }
|
55
|
-
|
56
|
-
it 'sets the host' do
|
57
|
-
expect(subject.location.host).to_not be nil
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
context 'not specifying a host' do
|
62
|
-
it 'does not set the host' do
|
63
|
-
expect(subject.location.host).to be nil
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
context 'specifying a pool' do
|
68
|
-
before { options[:resource_pool] = 'pool' }
|
69
|
-
|
70
|
-
it 'sets the pool' do
|
71
|
-
expect(subject.location.pool).to_not be nil
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
context 'not specifying a pool' do
|
76
|
-
it 'does not set the pool' do
|
77
|
-
expect(subject.location.pool).to be nil
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
|
-
context 'not specifying a pool but specifying a host on a template' do
|
82
|
-
before do
|
83
|
-
options[:host] = 'host'
|
84
|
-
allow(vm_template).to receive_message_chain(:config, :template)
|
85
|
-
.and_return(true)
|
86
|
-
end
|
87
|
-
|
88
|
-
it 'sets the pool to the hosts parent root pool' do
|
89
|
-
expect(subject.location.pool).to be subject.location.host.parent.resourcePool
|
90
|
-
end
|
91
|
-
end
|
92
|
-
|
93
|
-
context 'not specifying a pool or host when cloning from a template' do
|
94
|
-
before do
|
95
|
-
allow(vm_template).to receive_message_chain(:config, :template)
|
96
|
-
.and_return(true)
|
97
|
-
end
|
98
|
-
|
99
|
-
it 'raises an error' do
|
100
|
-
expect { subject }.to raise_error
|
101
|
-
end
|
102
|
-
end
|
103
|
-
|
104
|
-
context 'specifying a hostname' do
|
105
|
-
before do
|
106
|
-
options[:customization_spec] = {
|
107
|
-
ipsettings: {},
|
108
|
-
hostname: hostname,
|
109
|
-
domain: 'local'
|
110
|
-
}
|
111
|
-
end
|
112
|
-
|
113
|
-
context 'alpha characters only' do
|
114
|
-
let(:hostname) { 'myhost' }
|
115
|
-
|
116
|
-
it 'sets the spec hostname' do
|
117
|
-
expect(subject.customization.identity.hostName.name).to eq hostname
|
118
|
-
end
|
119
|
-
end
|
120
|
-
|
121
|
-
context 'alpha numeric characters only' do
|
122
|
-
let(:hostname) { 'myhost01' }
|
123
|
-
|
124
|
-
it 'sets the spec hostname' do
|
125
|
-
expect(subject.customization.identity.hostName.name).to eq hostname
|
126
|
-
end
|
127
|
-
end
|
128
|
-
|
129
|
-
context 'containing a dash' do
|
130
|
-
let(:hostname) { 'my-host01' }
|
131
|
-
|
132
|
-
it 'sets the spec hostname' do
|
133
|
-
expect(subject.customization.identity.hostName.name).to eq hostname
|
134
|
-
end
|
135
|
-
end
|
136
|
-
|
137
|
-
context 'containing an underscore' do
|
138
|
-
let(:hostname) { 'my_host' }
|
139
|
-
|
140
|
-
it 'raises an error' do
|
141
|
-
expect { subject }.to raise_error
|
142
|
-
end
|
143
|
-
end
|
144
|
-
|
145
|
-
context 'starting with a dash' do
|
146
|
-
let(:hostname) { '-myhost' }
|
147
|
-
|
148
|
-
it 'raises an error' do
|
149
|
-
expect { subject }.to raise_error
|
150
|
-
end
|
151
|
-
end
|
152
|
-
|
153
|
-
context 'ending with a dash' do
|
154
|
-
let(:hostname) { 'myhost-' }
|
155
|
-
|
156
|
-
it 'raises an error' do
|
157
|
-
expect { subject }.to raise_error
|
158
|
-
end
|
159
|
-
end
|
160
|
-
end
|
161
|
-
end
|
1
|
+
require 'chef/provisioning/vsphere_driver'
|
2
|
+
require_relative 'support/fake_action_handler'
|
3
|
+
require_relative 'support/vsphere_helper_stub'
|
4
|
+
|
5
|
+
describe ChefProvisioningVsphere::CloneSpecBuilder do
|
6
|
+
let(:options) { Hash.new }
|
7
|
+
let(:vm_template) { double('template') }
|
8
|
+
|
9
|
+
before do
|
10
|
+
allow(vm_template).to receive_message_chain(:config, :guestId)
|
11
|
+
.and_return('guest')
|
12
|
+
allow(vm_template).to receive_message_chain(:config, :template)
|
13
|
+
.and_return(false)
|
14
|
+
end
|
15
|
+
|
16
|
+
subject do
|
17
|
+
builder = ChefProvisioningVsphere::CloneSpecBuilder.new(
|
18
|
+
ChefProvisioningVsphereStubs::VsphereHelperStub.new,
|
19
|
+
ChefProvisioningVsphereStubs::FakeActionHandler.new
|
20
|
+
)
|
21
|
+
builder.build(vm_template, 'machine_name', options)
|
22
|
+
end
|
23
|
+
|
24
|
+
context 'using linked clones' do
|
25
|
+
before { options[:use_linked_clone] = true }
|
26
|
+
|
27
|
+
it 'sets the disk move type of the relocation spec' do
|
28
|
+
expect(subject.location.diskMoveType).to be :moveChildMostDiskBacking
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
context 'using linked clone on a template source' do
|
33
|
+
before do
|
34
|
+
options[:use_linked_clone] = true
|
35
|
+
options[:host] = 'host'
|
36
|
+
allow(vm_template).to receive_message_chain(:config, :template)
|
37
|
+
.and_return(true)
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'does not set the disk move type of the relocation spec' do
|
41
|
+
expect(subject.location.diskMoveType).to be nil
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
context 'not using linked clones' do
|
46
|
+
before { options[:use_linked_clone] = false }
|
47
|
+
|
48
|
+
it 'does not set the disk move type of the relocation spec' do
|
49
|
+
expect(subject.location.diskMoveType).to be nil
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
context 'specifying a host' do
|
54
|
+
before { options[:host] = 'host' }
|
55
|
+
|
56
|
+
it 'sets the host' do
|
57
|
+
expect(subject.location.host).to_not be nil
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
context 'not specifying a host' do
|
62
|
+
it 'does not set the host' do
|
63
|
+
expect(subject.location.host).to be nil
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
context 'specifying a pool' do
|
68
|
+
before { options[:resource_pool] = 'pool' }
|
69
|
+
|
70
|
+
it 'sets the pool' do
|
71
|
+
expect(subject.location.pool).to_not be nil
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
context 'not specifying a pool' do
|
76
|
+
it 'does not set the pool' do
|
77
|
+
expect(subject.location.pool).to be nil
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
context 'not specifying a pool but specifying a host on a template' do
|
82
|
+
before do
|
83
|
+
options[:host] = 'host'
|
84
|
+
allow(vm_template).to receive_message_chain(:config, :template)
|
85
|
+
.and_return(true)
|
86
|
+
end
|
87
|
+
|
88
|
+
it 'sets the pool to the hosts parent root pool' do
|
89
|
+
expect(subject.location.pool).to be subject.location.host.parent.resourcePool
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
context 'not specifying a pool or host when cloning from a template' do
|
94
|
+
before do
|
95
|
+
allow(vm_template).to receive_message_chain(:config, :template)
|
96
|
+
.and_return(true)
|
97
|
+
end
|
98
|
+
|
99
|
+
it 'raises an error' do
|
100
|
+
expect { subject }.to raise_error
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
context 'specifying a hostname' do
|
105
|
+
before do
|
106
|
+
options[:customization_spec] = {
|
107
|
+
ipsettings: {},
|
108
|
+
hostname: hostname,
|
109
|
+
domain: 'local'
|
110
|
+
}
|
111
|
+
end
|
112
|
+
|
113
|
+
context 'alpha characters only' do
|
114
|
+
let(:hostname) { 'myhost' }
|
115
|
+
|
116
|
+
it 'sets the spec hostname' do
|
117
|
+
expect(subject.customization.identity.hostName.name).to eq hostname
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
context 'alpha numeric characters only' do
|
122
|
+
let(:hostname) { 'myhost01' }
|
123
|
+
|
124
|
+
it 'sets the spec hostname' do
|
125
|
+
expect(subject.customization.identity.hostName.name).to eq hostname
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
context 'containing a dash' do
|
130
|
+
let(:hostname) { 'my-host01' }
|
131
|
+
|
132
|
+
it 'sets the spec hostname' do
|
133
|
+
expect(subject.customization.identity.hostName.name).to eq hostname
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
context 'containing an underscore' do
|
138
|
+
let(:hostname) { 'my_host' }
|
139
|
+
|
140
|
+
it 'raises an error' do
|
141
|
+
expect { subject }.to raise_error
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
context 'starting with a dash' do
|
146
|
+
let(:hostname) { '-myhost' }
|
147
|
+
|
148
|
+
it 'raises an error' do
|
149
|
+
expect { subject }.to raise_error
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
context 'ending with a dash' do
|
154
|
+
let(:hostname) { 'myhost-' }
|
155
|
+
|
156
|
+
it 'raises an error' do
|
157
|
+
expect { subject }.to raise_error
|
158
|
+
end
|
159
|
+
end
|
160
|
+
end
|
161
|
+
end
|