chef-provisioning-vsphere 2.2.2 → 2.3.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.
data/spec/spec_helper.rb CHANGED
@@ -1,4 +1,5 @@
1
- require 'simplecov'
1
+ # frozen_string_literal: true
2
+ require "simplecov"
2
3
 
3
4
  SimpleCov.start do
4
5
  # add_filter do |source_file|
@@ -15,5 +16,5 @@ RSpec.configure do |config|
15
16
  # order dependency and want to debug it, you can fix the order by providing
16
17
  # the seed, which is printed after each run.
17
18
  # --seed 1234
18
- config.order = 'random'
19
+ config.order = "random"
19
20
  end
@@ -1,99 +1,99 @@
1
1
  # frozen_string_literal: true
2
- require 'chef/provisioning/vsphere_driver'
2
+ require "chef/provisioning/vsphere_driver"
3
3
 
4
4
  describe ChefProvisioningVsphere::VsphereDriver do
5
5
  subject do
6
6
  Chef::Provisioning.driver_for_url(
7
- 'vsphere://3.3.3.3:999/crazyapi?use_ssl=false&insecure=true',
7
+ "vsphere://3.3.3.3:999/crazyapi?use_ssl=false&insecure=true",
8
8
  metal_config
9
9
  )
10
10
  end
11
11
 
12
- context 'when config does not include the properties included in the url' do
12
+ context "when config does not include the properties included in the url" do
13
13
  let(:metal_config) do
14
14
  {
15
15
  driver_options: {
16
- user: 'vmapi',
17
- password: '<password>'
16
+ user: "vmapi",
17
+ password: "<password>",
18
18
  },
19
19
  machine_options: {
20
20
  ssh: {
21
- password: '<password>',
22
- paranoid: false
21
+ password: "<password>",
22
+ paranoid: false,
23
23
  },
24
24
  bootstrap_options: {
25
- datacenter: 'QA1',
26
- template_name: 'UBUNTU-12-64-TEMPLATE',
27
- vm_folder: 'DLAB',
25
+ datacenter: "QA1",
26
+ template_name: "UBUNTU-12-64-TEMPLATE",
27
+ vm_folder: "DLAB",
28
28
  num_cpus: 2,
29
29
  memory_mb: 4096,
30
- resource_pool: 'CLSTR02/DLAB'
31
- }
30
+ resource_pool: "CLSTR02/DLAB",
31
+ },
32
32
  },
33
- log_level: :debug
33
+ log_level: :debug,
34
34
  }
35
35
  end
36
36
 
37
- it 'populates the connect options with correct host from the driver url' do
38
- expect(subject.connect_options[:host]).to eq('3.3.3.3')
37
+ it "populates the connect options with correct host from the driver url" do
38
+ expect(subject.connect_options[:host]).to eq("3.3.3.3")
39
39
  end
40
- it 'populates the connect options with correct port from the driver url' do
40
+ it "populates the connect options with correct port from the driver url" do
41
41
  expect(subject.connect_options[:port]).to eq(999)
42
42
  end
43
- it 'populates the connect options with correct path from the driver url' do
44
- expect(subject.connect_options[:path]).to eq('/crazyapi')
43
+ it "populates the connect options with correct path from the driver url" do
44
+ expect(subject.connect_options[:path]).to eq("/crazyapi")
45
45
  end
46
- it 'populates the connect options with correct use_ssl setting from the driver url' do
46
+ it "populates the connect options with correct use_ssl setting from the driver url" do
47
47
  expect(subject.connect_options[:use_ssl]).to eq(false)
48
48
  end
49
- it 'populates the connect options with correct insecure setting from the driver url' do
49
+ it "populates the connect options with correct insecure setting from the driver url" do
50
50
  expect(subject.connect_options[:insecure]).to eq(true)
51
51
  end
52
52
  end
53
53
 
54
- context 'when config keys are stringified' do
54
+ context "when config keys are stringified" do
55
55
  let(:metal_config) do
56
56
  {
57
- 'driver_options' => {
58
- 'user' => 'vmapi',
59
- 'password' => '<driver_password>'
57
+ "driver_options" => {
58
+ "user" => "vmapi",
59
+ "password" => "<driver_password>",
60
+ },
61
+ "bootstrap_options" => {
62
+ "machine_options" => {
63
+ "datacenter" => "QA1",
64
+ "ssh" => {
65
+ "password" => "<machine_password>",
66
+ },
67
+ },
60
68
  },
61
- 'bootstrap_options' => {
62
- 'machine_options' => {
63
- 'datacenter' => 'QA1',
64
- 'ssh' => {
65
- 'password' => '<machine_password>'
66
- }
67
- }
68
- }
69
69
  }
70
70
  end
71
71
 
72
- it 'will symbolize user' do
73
- expect(subject.connect_options[:user]).to eq('vmapi')
72
+ it "will symbolize user" do
73
+ expect(subject.connect_options[:user]).to eq("vmapi")
74
74
  end
75
- it 'will symbolize password' do
76
- expect(subject.connect_options[:password]).to eq('<driver_password>')
75
+ it "will symbolize password" do
76
+ expect(subject.connect_options[:password]).to eq("<driver_password>")
77
77
  end
78
- it 'will symbolize ssh password' do
79
- expect(subject.config[:bootstrap_options][:machine_options][:ssh][:password]).to eq('<machine_password>')
78
+ it "will symbolize ssh password" do
79
+ expect(subject.config[:bootstrap_options][:machine_options][:ssh][:password]).to eq("<machine_password>")
80
80
  end
81
- it 'will symbolize ssh bootstrap options' do
82
- expect(subject.config[:bootstrap_options][:machine_options][:datacenter]).to eq('QA1')
81
+ it "will symbolize ssh bootstrap options" do
82
+ expect(subject.config[:bootstrap_options][:machine_options][:datacenter]).to eq("QA1")
83
83
  end
84
84
  end
85
85
 
86
- describe 'canonicalize_url' do
87
- context 'when no url is in the config' do
86
+ describe "canonicalize_url" do
87
+ context "when no url is in the config" do
88
88
  let(:metal_config) do
89
89
  {
90
- user: 'vmapi',
91
- password: '<password>',
92
- host: '4.4.4.4',
90
+ user: "vmapi",
91
+ password: "<password>",
92
+ host: "4.4.4.4",
93
93
  port: 888,
94
- path: '/yoda',
94
+ path: "/yoda",
95
95
  use_ssl: false,
96
- insecure: true
96
+ insecure: true,
97
97
  }
98
98
  end
99
99
 
@@ -104,17 +104,17 @@ describe ChefProvisioningVsphere::VsphereDriver do
104
104
  )
105
105
  end
106
106
 
107
- it 'creates the correct driver url from config settings' do
108
- expect(subject[0]).to eq('vsphere://4.4.4.4:888/yoda?use_ssl=false&insecure=true')
107
+ it "creates the correct driver url from config settings" do
108
+ expect(subject[0]).to eq("vsphere://4.4.4.4:888/yoda?use_ssl=false&insecure=true")
109
109
  end
110
110
  end
111
111
 
112
- context 'when no url is in the config and config is missing defaulted values' do
112
+ context "when no url is in the config and config is missing defaulted values" do
113
113
  let(:metal_config) do
114
114
  {
115
- user: 'vmapi',
116
- password: '<password>',
117
- host: '4.4.4.4'
115
+ user: "vmapi",
116
+ password: "<password>",
117
+ host: "4.4.4.4",
118
118
  }
119
119
  end
120
120
 
@@ -125,8 +125,8 @@ describe ChefProvisioningVsphere::VsphereDriver do
125
125
  )
126
126
  end
127
127
 
128
- it 'creates the correct driver url from default settings' do
129
- expect(subject[0]).to eq('vsphere://4.4.4.4/sdk?use_ssl=true&insecure=false')
128
+ it "creates the correct driver url from default settings" do
129
+ expect(subject[0]).to eq("vsphere://4.4.4.4/sdk?use_ssl=true&insecure=false")
130
130
  end
131
131
  end
132
132
  end
@@ -151,7 +151,7 @@ describe ChefProvisioningVsphere::VsphereDriver do
151
151
 
152
152
  let(:port) { 22 }
153
153
  let(:bootstrap_conf) { {} }
154
-
154
+
155
155
  context "has_static_ip" do
156
156
  let(:bootstrap_conf) { { customization_spec: "some spec" } }
157
157
  context "customization_spec is named" do
@@ -178,12 +178,12 @@ describe ChefProvisioningVsphere::VsphereDriver do
178
178
 
179
179
  context "customization_spec has an ip address" do
180
180
  let(:bootstrap_conf) do
181
- {
181
+ {
182
182
  customization_spec: {
183
183
  ipsettings: {
184
- ip: "2.2.2.2"
185
- }
186
- }
184
+ ip: "2.2.2.2",
185
+ },
186
+ },
187
187
  }
188
188
  end
189
189
 
@@ -220,4 +220,42 @@ describe ChefProvisioningVsphere::VsphereDriver do
220
220
  end
221
221
  end
222
222
  end
223
+
224
+ context "#merge_options!" do
225
+ let(:metal_config) { {} }
226
+
227
+ it "Add tupple with string key" do
228
+ subject.merge_options! "string_key" => "some string"
229
+ expect(subject.config).to eq machine_options: {
230
+ string_key: "some string",
231
+ }
232
+ end
233
+
234
+ it "Add tupple with symbol key" do
235
+ subject.merge_options! symbol_key: "some other string"
236
+ expect(subject.config).to eq machine_options: {
237
+ symbol_key: "some other string",
238
+ }
239
+ end
240
+
241
+ it "Add empty MergedConfig" do
242
+ expect($stderr).not_to receive(:puts)
243
+
244
+ item = Cheffish::MergedConfig.new()
245
+ subject.merge_options! item
246
+
247
+ expect(subject.config).to eq machine_options: {}
248
+ end
249
+
250
+ it "Add MergedConfig with 1 tupple" do
251
+ expect($stderr).not_to receive(:puts)
252
+
253
+ item = Cheffish::MergedConfig.new(merged_config: "some merged value")
254
+ subject.merge_options! item
255
+
256
+ expect(subject.config).to eq machine_options: {
257
+ merged_config: "some merged value",
258
+ }
259
+ end
260
+ end
223
261
  end
@@ -1,65 +1,65 @@
1
1
  # frozen_string_literal: true
2
- require_relative '../../lib/chef/provisioning/vsphere_driver/vsphere_url.rb'
2
+ require_relative "../../lib/chef/provisioning/vsphere_driver/vsphere_url.rb"
3
3
 
4
- describe 'VsphereUrl' do
5
- expected_host = '1.1.1.1'
4
+ describe "VsphereUrl" do
5
+ expected_host = "1.1.1.1"
6
6
  expected_port = 1818
7
- expected_path = '/path'
7
+ expected_path = "/path"
8
8
 
9
9
  let(:url) { URI("vsphere://#{expected_host}:#{expected_port}#{expected_path}") }
10
10
 
11
- it 'has the vsphere scheme' do
12
- expect(url.scheme).to eq('vsphere')
11
+ it "has the vsphere scheme" do
12
+ expect(url.scheme).to eq("vsphere")
13
13
  end
14
- it 'has the expected host' do
14
+ it "has the expected host" do
15
15
  expect(url.host).to eq(expected_host)
16
16
  end
17
- it 'has the expected port' do
17
+ it "has the expected port" do
18
18
  expect(url.port).to eq(expected_port)
19
19
  end
20
- it 'has the expected path' do
20
+ it "has the expected path" do
21
21
  expect(url.path).to eq(expected_path)
22
22
  end
23
- it 'has the the default ssl setting' do
23
+ it "has the the default ssl setting" do
24
24
  expect(url.use_ssl).to eq(true)
25
25
  end
26
- it 'has the the default insecure setting' do
26
+ it "has the the default insecure setting" do
27
27
  expect(url.insecure).to eq(false)
28
28
  end
29
29
 
30
- context 'when setting from a hash' do
30
+ context "when setting from a hash" do
31
31
  let(:url) do
32
- URI::VsphereUrl.from_config(host: '2.2.2.2',
32
+ URI::VsphereUrl.from_config(host: "2.2.2.2",
33
33
  port: 2345,
34
- path: '/hoooo',
34
+ path: "/hoooo",
35
35
  use_ssl: false,
36
36
  insecure: true)
37
37
  end
38
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')
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
41
  end
42
42
  end
43
- context 'when ssl is enabled' do
44
- it 'retuns an ssl value of true' do
43
+ context "when ssl is enabled" do
44
+ it "retuns an ssl value of true" do
45
45
  url = URI("vsphere://#{expected_host}:#{expected_port}#{expected_path}?use_ssl=true")
46
46
  expect(url.use_ssl).to eq(true)
47
47
  end
48
48
  end
49
- context 'when ssl is disabled' do
50
- it 'retuns an ssl value of true' do
49
+ context "when ssl is disabled" do
50
+ it "retuns an ssl value of true" do
51
51
  url = URI("vsphere://#{expected_host}:#{expected_port}#{expected_path}?use_ssl=false")
52
52
  expect(url.use_ssl).to eq(false)
53
53
  end
54
54
  end
55
- context 'when insecure is enabled' do
56
- it 'retuns an insecure value of true' do
55
+ context "when insecure is enabled" do
56
+ it "retuns an insecure value of true" do
57
57
  url = URI("vsphere://#{expected_host}:#{expected_port}#{expected_path}?insecure=true")
58
58
  expect(url.insecure).to eq(true)
59
59
  end
60
60
  end
61
- context 'when insecure is disabled' do
62
- it 'retuns an insecure value of true' do
61
+ context "when insecure is disabled" do
62
+ it "retuns an insecure value of true" do
63
63
  url = URI("vsphere://#{expected_host}:#{expected_port}#{expected_path}?insecure=false")
64
64
  expect(url.insecure).to eq(false)
65
65
  end
@@ -1,15 +1,15 @@
1
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'
2
+ require "chef/provisioning/vsphere_driver"
3
+ require_relative "support/fake_action_handler"
4
+ require_relative "support/vsphere_helper_stub"
5
5
 
6
6
  describe ChefProvisioningVsphere::CloneSpecBuilder do
7
7
  let(:options) { Hash.new }
8
- let(:vm_template) { double('template') }
8
+ let(:vm_template) { double("template") }
9
9
 
10
10
  before do
11
11
  allow(vm_template).to receive_message_chain(:config, :guestId)
12
- .and_return('guest')
12
+ .and_return("guest")
13
13
  allow(vm_template).to receive_message_chain(:config, :template)
14
14
  .and_return(false)
15
15
  end
@@ -19,142 +19,142 @@ describe ChefProvisioningVsphere::CloneSpecBuilder do
19
19
  ChefProvisioningVsphereStubs::VsphereHelperStub.new,
20
20
  ChefProvisioningVsphereStubs::FakeActionHandler.new
21
21
  )
22
- builder.build(vm_template, 'machine_name', options)
22
+ builder.build(vm_template, "machine_name", options)
23
23
  end
24
24
 
25
- context 'using linked clones' do
25
+ context "using linked clones" do
26
26
  before { options[:use_linked_clone] = true }
27
27
 
28
- it 'sets the disk move type of the relocation spec' do
28
+ it "sets the disk move type of the relocation spec" do
29
29
  expect(subject.location.diskMoveType).to be :moveChildMostDiskBacking
30
30
  end
31
31
  end
32
32
 
33
- context 'using linked clone on a template source' do
33
+ context "using linked clone on a template source" do
34
34
  before do
35
35
  options[:use_linked_clone] = true
36
- options[:host] = 'host'
36
+ options[:host] = "host"
37
37
  allow(vm_template).to receive_message_chain(:config, :template)
38
38
  .and_return(true)
39
39
  end
40
40
 
41
- it 'does not set the disk move type of the relocation spec' do
41
+ it "does not set the disk move type of the relocation spec" do
42
42
  expect(subject.location.diskMoveType).to be nil
43
43
  end
44
44
  end
45
45
 
46
- context 'not using linked clones' do
46
+ context "not using linked clones" do
47
47
  before { options[:use_linked_clone] = false }
48
48
 
49
- it 'does not set the disk move type of the relocation spec' do
49
+ it "does not set the disk move type of the relocation spec" do
50
50
  expect(subject.location.diskMoveType).to be nil
51
51
  end
52
52
  end
53
53
 
54
- context 'specifying a host' do
55
- before { options[:host] = 'host' }
54
+ context "specifying a host" do
55
+ before { options[:host] = "host" }
56
56
 
57
- it 'sets the host' do
57
+ it "sets the host" do
58
58
  expect(subject.location.host).to_not be nil
59
59
  end
60
60
  end
61
61
 
62
- context 'not specifying a host' do
63
- it 'does not set the host' do
62
+ context "not specifying a host" do
63
+ it "does not set the host" do
64
64
  expect(subject.location.host).to be nil
65
65
  end
66
66
  end
67
67
 
68
- context 'specifying a pool' do
69
- before { options[:resource_pool] = 'pool' }
68
+ context "specifying a pool" do
69
+ before { options[:resource_pool] = "pool" }
70
70
 
71
- it 'sets the pool' do
71
+ it "sets the pool" do
72
72
  expect(subject.location.pool).to_not be nil
73
73
  end
74
74
  end
75
75
 
76
- context 'not specifying a pool' do
77
- it 'does not set the pool' do
76
+ context "not specifying a pool" do
77
+ it "does not set the pool" do
78
78
  expect(subject.location.pool).to be nil
79
79
  end
80
80
  end
81
81
 
82
- context 'not specifying a pool but specifying a host on a template' do
82
+ context "not specifying a pool but specifying a host on a template" do
83
83
  before do
84
- options[:host] = 'host'
84
+ options[:host] = "host"
85
85
  allow(vm_template).to receive_message_chain(:config, :template)
86
86
  .and_return(true)
87
87
  end
88
88
 
89
- it 'sets the pool to the hosts parent root pool' do
89
+ it "sets the pool to the hosts parent root pool" do
90
90
  expect(subject.location.pool).to be subject.location.host.parent.resourcePool
91
91
  end
92
92
  end
93
93
 
94
- context 'not specifying a pool or host when cloning from a template' do
94
+ context "not specifying a pool or host when cloning from a template" do
95
95
  before do
96
96
  allow(vm_template).to receive_message_chain(:config, :template)
97
97
  .and_return(true)
98
98
  end
99
99
 
100
- it 'raises an error' do
100
+ it "raises an error" do
101
101
  expect { subject }.to raise_error(RuntimeError)
102
102
  end
103
103
  end
104
104
 
105
- context 'specifying a hostname' do
105
+ context "specifying a hostname" do
106
106
  before do
107
107
  options[:customization_spec] = {
108
108
  ipsettings: {},
109
109
  hostname: hostname,
110
- domain: 'local'
110
+ domain: "local",
111
111
  }
112
112
  end
113
113
 
114
- context 'alpha characters only' do
115
- let(:hostname) { 'myhost' }
114
+ context "alpha characters only" do
115
+ let(:hostname) { "myhost" }
116
116
 
117
- it 'sets the spec hostname' do
117
+ it "sets the spec hostname" do
118
118
  expect(subject.customization.identity.hostName.name).to eq hostname
119
119
  end
120
120
  end
121
121
 
122
- context 'alpha numeric characters only' do
123
- let(:hostname) { 'myhost01' }
122
+ context "alpha numeric characters only" do
123
+ let(:hostname) { "myhost01" }
124
124
 
125
- it 'sets the spec hostname' do
125
+ it "sets the spec hostname" do
126
126
  expect(subject.customization.identity.hostName.name).to eq hostname
127
127
  end
128
128
  end
129
129
 
130
- context 'containing a dash' do
131
- let(:hostname) { 'my-host01' }
130
+ context "containing a dash" do
131
+ let(:hostname) { "my-host01" }
132
132
 
133
- it 'sets the spec hostname' do
133
+ it "sets the spec hostname" do
134
134
  expect(subject.customization.identity.hostName.name).to eq hostname
135
135
  end
136
136
  end
137
137
 
138
- context 'containing an underscore' do
139
- let(:hostname) { 'my_host' }
138
+ context "containing an underscore" do
139
+ let(:hostname) { "my_host" }
140
140
 
141
- it 'raises an error' do
141
+ it "raises an error" do
142
142
  expect { subject }.to raise_error(RuntimeError)
143
143
  end
144
144
  end
145
145
 
146
- context 'starting with a dash' do
147
- let(:hostname) { '-myhost' }
146
+ context "starting with a dash" do
147
+ let(:hostname) { "-myhost" }
148
148
 
149
- it 'raises an error' do
149
+ it "raises an error" do
150
150
  expect { subject }.to raise_error(RuntimeError)
151
151
  end
152
152
  end
153
153
 
154
- context 'ending with a dash' do
155
- let(:hostname) { 'myhost-' }
154
+ context "ending with a dash" do
155
+ let(:hostname) { "myhost-" }
156
156
 
157
- it 'raises an error' do
157
+ it "raises an error" do
158
158
  expect { subject }.to raise_error(RuntimeError)
159
159
  end
160
160
  end