chef-provisioning-vsphere 0.10.0 → 1.0.0

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