knife-ec2 0.13.0 → 0.14.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +3 -3
- data/CHANGELOG.md +6 -3
- data/CONTRIBUTIONS.md +0 -4
- data/DOC_CHANGES.md +5 -24
- data/Gemfile +1 -2
- data/RELEASE_NOTES.md +6 -22
- data/knife-ec2.gemspec +30 -29
- data/lib/chef/knife/ec2_flavor_list.rb +58 -53
- data/lib/chef/knife/ec2_server_create.rb +36 -11
- data/lib/knife-ec2/version.rb +1 -1
- data/spec/unit/ec2_flavor_list_spec.rb +74 -0
- data/spec/unit/ec2_server_create_spec.rb +641 -585
- data/spec/unit/ec2_server_list_spec.rb +131 -131
- metadata +7 -7
@@ -26,45 +26,15 @@ require 'chef/knife/bootstrap_windows_winrm'
|
|
26
26
|
require 'chef/knife/bootstrap_windows_ssh'
|
27
27
|
|
28
28
|
describe Chef::Knife::Ec2ServerCreate do
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
allow(@knife_ec2_create).to receive(:tcp_test_ssh).and_return(true)
|
33
|
-
|
34
|
-
{
|
35
|
-
:image => 'image',
|
36
|
-
:ssh_key_name => 'ssh_key_name',
|
37
|
-
:aws_access_key_id => 'aws_access_key_id',
|
38
|
-
:aws_secret_access_key => 'aws_secret_access_key',
|
39
|
-
:network_interfaces => ['eni-12345678',
|
40
|
-
'eni-87654321']
|
41
|
-
}.each do |key, value|
|
42
|
-
Chef::Config[:knife][key] = value
|
43
|
-
end
|
44
|
-
|
45
|
-
@my_vpc = 'vpc-12345678'
|
46
|
-
|
47
|
-
@ec2_connection = double(Fog::Compute::AWS)
|
48
|
-
allow(@ec2_connection).to receive(:tags).and_return double('create', :create => true)
|
49
|
-
allow(@ec2_connection).to receive_message_chain(:images, :get).and_return double('ami', :root_device_type => 'not_ebs', :platform => 'linux')
|
50
|
-
allow(@ec2_connection).to receive(:addresses).and_return [double('addesses', {
|
51
|
-
:domain => 'standard',
|
52
|
-
:public_ip => '111.111.111.111',
|
53
|
-
:server_id => nil,
|
54
|
-
:allocation_id => ''})]
|
29
|
+
let(:knife_ec2_create) { Chef::Knife::Ec2ServerCreate.new }
|
30
|
+
let(:ec2_connection) { double(Fog::Compute::AWS) }
|
31
|
+
let(:ec2_servers) { double() }
|
55
32
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
double('network_interfaces', network_interface_id: 'eni-87654321')
|
60
|
-
]
|
33
|
+
let(:new_ec2_server) { double }
|
34
|
+
let(:spot_requests) { double }
|
35
|
+
let(:new_spot_request) { double }
|
61
36
|
|
62
|
-
|
63
|
-
@new_ec2_server = double()
|
64
|
-
@spot_requests = double
|
65
|
-
@new_spot_request = double
|
66
|
-
|
67
|
-
@ec2_server_attribs = { :id => 'i-39382318',
|
37
|
+
let(:ec2_server_attribs) { { :id => 'i-39382318',
|
68
38
|
:flavor_id => 'm1.small',
|
69
39
|
:image_id => 'ami-47241231',
|
70
40
|
:placement_group => 'some_placement_group',
|
@@ -76,9 +46,9 @@ describe Chef::Knife::Ec2ServerCreate do
|
|
76
46
|
:public_ip_address => '75.101.253.10',
|
77
47
|
:private_dns_name => 'ip-10-251-75-20.ec2.internal',
|
78
48
|
:private_ip_address => '10.251.75.20',
|
79
|
-
:root_device_type => 'not_ebs' }
|
49
|
+
:root_device_type => 'not_ebs' } }
|
80
50
|
|
81
|
-
|
51
|
+
let(:spot_request_attribs) { { :id => 'test_spot_request_id',
|
82
52
|
:price => 0.001,
|
83
53
|
:request_type => 'persistent',
|
84
54
|
:created_at => '2015-07-14 09:53:11 UTC',
|
@@ -88,18 +58,46 @@ describe Chef::Knife::Ec2ServerCreate do
|
|
88
58
|
:key_name => 'ssh_key_name',
|
89
59
|
:availability_zone => nil,
|
90
60
|
:flavor_id => 'm1.small',
|
91
|
-
:image_id => 'image' }
|
61
|
+
:image_id => 'image' } }
|
92
62
|
|
63
|
+
let(:my_vpc) { 'vpc-12345678' }
|
93
64
|
|
94
|
-
|
95
|
-
|
65
|
+
before(:each) do
|
66
|
+
knife_ec2_create.initial_sleep_delay = 0
|
67
|
+
allow(knife_ec2_create).to receive(:tcp_test_ssh).and_return(true)
|
68
|
+
|
69
|
+
{
|
70
|
+
:image => 'image',
|
71
|
+
:ssh_key_name => 'ssh_key_name',
|
72
|
+
:aws_access_key_id => 'aws_access_key_id',
|
73
|
+
:aws_secret_access_key => 'aws_secret_access_key',
|
74
|
+
:network_interfaces => ['eni-12345678',
|
75
|
+
'eni-87654321']
|
76
|
+
}.each do |key, value|
|
77
|
+
Chef::Config[:knife][key] = value
|
96
78
|
end
|
97
79
|
|
98
|
-
|
99
|
-
|
80
|
+
allow(ec2_connection).to receive(:tags).and_return double('create', :create => true)
|
81
|
+
allow(ec2_connection).to receive_message_chain(:images, :get).and_return double('ami', :root_device_type => 'not_ebs', :platform => 'linux')
|
82
|
+
allow(ec2_connection).to receive(:addresses).and_return [double('addesses', {
|
83
|
+
:domain => 'standard',
|
84
|
+
:public_ip => '111.111.111.111',
|
85
|
+
:server_id => nil,
|
86
|
+
:allocation_id => ''})]
|
87
|
+
|
88
|
+
allow(ec2_connection).to receive(:subnets).and_return [@subnet_1, @subnet_2]
|
89
|
+
allow(ec2_connection).to receive_message_chain(:network_interfaces, :all).and_return [
|
90
|
+
double('network_interfaces', network_interface_id: 'eni-12345678'),
|
91
|
+
double('network_interfaces', network_interface_id: 'eni-87654321')
|
92
|
+
]
|
93
|
+
|
94
|
+
ec2_server_attribs.each_pair do |attrib, value|
|
95
|
+
allow(new_ec2_server).to receive(attrib).and_return(value)
|
100
96
|
end
|
101
97
|
|
102
|
-
|
98
|
+
spot_request_attribs.each_pair do |attrib, value|
|
99
|
+
allow(new_spot_request).to receive(attrib).and_return(value)
|
100
|
+
end
|
103
101
|
|
104
102
|
@bootstrap = Chef::Knife::Bootstrap.new
|
105
103
|
allow(Chef::Knife::Bootstrap).to receive(:new).and_return(@bootstrap)
|
@@ -113,20 +111,20 @@ describe Chef::Knife::Ec2ServerCreate do
|
|
113
111
|
|
114
112
|
describe "Spot Instance creation" do
|
115
113
|
before do
|
116
|
-
allow(Fog::Compute::AWS).to receive(:new).and_return(
|
117
|
-
|
118
|
-
|
119
|
-
allow(
|
120
|
-
allow(
|
121
|
-
allow(
|
122
|
-
allow(
|
114
|
+
allow(Fog::Compute::AWS).to receive(:new).and_return(ec2_connection)
|
115
|
+
knife_ec2_create.config[:spot_price] = 0.001
|
116
|
+
knife_ec2_create.config[:spot_request_type] = 'persistent'
|
117
|
+
allow(knife_ec2_create).to receive(:puts)
|
118
|
+
allow(knife_ec2_create).to receive(:msg_pair)
|
119
|
+
allow(knife_ec2_create.ui).to receive(:color).and_return('')
|
120
|
+
allow(knife_ec2_create).to receive(:confirm)
|
123
121
|
@spot_instance_server_def = {
|
124
122
|
:image_id => "image",
|
125
123
|
:groups => nil,
|
126
|
-
:security_group_ids => nil,
|
127
124
|
:flavor_id => nil,
|
128
125
|
:key_name => "ssh_key_name",
|
129
126
|
:availability_zone => nil,
|
127
|
+
:security_group_ids => nil,
|
130
128
|
:price => 0.001,
|
131
129
|
:request_type => 'persistent',
|
132
130
|
:placement_group => nil,
|
@@ -137,69 +135,69 @@ describe Chef::Knife::Ec2ServerCreate do
|
|
137
135
|
end
|
138
136
|
|
139
137
|
it "creates a new spot instance request with request type as persistent" do
|
140
|
-
expect(
|
141
|
-
:spot_requests).and_return(
|
142
|
-
expect(
|
143
|
-
:create).with(@spot_instance_server_def).and_return(
|
144
|
-
|
145
|
-
allow(
|
146
|
-
allow(
|
147
|
-
allow(
|
148
|
-
:get).with(
|
149
|
-
allow(
|
150
|
-
|
151
|
-
expect(
|
138
|
+
expect(ec2_connection).to receive(
|
139
|
+
:spot_requests).and_return(spot_requests)
|
140
|
+
expect(spot_requests).to receive(
|
141
|
+
:create).with(@spot_instance_server_def).and_return(new_spot_request)
|
142
|
+
knife_ec2_create.config[:yes] = true
|
143
|
+
allow(new_spot_request).to receive(:wait_for).and_return(true)
|
144
|
+
allow(ec2_connection).to receive(:servers).and_return(ec2_servers)
|
145
|
+
allow(ec2_servers).to receive(
|
146
|
+
:get).with(new_spot_request.instance_id).and_return(new_ec2_server)
|
147
|
+
allow(new_ec2_server).to receive(:wait_for).and_return(true)
|
148
|
+
knife_ec2_create.run
|
149
|
+
expect(new_spot_request.request_type).to eq('persistent')
|
152
150
|
end
|
153
151
|
|
154
152
|
it "successfully creates a new spot instance" do
|
155
|
-
allow(
|
156
|
-
:spot_requests).and_return(
|
157
|
-
allow(
|
158
|
-
:create).with(@spot_instance_server_def).and_return(
|
159
|
-
|
160
|
-
expect(
|
161
|
-
expect(
|
162
|
-
expect(
|
163
|
-
:get).with(
|
164
|
-
expect(
|
165
|
-
|
153
|
+
allow(ec2_connection).to receive(
|
154
|
+
:spot_requests).and_return(spot_requests)
|
155
|
+
allow(spot_requests).to receive(
|
156
|
+
:create).with(@spot_instance_server_def).and_return(new_spot_request)
|
157
|
+
knife_ec2_create.config[:yes] = true
|
158
|
+
expect(new_spot_request).to receive(:wait_for).and_return(true)
|
159
|
+
expect(ec2_connection).to receive(:servers).and_return(ec2_servers)
|
160
|
+
expect(ec2_servers).to receive(
|
161
|
+
:get).with(new_spot_request.instance_id).and_return(new_ec2_server)
|
162
|
+
expect(new_ec2_server).to receive(:wait_for).and_return(true)
|
163
|
+
knife_ec2_create.run
|
166
164
|
end
|
167
165
|
|
168
166
|
it "does not create the spot instance request and creates a regular instance" do
|
169
|
-
|
170
|
-
expect(
|
171
|
-
expect(
|
172
|
-
:create).and_return(
|
173
|
-
expect(
|
174
|
-
|
167
|
+
knife_ec2_create.config.delete(:spot_price)
|
168
|
+
expect(ec2_connection).to receive(:servers).and_return(ec2_servers)
|
169
|
+
expect(ec2_servers).to receive(
|
170
|
+
:create).and_return(new_ec2_server)
|
171
|
+
expect(new_ec2_server).to receive(:wait_for).and_return(true)
|
172
|
+
knife_ec2_create.run
|
175
173
|
end
|
176
174
|
|
177
175
|
context 'spot-wait-mode option' do
|
178
176
|
context 'when spot-price is not given' do
|
179
177
|
context 'spot-wait-mode option is not given' do
|
180
178
|
before do
|
181
|
-
|
179
|
+
knife_ec2_create.config.delete(:spot_price)
|
182
180
|
end
|
183
181
|
|
184
182
|
it 'does not raise error' do
|
185
|
-
expect(
|
183
|
+
expect(knife_ec2_create.ui).to_not receive(:error).with(
|
186
184
|
'spot-wait-mode option requires that a spot-price option is set.'
|
187
185
|
)
|
188
|
-
expect {
|
186
|
+
expect { knife_ec2_create.validate! }.to_not raise_error
|
189
187
|
end
|
190
188
|
end
|
191
189
|
|
192
190
|
context 'spot-wait-mode option is given' do
|
193
191
|
before do
|
194
|
-
|
195
|
-
|
192
|
+
knife_ec2_create.config.delete(:spot_price)
|
193
|
+
knife_ec2_create.config[:spot_wait_mode] = 'wait'
|
196
194
|
end
|
197
195
|
|
198
196
|
it 'raises error' do
|
199
|
-
expect(
|
197
|
+
expect(knife_ec2_create.ui).to receive(:error).with(
|
200
198
|
'spot-wait-mode option requires that a spot-price option is set.'
|
201
199
|
)
|
202
|
-
expect {
|
200
|
+
expect { knife_ec2_create.validate! }.to raise_error(SystemExit)
|
203
201
|
end
|
204
202
|
end
|
205
203
|
end
|
@@ -207,28 +205,28 @@ describe Chef::Knife::Ec2ServerCreate do
|
|
207
205
|
context 'when spot-price is given' do
|
208
206
|
context 'spot-wait-mode option is not given' do
|
209
207
|
before do
|
210
|
-
|
208
|
+
knife_ec2_create.config[:spot_price] = 0.001
|
211
209
|
end
|
212
210
|
|
213
211
|
it 'does not raise error' do
|
214
|
-
expect(
|
212
|
+
expect(knife_ec2_create.ui).to_not receive(:error).with(
|
215
213
|
'spot-wait-mode option requires that a spot-price option is set.'
|
216
214
|
)
|
217
|
-
expect {
|
215
|
+
expect { knife_ec2_create.validate! }.to_not raise_error
|
218
216
|
end
|
219
217
|
end
|
220
218
|
|
221
219
|
context 'spot-wait-mode option is given' do
|
222
220
|
before do
|
223
|
-
|
224
|
-
|
221
|
+
knife_ec2_create.config[:spot_price] = 0.001
|
222
|
+
knife_ec2_create.config[:spot_wait_mode] = 'exit'
|
225
223
|
end
|
226
224
|
|
227
225
|
it 'does not raise error' do
|
228
|
-
expect(
|
226
|
+
expect(knife_ec2_create.ui).to_not receive(:error).with(
|
229
227
|
'spot-wait-mode option requires that a spot-price option is set.'
|
230
228
|
)
|
231
|
-
expect {
|
229
|
+
expect { knife_ec2_create.validate! }.to_not raise_error
|
232
230
|
end
|
233
231
|
end
|
234
232
|
end
|
@@ -237,255 +235,255 @@ describe Chef::Knife::Ec2ServerCreate do
|
|
237
235
|
|
238
236
|
describe "run" do
|
239
237
|
before do
|
240
|
-
expect(
|
241
|
-
expect(
|
242
|
-
expect(
|
238
|
+
expect(ec2_servers).to receive(:create).and_return(new_ec2_server)
|
239
|
+
expect(ec2_connection).to receive(:servers).and_return(ec2_servers)
|
240
|
+
expect(ec2_connection).to receive(:addresses)
|
243
241
|
|
244
242
|
@eip = "111.111.111.111"
|
245
|
-
expect(Fog::Compute::AWS).to receive(:new).and_return(
|
243
|
+
expect(Fog::Compute::AWS).to receive(:new).and_return(ec2_connection)
|
246
244
|
|
247
|
-
allow(
|
248
|
-
allow(
|
249
|
-
|
245
|
+
allow(knife_ec2_create).to receive(:puts)
|
246
|
+
allow(knife_ec2_create).to receive(:print)
|
247
|
+
knife_ec2_create.config[:image] = '12345'
|
250
248
|
expect(@bootstrap).to receive(:run)
|
251
249
|
end
|
252
250
|
|
253
251
|
it "defaults to a distro of 'chef-full' for a linux instance" do
|
254
|
-
expect(
|
255
|
-
|
256
|
-
expect(
|
257
|
-
|
252
|
+
expect(new_ec2_server).to receive(:wait_for).and_return(true)
|
253
|
+
knife_ec2_create.config[:distro] = knife_ec2_create.options[:distro][:default]
|
254
|
+
expect(knife_ec2_create).to receive(:default_bootstrap_template).and_return('chef-full')
|
255
|
+
knife_ec2_create.run
|
258
256
|
end
|
259
257
|
|
260
258
|
it "creates an EC2 instance and bootstraps it" do
|
261
|
-
expect(
|
262
|
-
expect(
|
263
|
-
|
264
|
-
expect(
|
259
|
+
expect(new_ec2_server).to receive(:wait_for).and_return(true)
|
260
|
+
expect(knife_ec2_create).to receive(:ssh_override_winrm)
|
261
|
+
knife_ec2_create.run
|
262
|
+
expect(knife_ec2_create.server).to_not be_nil
|
265
263
|
end
|
266
264
|
|
267
265
|
it "set ssh_user value by using -x option for ssh bootstrap protocol or linux image" do
|
268
266
|
# Currently -x option set config[:winrm_user]
|
269
267
|
# default value of config[:ssh_user] is root
|
270
|
-
|
271
|
-
|
268
|
+
knife_ec2_create.config[:winrm_user] = "ubuntu"
|
269
|
+
knife_ec2_create.config[:ssh_user] = "root"
|
272
270
|
|
273
|
-
expect(
|
274
|
-
|
275
|
-
expect(
|
276
|
-
expect(
|
271
|
+
expect(new_ec2_server).to receive(:wait_for).and_return(true)
|
272
|
+
knife_ec2_create.run
|
273
|
+
expect(knife_ec2_create.config[:ssh_user]).to eq("ubuntu")
|
274
|
+
expect(knife_ec2_create.server).to_not be_nil
|
277
275
|
end
|
278
276
|
|
279
277
|
it "set ssh_password value by using -P option for ssh bootstrap protocol or linux image" do
|
280
278
|
# Currently -P option set config[:winrm_password]
|
281
279
|
# default value of config[:ssh_password] is nil
|
282
|
-
|
283
|
-
|
280
|
+
knife_ec2_create.config[:winrm_password] = "winrm_password"
|
281
|
+
knife_ec2_create.config[:ssh_password] = nil
|
284
282
|
|
285
|
-
expect(
|
286
|
-
|
287
|
-
expect(
|
288
|
-
expect(
|
283
|
+
expect(new_ec2_server).to receive(:wait_for).and_return(true)
|
284
|
+
knife_ec2_create.run
|
285
|
+
expect(knife_ec2_create.config[:ssh_password]).to eq("winrm_password")
|
286
|
+
expect(knife_ec2_create.server).to_not be_nil
|
289
287
|
end
|
290
288
|
|
291
289
|
it "set ssh_port value by using -p option for ssh bootstrap protocol or linux image" do
|
292
290
|
# Currently -p option set config[:winrm_port]
|
293
291
|
# default value of config[:ssh_port] is 22
|
294
|
-
|
295
|
-
|
292
|
+
knife_ec2_create.config[:winrm_port] = "1234"
|
293
|
+
knife_ec2_create.config[:ssh_port] = "22"
|
296
294
|
|
297
|
-
expect(
|
298
|
-
|
299
|
-
expect(
|
300
|
-
expect(
|
295
|
+
expect(new_ec2_server).to receive(:wait_for).and_return(true)
|
296
|
+
knife_ec2_create.run
|
297
|
+
expect(knife_ec2_create.config[:ssh_port]).to eq("1234")
|
298
|
+
expect(knife_ec2_create.server).to_not be_nil
|
301
299
|
end
|
302
300
|
|
303
301
|
it "set identity_file value by using -i option for ssh bootstrap protocol or linux image" do
|
304
302
|
# Currently -i option set config[:kerberos_keytab_file]
|
305
303
|
# default value of config[:identity_file] is nil
|
306
|
-
|
307
|
-
|
304
|
+
knife_ec2_create.config[:kerberos_keytab_file] = "kerberos_keytab_file"
|
305
|
+
knife_ec2_create.config[:identity_file] = nil
|
308
306
|
|
309
|
-
expect(
|
310
|
-
|
311
|
-
expect(
|
312
|
-
expect(
|
307
|
+
expect(new_ec2_server).to receive(:wait_for).and_return(true)
|
308
|
+
knife_ec2_create.run
|
309
|
+
expect(knife_ec2_create.config[:identity_file]).to eq("kerberos_keytab_file")
|
310
|
+
expect(knife_ec2_create.server).to_not be_nil
|
313
311
|
end
|
314
312
|
|
315
313
|
it "should never invoke windows bootstrap for linux instance" do
|
316
|
-
expect(
|
317
|
-
expect(
|
318
|
-
|
314
|
+
expect(new_ec2_server).to receive(:wait_for).and_return(true)
|
315
|
+
expect(knife_ec2_create).not_to receive(:bootstrap_for_windows_node)
|
316
|
+
knife_ec2_create.run
|
319
317
|
end
|
320
318
|
|
321
319
|
it "creates an EC2 instance, assigns existing EIP and bootstraps it" do
|
322
|
-
|
320
|
+
knife_ec2_create.config[:associate_eip] = @eip
|
323
321
|
|
324
|
-
allow(
|
325
|
-
expect(
|
326
|
-
expect(
|
322
|
+
allow(new_ec2_server).to receive(:public_ip_address).and_return(@eip)
|
323
|
+
expect(ec2_connection).to receive(:associate_address).with(ec2_server_attribs[:id], @eip, nil, '')
|
324
|
+
expect(new_ec2_server).to receive(:wait_for).at_least(:twice).and_return(true)
|
327
325
|
|
328
|
-
|
329
|
-
expect(
|
326
|
+
knife_ec2_create.run
|
327
|
+
expect(knife_ec2_create.server).to_not be_nil
|
330
328
|
end
|
331
329
|
|
332
330
|
it "creates an EC2 instance, enables ClassicLink and bootstraps it" do
|
333
|
-
|
334
|
-
|
331
|
+
knife_ec2_create.config[:classic_link_vpc_id] = @vpc_id
|
332
|
+
knife_ec2_create.config[:classic_link_vpc_security_group_ids] = @vpc_security_group_ids
|
335
333
|
|
336
|
-
expect(
|
337
|
-
expect(
|
334
|
+
expect(ec2_connection).to receive(:attach_classic_link_vpc).with(ec2_server_attribs[:id], @vpc_id, @vpc_security_group_ids)
|
335
|
+
expect(new_ec2_server).to receive(:wait_for).and_return(true)
|
338
336
|
|
339
|
-
|
340
|
-
expect(
|
337
|
+
knife_ec2_create.run
|
338
|
+
expect(knife_ec2_create.server).to_not be_nil
|
341
339
|
end
|
342
340
|
|
343
341
|
it "retries if it receives Fog::Compute::AWS::NotFound" do
|
344
|
-
expect(
|
345
|
-
expect(
|
346
|
-
expect(
|
347
|
-
expect(
|
348
|
-
expect(
|
349
|
-
|
342
|
+
expect(new_ec2_server).to receive(:wait_for).and_return(true)
|
343
|
+
expect(knife_ec2_create).to receive(:create_tags).and_raise(Fog::Compute::AWS::NotFound)
|
344
|
+
expect(knife_ec2_create).to receive(:create_tags).and_return(true)
|
345
|
+
expect(knife_ec2_create).to receive(:sleep).and_return(true)
|
346
|
+
expect(knife_ec2_create.ui).to receive(:warn).with(/retrying/)
|
347
|
+
knife_ec2_create.run
|
350
348
|
end
|
351
349
|
|
352
350
|
it 'actually writes to the validation key tempfile' do
|
353
|
-
expect(
|
351
|
+
expect(new_ec2_server).to receive(:wait_for).and_return(true)
|
354
352
|
Chef::Config[:knife][:validation_key_url] = @validation_key_url
|
355
|
-
|
353
|
+
knife_ec2_create.config[:validation_key_url] = @validation_key_url
|
356
354
|
|
357
|
-
allow(
|
355
|
+
allow(knife_ec2_create).to receive_message_chain(:validation_key_tmpfile, :path).and_return(@validation_key_file)
|
358
356
|
allow(Chef::Knife::S3Source).to receive(:fetch).with(@validation_key_url).and_return(@validation_key_body)
|
359
357
|
expect(File).to receive(:open).with(@validation_key_file, 'w')
|
360
|
-
|
358
|
+
knife_ec2_create.run
|
361
359
|
end
|
362
360
|
end
|
363
361
|
|
364
362
|
describe "run for EC2 Windows instance" do
|
365
363
|
before do
|
366
|
-
expect(
|
367
|
-
expect(
|
368
|
-
expect(
|
364
|
+
expect(ec2_servers).to receive(:create).and_return(new_ec2_server)
|
365
|
+
expect(ec2_connection).to receive(:servers).and_return(ec2_servers)
|
366
|
+
expect(ec2_connection).to receive(:addresses)
|
369
367
|
|
370
|
-
expect(Fog::Compute::AWS).to receive(:new).and_return(
|
368
|
+
expect(Fog::Compute::AWS).to receive(:new).and_return(ec2_connection)
|
371
369
|
|
372
|
-
allow(
|
373
|
-
allow(
|
374
|
-
|
375
|
-
|
376
|
-
allow(
|
377
|
-
allow(
|
370
|
+
allow(knife_ec2_create).to receive(:puts)
|
371
|
+
allow(knife_ec2_create).to receive(:print)
|
372
|
+
knife_ec2_create.config[:identity_file] = "~/.ssh/aws-key.pem"
|
373
|
+
knife_ec2_create.config[:image] = '12345'
|
374
|
+
allow(knife_ec2_create).to receive(:is_image_windows?).and_return(true)
|
375
|
+
allow(knife_ec2_create).to receive(:tcp_test_winrm).and_return(true)
|
378
376
|
end
|
379
377
|
|
380
378
|
it "bootstraps via the WinRM protocol" do
|
381
|
-
|
382
|
-
|
379
|
+
knife_ec2_create.config[:winrm_password] = 'winrm-password'
|
380
|
+
knife_ec2_create.config[:bootstrap_protocol] = 'winrm'
|
383
381
|
@bootstrap_winrm = Chef::Knife::BootstrapWindowsWinrm.new
|
384
382
|
allow(Chef::Knife::BootstrapWindowsWinrm).to receive(:new).and_return(@bootstrap_winrm)
|
385
383
|
expect(@bootstrap_winrm).to receive(:run)
|
386
|
-
expect(
|
387
|
-
expect(
|
388
|
-
|
384
|
+
expect(knife_ec2_create).not_to receive(:ssh_override_winrm)
|
385
|
+
expect(new_ec2_server).to receive(:wait_for).and_return(true)
|
386
|
+
knife_ec2_create.run
|
389
387
|
end
|
390
388
|
|
391
389
|
it "set default distro to windows-chef-client-msi for windows" do
|
392
|
-
|
393
|
-
|
390
|
+
knife_ec2_create.config[:winrm_password] = 'winrm-password'
|
391
|
+
knife_ec2_create.config[:bootstrap_protocol] = 'winrm'
|
394
392
|
@bootstrap_winrm = Chef::Knife::BootstrapWindowsWinrm.new
|
395
393
|
allow(Chef::Knife::BootstrapWindowsWinrm).to receive(:new).and_return(@bootstrap_winrm)
|
396
394
|
expect(@bootstrap_winrm).to receive(:run)
|
397
|
-
expect(
|
398
|
-
allow(
|
399
|
-
expect(
|
400
|
-
|
395
|
+
expect(new_ec2_server).to receive(:wait_for).and_return(true)
|
396
|
+
allow(knife_ec2_create).to receive(:is_image_windows?).and_return(true)
|
397
|
+
expect(knife_ec2_create).to receive(:default_bootstrap_template).and_return("windows-chef-client-msi")
|
398
|
+
knife_ec2_create.run
|
401
399
|
end
|
402
400
|
|
403
401
|
it "bootstraps via the SSH protocol" do
|
404
|
-
|
402
|
+
knife_ec2_create.config[:bootstrap_protocol] = 'ssh'
|
405
403
|
bootstrap_win_ssh = Chef::Knife::BootstrapWindowsSsh.new
|
406
404
|
allow(Chef::Knife::BootstrapWindowsSsh).to receive(:new).and_return(bootstrap_win_ssh)
|
407
405
|
expect(bootstrap_win_ssh).to receive(:run)
|
408
|
-
expect(
|
409
|
-
expect(
|
410
|
-
|
406
|
+
expect(knife_ec2_create).to receive(:ssh_override_winrm)
|
407
|
+
expect(new_ec2_server).to receive(:wait_for).and_return(true)
|
408
|
+
knife_ec2_create.run
|
411
409
|
end
|
412
410
|
|
413
411
|
it "should use configured SSH port" do
|
414
|
-
|
415
|
-
|
412
|
+
knife_ec2_create.config[:bootstrap_protocol] = 'ssh'
|
413
|
+
knife_ec2_create.config[:ssh_port] = 422
|
416
414
|
|
417
|
-
expect(
|
415
|
+
expect(knife_ec2_create).to receive(:tcp_test_ssh).with('ec2-75.101.253.10.compute-1.amazonaws.com', 422).and_return(true)
|
418
416
|
|
419
417
|
bootstrap_win_ssh = Chef::Knife::BootstrapWindowsSsh.new
|
420
418
|
allow(Chef::Knife::BootstrapWindowsSsh).to receive(:new).and_return(bootstrap_win_ssh)
|
421
419
|
expect(bootstrap_win_ssh).to receive(:run)
|
422
|
-
expect(
|
423
|
-
|
420
|
+
expect(new_ec2_server).to receive(:wait_for).and_return(true)
|
421
|
+
knife_ec2_create.run
|
424
422
|
end
|
425
423
|
|
426
424
|
it "should never invoke linux bootstrap" do
|
427
|
-
|
428
|
-
allow(
|
429
|
-
expect(
|
430
|
-
expect(
|
431
|
-
allow(
|
432
|
-
|
425
|
+
knife_ec2_create.config[:bootstrap_protocol] = 'winrm'
|
426
|
+
allow(knife_ec2_create).to receive(:windows_password).and_return("")
|
427
|
+
expect(knife_ec2_create).not_to receive(:bootstrap_for_linux_node)
|
428
|
+
expect(new_ec2_server).to receive(:wait_for).and_return(true)
|
429
|
+
allow(knife_ec2_create).to receive(:bootstrap_for_windows_node).and_return double("bootstrap", :run => true)
|
430
|
+
knife_ec2_create.run
|
433
431
|
end
|
434
432
|
|
435
433
|
it "waits for EC2 to generate password if not supplied" do
|
436
|
-
|
437
|
-
|
438
|
-
expect(
|
439
|
-
allow(
|
440
|
-
allow(
|
434
|
+
knife_ec2_create.config[:bootstrap_protocol] = 'winrm'
|
435
|
+
knife_ec2_create.config[:winrm_password] = nil
|
436
|
+
expect(knife_ec2_create).to receive(:windows_password).and_return("")
|
437
|
+
allow(new_ec2_server).to receive(:wait_for).and_return(true)
|
438
|
+
allow(knife_ec2_create).to receive(:check_windows_password_available).and_return(true)
|
441
439
|
bootstrap_winrm = Chef::Knife::BootstrapWindowsWinrm.new
|
442
440
|
allow(Chef::Knife::BootstrapWindowsWinrm).to receive(:new).and_return(bootstrap_winrm)
|
443
441
|
expect(bootstrap_winrm).to receive(:run)
|
444
|
-
|
442
|
+
knife_ec2_create.run
|
445
443
|
end
|
446
444
|
end
|
447
445
|
|
448
446
|
describe "when setting tags" do
|
449
447
|
before do
|
450
|
-
expect(Fog::Compute::AWS).to receive(:new).and_return(
|
451
|
-
allow(
|
452
|
-
allow(
|
453
|
-
expect(
|
454
|
-
allow(
|
455
|
-
allow(
|
456
|
-
allow(
|
457
|
-
allow(
|
448
|
+
expect(Fog::Compute::AWS).to receive(:new).and_return(ec2_connection)
|
449
|
+
allow(knife_ec2_create).to receive(:bootstrap_for_linux_node).and_return double("bootstrap", :run => true)
|
450
|
+
allow(ec2_connection).to receive(:servers).and_return(ec2_servers)
|
451
|
+
expect(ec2_connection).to receive(:addresses)
|
452
|
+
allow(new_ec2_server).to receive(:wait_for).and_return(true)
|
453
|
+
allow(ec2_servers).to receive(:create).and_return(new_ec2_server)
|
454
|
+
allow(knife_ec2_create).to receive(:puts)
|
455
|
+
allow(knife_ec2_create).to receive(:print)
|
458
456
|
end
|
459
457
|
|
460
458
|
it "sets the Name tag to the instance id by default" do
|
461
|
-
expect(
|
462
|
-
:value =>
|
463
|
-
:resource_id =>
|
464
|
-
|
459
|
+
expect(ec2_connection.tags).to receive(:create).with(:key => "Name",
|
460
|
+
:value => new_ec2_server.id,
|
461
|
+
:resource_id => new_ec2_server.id)
|
462
|
+
knife_ec2_create.run
|
465
463
|
end
|
466
464
|
|
467
465
|
it "sets the Name tag to the chef_node_name when given" do
|
468
|
-
|
469
|
-
expect(
|
466
|
+
knife_ec2_create.config[:chef_node_name] = "wombat"
|
467
|
+
expect(ec2_connection.tags).to receive(:create).with(:key => "Name",
|
470
468
|
:value => "wombat",
|
471
|
-
:resource_id =>
|
472
|
-
|
469
|
+
:resource_id => new_ec2_server.id)
|
470
|
+
knife_ec2_create.run
|
473
471
|
end
|
474
472
|
|
475
473
|
it "sets the Name tag to the specified name when given --tags Name=NAME" do
|
476
|
-
|
477
|
-
expect(
|
474
|
+
knife_ec2_create.config[:tags] = ["Name=bobcat"]
|
475
|
+
expect(ec2_connection.tags).to receive(:create).with(:key => "Name",
|
478
476
|
:value => "bobcat",
|
479
|
-
:resource_id =>
|
480
|
-
|
477
|
+
:resource_id => new_ec2_server.id)
|
478
|
+
knife_ec2_create.run
|
481
479
|
end
|
482
480
|
|
483
481
|
it "sets arbitrary tags" do
|
484
|
-
|
485
|
-
expect(
|
482
|
+
knife_ec2_create.config[:tags] = ["foo=bar"]
|
483
|
+
expect(ec2_connection.tags).to receive(:create).with(:key => "foo",
|
486
484
|
:value => "bar",
|
487
|
-
:resource_id =>
|
488
|
-
|
485
|
+
:resource_id => new_ec2_server.id)
|
486
|
+
knife_ec2_create.run
|
489
487
|
end
|
490
488
|
|
491
489
|
end
|
@@ -537,7 +535,7 @@ describe Chef::Knife::Ec2ServerCreate do
|
|
537
535
|
Chef::Config[:knife][:s3_secret] =
|
538
536
|
's3://test.bucket/folder/encrypted_data_bag_secret'
|
539
537
|
@secret_content = "TEST DATA BAG SECRET\n"
|
540
|
-
allow(
|
538
|
+
allow(knife_ec2_create).to receive(:s3_secret).and_return(@secret_content)
|
541
539
|
end
|
542
540
|
|
543
541
|
it 'sets the secret to the expected test string' do
|
@@ -550,16 +548,16 @@ describe Chef::Knife::Ec2ServerCreate do
|
|
550
548
|
before do
|
551
549
|
Chef::Config[:knife][:s3_secret] =
|
552
550
|
's3://test.bucket/folder/encrypted_data_bag_secret'
|
553
|
-
|
551
|
+
knife_ec2_create.config[:distro] = 'ubuntu-10.04-magic-sparkles'
|
554
552
|
@secret_content = "TEST DATA BAG SECRET\n"
|
555
|
-
allow(
|
553
|
+
allow(knife_ec2_create).to receive(:s3_secret).and_return(@secret_content)
|
556
554
|
allow(Chef::Knife).to receive(:Bootstrap)
|
557
|
-
@bootstrap =
|
555
|
+
@bootstrap = knife_ec2_create.bootstrap_for_linux_node(new_ec2_server, new_ec2_server.dns_name)
|
558
556
|
end
|
559
557
|
|
560
558
|
context 'when s3 secret option is passed' do
|
561
559
|
it 'sets the s3 secret value to cl_secret key' do
|
562
|
-
|
560
|
+
knife_ec2_create.bootstrap_common_params(@bootstrap)
|
563
561
|
expect(Chef::Config[:knife][:cl_secret]).to eql(@secret_content)
|
564
562
|
end
|
565
563
|
end
|
@@ -568,7 +566,7 @@ describe Chef::Knife::Ec2ServerCreate do
|
|
568
566
|
it 'sets the cl_secret value to nil' do
|
569
567
|
Chef::Config[:knife].delete(:s3_secret)
|
570
568
|
Chef::Config[:knife].delete(:cl_secret)
|
571
|
-
|
569
|
+
knife_ec2_create.bootstrap_common_params(@bootstrap)
|
572
570
|
expect(Chef::Config[:knife][:cl_secret]).to eql(nil)
|
573
571
|
end
|
574
572
|
end
|
@@ -579,13 +577,13 @@ describe Chef::Knife::Ec2ServerCreate do
|
|
579
577
|
Chef::Config[:knife][:aws_ssh_key_id] = "mykey"
|
580
578
|
Chef::Config[:knife].delete(:ssh_key_name)
|
581
579
|
@aws_key = Chef::Config[:knife][:aws_ssh_key_id]
|
582
|
-
allow(
|
583
|
-
allow(
|
580
|
+
allow(knife_ec2_create).to receive(:ami).and_return(false)
|
581
|
+
allow(knife_ec2_create).to receive(:validate_nics!).and_return(true)
|
584
582
|
end
|
585
583
|
|
586
584
|
it "gives warning message and creates the attribute with the required name" do
|
587
|
-
expect(
|
588
|
-
|
585
|
+
expect(knife_ec2_create.ui).to receive(:warn).with("Use of aws_ssh_key_id option in knife.rb config is deprecated, use ssh_key_name option instead.")
|
586
|
+
knife_ec2_create.validate!
|
589
587
|
expect(Chef::Config[:knife][:ssh_key_name]).to eq(@aws_key)
|
590
588
|
end
|
591
589
|
end
|
@@ -594,13 +592,13 @@ describe Chef::Knife::Ec2ServerCreate do
|
|
594
592
|
before do
|
595
593
|
Chef::Config[:knife][:aws_ssh_key_id] = "mykey"
|
596
594
|
@aws_key = Chef::Config[:knife][:aws_ssh_key_id]
|
597
|
-
allow(
|
598
|
-
allow(
|
595
|
+
allow(knife_ec2_create).to receive(:ami).and_return(false)
|
596
|
+
allow(knife_ec2_create).to receive(:validate_nics!).and_return(true)
|
599
597
|
end
|
600
598
|
|
601
599
|
it "gives warning message and gives preference to CLI value over knife config's value" do
|
602
|
-
expect(
|
603
|
-
|
600
|
+
expect(knife_ec2_create.ui).to receive(:warn).with("Use of aws_ssh_key_id option in knife.rb config is deprecated, use ssh_key_name option instead.")
|
601
|
+
knife_ec2_create.validate!
|
604
602
|
expect(Chef::Config[:knife][:ssh_key_name]).to_not eq(@aws_key)
|
605
603
|
end
|
606
604
|
end
|
@@ -608,48 +606,48 @@ describe Chef::Knife::Ec2ServerCreate do
|
|
608
606
|
context "when ssh_key_name option is used in knife config instead of deprecated aws_ssh_key_id option" do
|
609
607
|
before do
|
610
608
|
Chef::Config[:knife][:ssh_key_name] = "mykey"
|
611
|
-
allow(
|
612
|
-
allow(
|
609
|
+
allow(knife_ec2_create).to receive(:ami).and_return(false)
|
610
|
+
allow(knife_ec2_create).to receive(:validate_nics!).and_return(true)
|
613
611
|
end
|
614
612
|
|
615
613
|
it "does nothing" do
|
616
|
-
|
614
|
+
knife_ec2_create.validate!
|
617
615
|
end
|
618
616
|
end
|
619
617
|
|
620
618
|
context "when ssh_key_name option is used in knife config also it is passed on the CLI" do
|
621
619
|
before do
|
622
|
-
allow(Fog::Compute::AWS).to receive(:new).and_return(
|
620
|
+
allow(Fog::Compute::AWS).to receive(:new).and_return(ec2_connection)
|
623
621
|
Chef::Config[:knife][:ssh_key_name] = "mykey"
|
624
|
-
|
622
|
+
knife_ec2_create.config[:ssh_key_name] = "ssh_key_name"
|
625
623
|
end
|
626
624
|
|
627
625
|
it "ssh-key passed over CLI gets preference over knife config value" do
|
628
|
-
server_def =
|
629
|
-
expect(server_def[:key_name]).to eq(
|
626
|
+
server_def = knife_ec2_create.create_server_def
|
627
|
+
expect(server_def[:key_name]).to eq(knife_ec2_create.config[:ssh_key_name])
|
630
628
|
end
|
631
629
|
end
|
632
630
|
|
633
631
|
describe "when configuring the bootstrap process" do
|
634
632
|
before do
|
635
|
-
|
636
|
-
|
637
|
-
|
638
|
-
|
639
|
-
|
640
|
-
|
641
|
-
|
642
|
-
|
643
|
-
|
644
|
-
|
633
|
+
knife_ec2_create.config[:ssh_user] = "ubuntu"
|
634
|
+
knife_ec2_create.config[:identity_file] = "~/.ssh/aws-key.pem"
|
635
|
+
knife_ec2_create.config[:ssh_port] = 22
|
636
|
+
knife_ec2_create.config[:ssh_gateway] = 'bastion.host.com'
|
637
|
+
knife_ec2_create.config[:chef_node_name] = "blarf"
|
638
|
+
knife_ec2_create.config[:template_file] = '~/.chef/templates/my-bootstrap.sh.erb'
|
639
|
+
knife_ec2_create.config[:distro] = 'ubuntu-10.04-magic-sparkles'
|
640
|
+
knife_ec2_create.config[:run_list] = ['role[base]']
|
641
|
+
knife_ec2_create.config[:first_boot_attributes] = "{'my_attributes':{'foo':'bar'}"
|
642
|
+
knife_ec2_create.config[:first_boot_attributes_from_file] = "{'my_attributes':{'foo':'bar'}"
|
645
643
|
|
646
644
|
|
647
|
-
@bootstrap =
|
645
|
+
@bootstrap = knife_ec2_create.bootstrap_for_linux_node(new_ec2_server, new_ec2_server.dns_name)
|
648
646
|
end
|
649
647
|
|
650
648
|
include_examples "generic bootstrap configurations" do
|
651
|
-
subject {
|
652
|
-
let(:bootstrap) {
|
649
|
+
subject { knife_ec2_create }
|
650
|
+
let(:bootstrap) { knife_ec2_create.bootstrap_for_linux_node(new_ec2_server, new_ec2_server.dns_name) }
|
653
651
|
end
|
654
652
|
|
655
653
|
it "should set the bootstrap 'name argument' to the hostname of the EC2 server" do
|
@@ -689,18 +687,18 @@ describe Chef::Knife::Ec2ServerCreate do
|
|
689
687
|
end
|
690
688
|
|
691
689
|
it "configures the bootstrap to use the EC2 server id if no explicit node name is set" do
|
692
|
-
|
690
|
+
knife_ec2_create.config[:chef_node_name] = nil
|
693
691
|
|
694
|
-
bootstrap =
|
695
|
-
expect(bootstrap.config[:chef_node_name]).to eq(
|
692
|
+
bootstrap = knife_ec2_create.bootstrap_for_linux_node(new_ec2_server, new_ec2_server.dns_name)
|
693
|
+
expect(bootstrap.config[:chef_node_name]).to eq(new_ec2_server.id)
|
696
694
|
end
|
697
695
|
|
698
696
|
it "configures the bootstrap to use prerelease versions of chef if specified" do
|
699
697
|
expect(@bootstrap.config[:prerelease]).to be_falsey
|
700
698
|
|
701
|
-
|
699
|
+
knife_ec2_create.config[:prerelease] = true
|
702
700
|
|
703
|
-
bootstrap =
|
701
|
+
bootstrap = knife_ec2_create.bootstrap_for_linux_node(new_ec2_server, new_ec2_server.dns_name)
|
704
702
|
expect(bootstrap.config[:prerelease]).to eq(true)
|
705
703
|
end
|
706
704
|
|
@@ -723,15 +721,15 @@ describe Chef::Knife::Ec2ServerCreate do
|
|
723
721
|
|
724
722
|
describe "when configuring the ssh bootstrap process for windows" do
|
725
723
|
before do
|
726
|
-
allow(
|
727
|
-
|
728
|
-
|
729
|
-
|
730
|
-
|
731
|
-
|
732
|
-
|
733
|
-
allow(
|
734
|
-
@bootstrap =
|
724
|
+
allow(knife_ec2_create).to receive(:fetch_server_fqdn).and_return("SERVERNAME")
|
725
|
+
knife_ec2_create.config[:ssh_user] = "administrator"
|
726
|
+
knife_ec2_create.config[:ssh_password] = "password"
|
727
|
+
knife_ec2_create.config[:ssh_port] = 22
|
728
|
+
knife_ec2_create.config[:forward_agent] = true
|
729
|
+
knife_ec2_create.config[:bootstrap_protocol] = 'ssh'
|
730
|
+
knife_ec2_create.config[:image] = '12345'
|
731
|
+
allow(knife_ec2_create).to receive(:is_image_windows?).and_return(true)
|
732
|
+
@bootstrap = knife_ec2_create.bootstrap_for_windows_node(new_ec2_server, new_ec2_server.dns_name)
|
735
733
|
end
|
736
734
|
|
737
735
|
it "sets the bootstrap 'forward_agent' correctly" do
|
@@ -741,52 +739,52 @@ describe Chef::Knife::Ec2ServerCreate do
|
|
741
739
|
|
742
740
|
describe "when configuring the winrm bootstrap process for windows" do
|
743
741
|
before do
|
744
|
-
allow(
|
745
|
-
|
746
|
-
|
747
|
-
|
748
|
-
|
749
|
-
|
750
|
-
|
751
|
-
|
752
|
-
|
753
|
-
|
754
|
-
|
755
|
-
|
756
|
-
|
757
|
-
|
758
|
-
|
759
|
-
|
760
|
-
|
761
|
-
@bootstrap =
|
742
|
+
allow(knife_ec2_create).to receive(:fetch_server_fqdn).and_return("SERVERNAME")
|
743
|
+
knife_ec2_create.config[:winrm_user] = "Administrator"
|
744
|
+
knife_ec2_create.config[:winrm_password] = "password"
|
745
|
+
knife_ec2_create.config[:winrm_port] = 12345
|
746
|
+
knife_ec2_create.config[:winrm_transport] = 'ssl'
|
747
|
+
knife_ec2_create.config[:kerberos_realm] = "realm"
|
748
|
+
knife_ec2_create.config[:bootstrap_protocol] = 'winrm'
|
749
|
+
knife_ec2_create.config[:kerberos_service] = "service"
|
750
|
+
knife_ec2_create.config[:chef_node_name] = "blarf"
|
751
|
+
knife_ec2_create.config[:template_file] = '~/.chef/templates/my-bootstrap.sh.erb'
|
752
|
+
knife_ec2_create.config[:distro] = 'ubuntu-10.04-magic-sparkles'
|
753
|
+
knife_ec2_create.config[:run_list] = ['role[base]']
|
754
|
+
knife_ec2_create.config[:first_boot_attributes] = "{'my_attributes':{'foo':'bar'}"
|
755
|
+
knife_ec2_create.config[:winrm_ssl_verify_mode] = 'verify_peer'
|
756
|
+
knife_ec2_create.config[:msi_url] = 'https://opscode-omnibus-packages.s3.amazonaws.com/windows/2008r2/x86_64/chef-client-12.3.0-1.msi'
|
757
|
+
knife_ec2_create.config[:install_as_service] = true
|
758
|
+
knife_ec2_create.config[:session_timeout] = "90"
|
759
|
+
@bootstrap = knife_ec2_create.bootstrap_for_windows_node(new_ec2_server, new_ec2_server.dns_name)
|
762
760
|
end
|
763
761
|
|
764
762
|
include_examples "generic bootstrap configurations" do
|
765
|
-
subject {
|
766
|
-
let(:bootstrap) {
|
763
|
+
subject { knife_ec2_create }
|
764
|
+
let(:bootstrap) { knife_ec2_create.bootstrap_for_linux_node(new_ec2_server, new_ec2_server.dns_name) }
|
767
765
|
end
|
768
766
|
|
769
767
|
it "should set the winrm username correctly" do
|
770
|
-
expect(@bootstrap.config[:winrm_user]).to eq(
|
768
|
+
expect(@bootstrap.config[:winrm_user]).to eq(knife_ec2_create.config[:winrm_user])
|
771
769
|
end
|
772
770
|
it "should set the winrm password correctly" do
|
773
|
-
expect(@bootstrap.config[:winrm_password]).to eq(
|
771
|
+
expect(@bootstrap.config[:winrm_password]).to eq(knife_ec2_create.config[:winrm_password])
|
774
772
|
end
|
775
773
|
|
776
774
|
it "should set the winrm port correctly" do
|
777
|
-
expect(@bootstrap.config[:winrm_port]).to eq(
|
775
|
+
expect(@bootstrap.config[:winrm_port]).to eq(knife_ec2_create.config[:winrm_port])
|
778
776
|
end
|
779
777
|
|
780
778
|
it "should set the winrm transport layer correctly" do
|
781
|
-
expect(@bootstrap.config[:winrm_transport]).to eq(
|
779
|
+
expect(@bootstrap.config[:winrm_transport]).to eq(knife_ec2_create.config[:winrm_transport])
|
782
780
|
end
|
783
781
|
|
784
782
|
it "should set the kerberos realm correctly" do
|
785
|
-
expect(@bootstrap.config[:kerberos_realm]).to eq(
|
783
|
+
expect(@bootstrap.config[:kerberos_realm]).to eq(knife_ec2_create.config[:kerberos_realm])
|
786
784
|
end
|
787
785
|
|
788
786
|
it "should set the kerberos service correctly" do
|
789
|
-
expect(@bootstrap.config[:kerberos_service]).to eq(
|
787
|
+
expect(@bootstrap.config[:kerberos_service]).to eq(knife_ec2_create.config[:kerberos_service])
|
790
788
|
end
|
791
789
|
|
792
790
|
it "should set the bootstrap 'name argument' to the Windows/AD hostname of the EC2 server" do
|
@@ -794,8 +792,8 @@ describe Chef::Knife::Ec2ServerCreate do
|
|
794
792
|
end
|
795
793
|
|
796
794
|
it "should set the bootstrap 'name argument' to the hostname of the EC2 server when AD/Kerberos is not used" do
|
797
|
-
|
798
|
-
@bootstrap =
|
795
|
+
knife_ec2_create.config[:kerberos_realm] = nil
|
796
|
+
@bootstrap = knife_ec2_create.bootstrap_for_windows_node(new_ec2_server, new_ec2_server.dns_name)
|
799
797
|
expect(@bootstrap.name_args).to eq(['ec2-75.101.253.10.compute-1.amazonaws.com'])
|
800
798
|
end
|
801
799
|
|
@@ -812,11 +810,11 @@ describe Chef::Knife::Ec2ServerCreate do
|
|
812
810
|
end
|
813
811
|
|
814
812
|
it "should set the bootstrap 'install_as_service' correctly" do
|
815
|
-
expect(@bootstrap.config[:install_as_service]).to eq(
|
813
|
+
expect(@bootstrap.config[:install_as_service]).to eq(knife_ec2_create.config[:install_as_service])
|
816
814
|
end
|
817
815
|
|
818
816
|
it "should set the bootstrap 'session_timeout' correctly" do
|
819
|
-
expect(@bootstrap.config[:session_timeout]).to eq(
|
817
|
+
expect(@bootstrap.config[:session_timeout]).to eq(knife_ec2_create.config[:session_timeout])
|
820
818
|
end
|
821
819
|
|
822
820
|
it "configures sets the bootstrap's run_list" do
|
@@ -824,21 +822,21 @@ describe Chef::Knife::Ec2ServerCreate do
|
|
824
822
|
end
|
825
823
|
|
826
824
|
it "configures auth_timeout for bootstrap to default to 25 minutes" do
|
827
|
-
expect(
|
825
|
+
expect(knife_ec2_create.options[:auth_timeout][:default]).to eq(25)
|
828
826
|
end
|
829
827
|
|
830
828
|
it "configures auth_timeout for bootstrap according to plugin auth_timeout config" do
|
831
|
-
|
832
|
-
bootstrap =
|
829
|
+
knife_ec2_create.config[:auth_timeout] = 5
|
830
|
+
bootstrap = knife_ec2_create.bootstrap_for_windows_node(new_ec2_server, new_ec2_server.dns_name)
|
833
831
|
expect(bootstrap.config[:auth_timeout]).to eq(5)
|
834
832
|
end
|
835
833
|
end
|
836
834
|
|
837
835
|
describe "when validating the command-line parameters" do
|
838
836
|
before do
|
839
|
-
allow(Fog::Compute::AWS).to receive(:new).and_return(
|
840
|
-
allow(
|
841
|
-
allow(
|
837
|
+
allow(Fog::Compute::AWS).to receive(:new).and_return(ec2_connection)
|
838
|
+
allow(knife_ec2_create.ui).to receive(:error)
|
839
|
+
allow(knife_ec2_create.ui).to receive(:msg)
|
842
840
|
end
|
843
841
|
|
844
842
|
describe "when reading aws_credential_file" do
|
@@ -854,7 +852,7 @@ describe Chef::Knife::Ec2ServerCreate do
|
|
854
852
|
it "reads UNIX Line endings" do
|
855
853
|
allow(File).to receive(:read).
|
856
854
|
and_return("AWSAccessKeyId=#{@access_key_id}\nAWSSecretKey=#{@secret_key}")
|
857
|
-
|
855
|
+
knife_ec2_create.validate!
|
858
856
|
expect(Chef::Config[:knife][:aws_access_key_id]).to eq(@access_key_id)
|
859
857
|
expect(Chef::Config[:knife][:aws_secret_access_key]).to eq(@secret_key)
|
860
858
|
end
|
@@ -862,14 +860,14 @@ describe Chef::Knife::Ec2ServerCreate do
|
|
862
860
|
it "reads DOS Line endings" do
|
863
861
|
allow(File).to receive(:read).
|
864
862
|
and_return("AWSAccessKeyId=#{@access_key_id}\r\nAWSSecretKey=#{@secret_key}")
|
865
|
-
|
863
|
+
knife_ec2_create.validate!
|
866
864
|
expect(Chef::Config[:knife][:aws_access_key_id]).to eq(@access_key_id)
|
867
865
|
expect(Chef::Config[:knife][:aws_secret_access_key]).to eq(@secret_key)
|
868
866
|
end
|
869
867
|
it "reads UNIX Line endings for new format" do
|
870
868
|
allow(File).to receive(:read).
|
871
869
|
and_return("[default]\naws_access_key_id=#{@access_key_id}\naws_secret_access_key=#{@secret_key}")
|
872
|
-
|
870
|
+
knife_ec2_create.validate!
|
873
871
|
expect(Chef::Config[:knife][:aws_access_key_id]).to eq(@access_key_id)
|
874
872
|
expect(Chef::Config[:knife][:aws_secret_access_key]).to eq(@secret_key)
|
875
873
|
end
|
@@ -877,7 +875,7 @@ describe Chef::Knife::Ec2ServerCreate do
|
|
877
875
|
it "reads DOS Line endings for new format" do
|
878
876
|
allow(File).to receive(:read).
|
879
877
|
and_return("[default]\naws_access_key_id=#{@access_key_id}\r\naws_secret_access_key=#{@secret_key}")
|
880
|
-
|
878
|
+
knife_ec2_create.validate!
|
881
879
|
expect(Chef::Config[:knife][:aws_access_key_id]).to eq(@access_key_id)
|
882
880
|
expect(Chef::Config[:knife][:aws_secret_access_key]).to eq(@secret_key)
|
883
881
|
end
|
@@ -886,7 +884,7 @@ describe Chef::Knife::Ec2ServerCreate do
|
|
886
884
|
Chef::Config[:knife][:aws_profile] = 'other'
|
887
885
|
allow(File).to receive(:read).
|
888
886
|
and_return("[default]\naws_access_key_id=TESTKEY\r\naws_secret_access_key=TESTSECRET\n\n[other]\naws_access_key_id=#{@access_key_id}\r\naws_secret_access_key=#{@secret_key}")
|
889
|
-
|
887
|
+
knife_ec2_create.validate!
|
890
888
|
expect(Chef::Config[:knife][:aws_access_key_id]).to eq(@access_key_id)
|
891
889
|
expect(Chef::Config[:knife][:aws_secret_access_key]).to eq(@secret_key)
|
892
890
|
end
|
@@ -895,7 +893,7 @@ describe Chef::Knife::Ec2ServerCreate do
|
|
895
893
|
it "raises exception" do
|
896
894
|
Chef::Config[:knife][:aws_profile] = 'xyz'
|
897
895
|
allow(File).to receive(:read).and_return("[default]\naws_access_key_id=TESTKEY\r\naws_secret_access_key=TESTSECRET")
|
898
|
-
expect{
|
896
|
+
expect{ knife_ec2_create.validate! }.to raise_error("The provided --aws-profile 'xyz' is invalid.")
|
899
897
|
end
|
900
898
|
end
|
901
899
|
end
|
@@ -910,27 +908,27 @@ describe Chef::Knife::Ec2ServerCreate do
|
|
910
908
|
it "reads UNIX Line endings" do
|
911
909
|
allow(File).to receive(:read).
|
912
910
|
and_return("[default]\r\nregion=#{@region}")
|
913
|
-
|
911
|
+
knife_ec2_create.validate!
|
914
912
|
expect(Chef::Config[:knife][:region]).to eq(@region)
|
915
913
|
end
|
916
914
|
|
917
915
|
it "reads DOS Line endings" do
|
918
916
|
allow(File).to receive(:read).
|
919
917
|
and_return("[default]\r\nregion=#{@region}")
|
920
|
-
|
918
|
+
knife_ec2_create.validate!
|
921
919
|
expect(Chef::Config[:knife][:region]).to eq(@region)
|
922
920
|
end
|
923
921
|
it "reads UNIX Line endings for new format" do
|
924
922
|
allow(File).to receive(:read).
|
925
923
|
and_return("[default]\nregion=#{@region}")
|
926
|
-
|
924
|
+
knife_ec2_create.validate!
|
927
925
|
expect(Chef::Config[:knife][:region]).to eq(@region)
|
928
926
|
end
|
929
927
|
|
930
928
|
it "reads DOS Line endings for new format" do
|
931
929
|
allow(File).to receive(:read).
|
932
930
|
and_return("[default]\nregion=#{@region}")
|
933
|
-
|
931
|
+
knife_ec2_create.validate!
|
934
932
|
expect(Chef::Config[:knife][:region]).to eq(@region)
|
935
933
|
end
|
936
934
|
|
@@ -938,7 +936,7 @@ describe Chef::Knife::Ec2ServerCreate do
|
|
938
936
|
Chef::Config[:knife][:aws_profile] = 'other'
|
939
937
|
allow(File).to receive(:read).
|
940
938
|
and_return("[default]\nregion=TESTREGION\n\n[profile other]\nregion=#{@region}")
|
941
|
-
|
939
|
+
knife_ec2_create.validate!
|
942
940
|
expect(Chef::Config[:knife][:region]).to eq(@region)
|
943
941
|
end
|
944
942
|
|
@@ -946,7 +944,7 @@ describe Chef::Knife::Ec2ServerCreate do
|
|
946
944
|
it "raises exception" do
|
947
945
|
Chef::Config[:knife][:aws_profile] = 'xyz'
|
948
946
|
allow(File).to receive(:read).and_return("[default]\nregion=TESTREGION")
|
949
|
-
expect{
|
947
|
+
expect{ knife_ec2_create.validate! }.to raise_error("The provided --aws-profile 'profile xyz' is invalid.")
|
950
948
|
end
|
951
949
|
end
|
952
950
|
|
@@ -954,7 +952,7 @@ describe Chef::Knife::Ec2ServerCreate do
|
|
954
952
|
it 'loads the default profile successfully' do
|
955
953
|
Chef::Config[:knife][:aws_profile] = 'default'
|
956
954
|
allow(File).to receive(:read).and_return("[default]\nregion=#{@region}\n\n[profile other]\nregion=TESTREGION")
|
957
|
-
|
955
|
+
knife_ec2_create.validate!
|
958
956
|
expect(Chef::Config[:knife][:region]).to eq(@region)
|
959
957
|
end
|
960
958
|
end
|
@@ -962,157 +960,157 @@ describe Chef::Knife::Ec2ServerCreate do
|
|
962
960
|
|
963
961
|
it 'understands that file:// validation key URIs are just paths' do
|
964
962
|
Chef::Config[:knife][:validation_key_url] = 'file:///foo/bar'
|
965
|
-
expect(
|
963
|
+
expect(knife_ec2_create.validation_key_path).to eq('/foo/bar')
|
966
964
|
end
|
967
965
|
|
968
966
|
it 'returns a path to a tmp file when presented with a URI for the ' \
|
969
967
|
'validation key' do
|
970
968
|
Chef::Config[:knife][:validation_key_url] = @validation_key_url
|
971
969
|
|
972
|
-
allow(
|
970
|
+
allow(knife_ec2_create).to receive_message_chain(:validation_key_tmpfile, :path).and_return(@validation_key_file)
|
973
971
|
|
974
|
-
expect(
|
972
|
+
expect(knife_ec2_create.validation_key_path).to eq(@validation_key_file)
|
975
973
|
end
|
976
974
|
|
977
975
|
it "disallows security group names when using a VPC" do
|
978
|
-
|
979
|
-
|
980
|
-
|
976
|
+
knife_ec2_create.config[:subnet_id] = @subnet_1_id
|
977
|
+
knife_ec2_create.config[:security_group_ids] = 'sg-aabbccdd'
|
978
|
+
knife_ec2_create.config[:security_groups] = 'groupname'
|
981
979
|
|
982
|
-
allow(
|
980
|
+
allow(ec2_connection).to receive_message_chain(:subnets, :get).with(@subnet_1_id).and_return(@subnet_1)
|
983
981
|
|
984
|
-
expect {
|
982
|
+
expect { knife_ec2_create.validate! }.to raise_error(SystemExit)
|
985
983
|
end
|
986
984
|
|
987
985
|
it 'disallows invalid network interface ids' do
|
988
|
-
|
986
|
+
knife_ec2_create.config[:network_interfaces] = ['INVALID_ID']
|
989
987
|
|
990
|
-
expect {
|
988
|
+
expect { knife_ec2_create.validate! }.to raise_error(SystemExit)
|
991
989
|
end
|
992
990
|
|
993
991
|
it 'disallows network interfaces not in the right VPC' do
|
994
|
-
|
995
|
-
|
996
|
-
|
992
|
+
knife_ec2_create.config[:subnet_id] = @subnet_1_id
|
993
|
+
knife_ec2_create.config[:security_group_ids] = 'sg-aabbccdd'
|
994
|
+
knife_ec2_create.config[:security_groups] = 'groupname'
|
997
995
|
|
998
|
-
allow(
|
996
|
+
allow(ec2_connection).to receive_message_chain(:subnets, :get).with(@subnet_1_id).and_return(@subnet_1)
|
999
997
|
|
1000
|
-
allow(
|
998
|
+
allow(ec2_connection).to receive_message_chain(:network_interfaces, :all).and_return [
|
1001
999
|
double('network_interfaces', network_interface_id: 'eni-12345678', vpc_id: 'another_vpc'),
|
1002
|
-
double('network_interfaces', network_interface_id: 'eni-87654321', vpc_id:
|
1000
|
+
double('network_interfaces', network_interface_id: 'eni-87654321', vpc_id: my_vpc)
|
1003
1001
|
]
|
1004
1002
|
|
1005
|
-
expect {
|
1003
|
+
expect { knife_ec2_create.validate! }.to raise_error SystemExit
|
1006
1004
|
end
|
1007
1005
|
|
1008
1006
|
it "disallows private ips when not using a VPC" do
|
1009
|
-
|
1007
|
+
knife_ec2_create.config[:private_ip_address] = '10.0.0.10'
|
1010
1008
|
|
1011
|
-
expect {
|
1009
|
+
expect { knife_ec2_create.validate! }.to raise_error SystemExit
|
1012
1010
|
end
|
1013
1011
|
|
1014
1012
|
it "disallows specifying credentials file and aws keys" do
|
1015
1013
|
Chef::Config[:knife][:aws_credential_file] = '/apple/pear'
|
1016
1014
|
allow(File).to receive(:read).and_return("AWSAccessKeyId=b\nAWSSecretKey=a")
|
1017
1015
|
|
1018
|
-
expect {
|
1016
|
+
expect { knife_ec2_create.validate! }.to raise_error SystemExit
|
1019
1017
|
end
|
1020
1018
|
|
1021
1019
|
it "disallows associate public ip option when not using a VPC" do
|
1022
|
-
|
1023
|
-
|
1020
|
+
knife_ec2_create.config[:associate_public_ip] = true
|
1021
|
+
knife_ec2_create.config[:subnet_id] = nil
|
1024
1022
|
|
1025
|
-
expect {
|
1023
|
+
expect { knife_ec2_create.validate! }.to raise_error SystemExit
|
1026
1024
|
end
|
1027
1025
|
|
1028
1026
|
it "disallows setting only one of the two ClassicLink options" do
|
1029
|
-
|
1030
|
-
|
1027
|
+
knife_ec2_create.config[:classic_link_vpc_id] = @vpc_id
|
1028
|
+
knife_ec2_create.config[:classic_link_vpc_security_group_ids] = nil
|
1031
1029
|
|
1032
|
-
expect {
|
1030
|
+
expect { knife_ec2_create.validate! }.to raise_error SystemExit
|
1033
1031
|
end
|
1034
1032
|
|
1035
1033
|
it "disallows ClassicLink with VPC" do
|
1036
|
-
|
1037
|
-
|
1038
|
-
|
1034
|
+
knife_ec2_create.config[:subnet_id] = 'subnet-1a2b3c4d'
|
1035
|
+
knife_ec2_create.config[:classic_link_vpc_id] = @vpc_id
|
1036
|
+
knife_ec2_create.config[:classic_link_vpc_security_group_ids] = @vpc_security_group_ids
|
1039
1037
|
|
1040
|
-
allow(
|
1038
|
+
allow(knife_ec2_create).to receive(:validate_nics!).and_return(true)
|
1041
1039
|
|
1042
|
-
expect {
|
1040
|
+
expect { knife_ec2_create.validate! }.to raise_error SystemExit
|
1043
1041
|
end
|
1044
1042
|
|
1045
1043
|
it "disallows ebs provisioned iops option when not using ebs volume type" do
|
1046
|
-
|
1047
|
-
|
1044
|
+
knife_ec2_create.config[:ebs_provisioned_iops] = "123"
|
1045
|
+
knife_ec2_create.config[:ebs_volume_type] = nil
|
1048
1046
|
|
1049
|
-
expect {
|
1047
|
+
expect { knife_ec2_create.validate! }.to raise_error SystemExit
|
1050
1048
|
end
|
1051
1049
|
|
1052
1050
|
it "disallows ebs provisioned iops option when not using ebs volume type 'io1'" do
|
1053
|
-
|
1054
|
-
|
1051
|
+
knife_ec2_create.config[:ebs_provisioned_iops] = "123"
|
1052
|
+
knife_ec2_create.config[:ebs_volume_type] = "standard"
|
1055
1053
|
|
1056
|
-
expect {
|
1054
|
+
expect { knife_ec2_create.validate! }.to raise_error SystemExit
|
1057
1055
|
end
|
1058
1056
|
|
1059
1057
|
it "disallows ebs volume type if its other than 'io1' or 'gp2' or 'standard'" do
|
1060
|
-
|
1061
|
-
|
1058
|
+
knife_ec2_create.config[:ebs_provisioned_iops] = "123"
|
1059
|
+
knife_ec2_create.config[:ebs_volume_type] = 'invalid'
|
1062
1060
|
|
1063
|
-
expect {
|
1061
|
+
expect { knife_ec2_create.validate! }.to raise_error SystemExit
|
1064
1062
|
end
|
1065
1063
|
|
1066
1064
|
it "disallows 'io1' ebs volume type when not using ebs provisioned iops" do
|
1067
|
-
|
1068
|
-
|
1065
|
+
knife_ec2_create.config[:ebs_provisioned_iops] = nil
|
1066
|
+
knife_ec2_create.config[:ebs_volume_type] = 'io1'
|
1069
1067
|
|
1070
|
-
expect {
|
1068
|
+
expect { knife_ec2_create.validate! }.to raise_error SystemExit
|
1071
1069
|
end
|
1072
1070
|
|
1073
1071
|
context "when ebs_encrypted option specified" do
|
1074
1072
|
it "not raise any validation error if valid ebs_size specified" do
|
1075
|
-
|
1076
|
-
|
1077
|
-
|
1078
|
-
expect(
|
1079
|
-
|
1073
|
+
knife_ec2_create.config[:ebs_size] = "8"
|
1074
|
+
knife_ec2_create.config[:flavor] = "m3.medium"
|
1075
|
+
knife_ec2_create.config[:ebs_encrypted] = true
|
1076
|
+
expect(knife_ec2_create.ui).to_not receive(:error).with(" --ebs-encrypted option requires valid --ebs-size to be specified.")
|
1077
|
+
knife_ec2_create.validate!
|
1080
1078
|
end
|
1081
1079
|
|
1082
1080
|
it "raise error on missing ebs_size" do
|
1083
|
-
|
1084
|
-
|
1085
|
-
|
1086
|
-
expect(
|
1087
|
-
expect {
|
1081
|
+
knife_ec2_create.config[:ebs_size] = nil
|
1082
|
+
knife_ec2_create.config[:flavor] = "m3.medium"
|
1083
|
+
knife_ec2_create.config[:ebs_encrypted] = true
|
1084
|
+
expect(knife_ec2_create.ui).to receive(:error).with(" --ebs-encrypted option requires valid --ebs-size to be specified.")
|
1085
|
+
expect { knife_ec2_create.validate! }.to raise_error SystemExit
|
1088
1086
|
end
|
1089
1087
|
|
1090
1088
|
it "raise error if invalid ebs_size specified for 'standard' VolumeType" do
|
1091
|
-
|
1092
|
-
|
1093
|
-
|
1094
|
-
|
1095
|
-
expect(
|
1096
|
-
expect {
|
1089
|
+
knife_ec2_create.config[:ebs_size] = "1055"
|
1090
|
+
knife_ec2_create.config[:ebs_volume_type] = 'standard'
|
1091
|
+
knife_ec2_create.config[:flavor] = "m3.medium"
|
1092
|
+
knife_ec2_create.config[:ebs_encrypted] = true
|
1093
|
+
expect(knife_ec2_create.ui).to receive(:error).with(" --ebs-size should be in between 1-1024 for 'standard' ebs volume type.")
|
1094
|
+
expect { knife_ec2_create.validate! }.to raise_error SystemExit
|
1097
1095
|
end
|
1098
1096
|
|
1099
1097
|
it "raise error on invalid ebs_size specified for 'gp2' VolumeType" do
|
1100
|
-
|
1101
|
-
|
1102
|
-
|
1103
|
-
|
1104
|
-
expect(
|
1105
|
-
expect {
|
1098
|
+
knife_ec2_create.config[:ebs_size] = "16500"
|
1099
|
+
knife_ec2_create.config[:ebs_volume_type] = 'gp2'
|
1100
|
+
knife_ec2_create.config[:flavor] = "m3.medium"
|
1101
|
+
knife_ec2_create.config[:ebs_encrypted] = true
|
1102
|
+
expect(knife_ec2_create.ui).to receive(:error).with(" --ebs-size should be in between 1-16384 for 'gp2' ebs volume type.")
|
1103
|
+
expect { knife_ec2_create.validate! }.to raise_error SystemExit
|
1106
1104
|
end
|
1107
1105
|
|
1108
1106
|
it "raise error on invalid ebs_size specified for 'io1' VolumeType" do
|
1109
|
-
|
1110
|
-
|
1111
|
-
|
1112
|
-
|
1113
|
-
|
1114
|
-
expect(
|
1115
|
-
expect {
|
1107
|
+
knife_ec2_create.config[:ebs_size] = "3"
|
1108
|
+
knife_ec2_create.config[:ebs_provisioned_iops] = "200"
|
1109
|
+
knife_ec2_create.config[:ebs_volume_type] = 'io1'
|
1110
|
+
knife_ec2_create.config[:flavor] = "m3.medium"
|
1111
|
+
knife_ec2_create.config[:ebs_encrypted] = true
|
1112
|
+
expect(knife_ec2_create.ui).to receive(:error).with(" --ebs-size should be in between 4-16384 for 'io1' ebs volume type.")
|
1113
|
+
expect { knife_ec2_create.validate! }.to raise_error SystemExit
|
1116
1114
|
end
|
1117
1115
|
end
|
1118
1116
|
end
|
@@ -1125,74 +1123,74 @@ describe Chef::Knife::Ec2ServerCreate do
|
|
1125
1123
|
end
|
1126
1124
|
|
1127
1125
|
it "creates a connection without access keys" do
|
1128
|
-
|
1129
|
-
expect(Fog::Compute::AWS).to receive(:new).with(hash_including(:use_iam_profile => true)).and_return(
|
1130
|
-
|
1126
|
+
knife_ec2_create.config[:use_iam_profile] = true
|
1127
|
+
expect(Fog::Compute::AWS).to receive(:new).with(hash_including(:use_iam_profile => true)).and_return(ec2_connection)
|
1128
|
+
knife_ec2_create.connection
|
1131
1129
|
end
|
1132
1130
|
end
|
1133
1131
|
|
1134
1132
|
describe "when aws_session_token is present" do
|
1135
1133
|
it "creates a connection using the session token" do
|
1136
|
-
|
1137
|
-
expect(Fog::Compute::AWS).to receive(:new).with(hash_including(:aws_session_token => 'session-token')).and_return(
|
1138
|
-
|
1134
|
+
knife_ec2_create.config[:aws_session_token] = 'session-token'
|
1135
|
+
expect(Fog::Compute::AWS).to receive(:new).with(hash_including(:aws_session_token => 'session-token')).and_return(ec2_connection)
|
1136
|
+
knife_ec2_create.connection
|
1139
1137
|
end
|
1140
1138
|
end
|
1141
1139
|
end
|
1142
1140
|
|
1143
1141
|
describe "when creating the server definition" do
|
1144
1142
|
before do
|
1145
|
-
allow(Fog::Compute::AWS).to receive(:new).and_return(
|
1143
|
+
allow(Fog::Compute::AWS).to receive(:new).and_return(ec2_connection)
|
1146
1144
|
end
|
1147
1145
|
|
1148
1146
|
it "sets the specified placement_group" do
|
1149
|
-
|
1150
|
-
server_def =
|
1147
|
+
knife_ec2_create.config[:placement_group] = ['some_placement_group']
|
1148
|
+
server_def = knife_ec2_create.create_server_def
|
1151
1149
|
|
1152
1150
|
expect(server_def[:placement_group]).to eq(['some_placement_group'])
|
1153
1151
|
end
|
1154
1152
|
|
1155
1153
|
it "sets the specified security group names" do
|
1156
|
-
|
1157
|
-
server_def =
|
1154
|
+
knife_ec2_create.config[:security_groups] = ['groupname']
|
1155
|
+
server_def = knife_ec2_create.create_server_def
|
1158
1156
|
|
1159
1157
|
expect(server_def[:groups]).to eq(['groupname'])
|
1160
1158
|
end
|
1161
1159
|
|
1162
1160
|
it "sets the specified security group ids" do
|
1163
|
-
|
1164
|
-
server_def =
|
1161
|
+
knife_ec2_create.config[:security_group_ids] = ['sg-aabbccdd', 'sg-3764sdss', 'sg-aab343ytre']
|
1162
|
+
server_def = knife_ec2_create.create_server_def
|
1165
1163
|
|
1166
|
-
expect(server_def[:security_group_ids]).to eq(['sg-aabbccdd'])
|
1164
|
+
expect(server_def[:security_group_ids]).to eq(['sg-aabbccdd', 'sg-3764sdss', 'sg-aab343ytre'])
|
1167
1165
|
end
|
1168
1166
|
|
1169
1167
|
it "sets the image id from CLI arguments over knife config" do
|
1170
|
-
|
1168
|
+
knife_ec2_create.config[:image] = "ami-aaa"
|
1171
1169
|
Chef::Config[:knife][:image] = "ami-zzz"
|
1172
|
-
server_def =
|
1170
|
+
server_def = knife_ec2_create.create_server_def
|
1173
1171
|
|
1174
1172
|
expect(server_def[:image_id]).to eq("ami-aaa")
|
1175
1173
|
end
|
1176
1174
|
|
1177
1175
|
it "sets the flavor id from CLI arguments over knife config" do
|
1178
|
-
|
1176
|
+
knife_ec2_create.config[:flavor] = "massive"
|
1179
1177
|
Chef::Config[:knife][:flavor] = "bitty"
|
1180
|
-
server_def =
|
1178
|
+
server_def = knife_ec2_create.create_server_def
|
1181
1179
|
|
1182
1180
|
expect(server_def[:flavor_id]).to eq("massive")
|
1183
1181
|
end
|
1184
1182
|
|
1185
1183
|
it "sets the availability zone from CLI arguments over knife config" do
|
1186
|
-
|
1184
|
+
knife_ec2_create.config[:availability_zone] = "dis-one"
|
1187
1185
|
Chef::Config[:knife][:availability_zone] = "dat-one"
|
1188
|
-
server_def =
|
1186
|
+
server_def = knife_ec2_create.create_server_def
|
1189
1187
|
|
1190
1188
|
expect(server_def[:availability_zone]).to eq("dis-one")
|
1191
1189
|
end
|
1192
1190
|
|
1193
1191
|
it "adds the specified ephemeral device mappings" do
|
1194
|
-
|
1195
|
-
server_def =
|
1192
|
+
knife_ec2_create.config[:ephemeral] = [ "/dev/sdb", "/dev/sdc", "/dev/sdd", "/dev/sde" ]
|
1193
|
+
server_def = knife_ec2_create.create_server_def
|
1196
1194
|
|
1197
1195
|
expect(server_def[:block_device_mapping]).to eq([{ "VirtualName" => "ephemeral0", "DeviceName" => "/dev/sdb" },
|
1198
1196
|
{ "VirtualName" => "ephemeral1", "DeviceName" => "/dev/sdc" },
|
@@ -1201,128 +1199,128 @@ describe Chef::Knife::Ec2ServerCreate do
|
|
1201
1199
|
end
|
1202
1200
|
|
1203
1201
|
it "sets the specified private ip address" do
|
1204
|
-
|
1205
|
-
|
1206
|
-
server_def =
|
1202
|
+
knife_ec2_create.config[:subnet_id] = 'subnet-1a2b3c4d'
|
1203
|
+
knife_ec2_create.config[:private_ip_address] = '10.0.0.10'
|
1204
|
+
server_def = knife_ec2_create.create_server_def
|
1207
1205
|
|
1208
1206
|
expect(server_def[:subnet_id]).to eq('subnet-1a2b3c4d')
|
1209
1207
|
expect(server_def[:private_ip_address]).to eq('10.0.0.10')
|
1210
1208
|
end
|
1211
1209
|
|
1212
1210
|
it "sets the IAM server role when one is specified" do
|
1213
|
-
|
1214
|
-
server_def =
|
1211
|
+
knife_ec2_create.config[:iam_instance_profile] = ['iam-role']
|
1212
|
+
server_def = knife_ec2_create.create_server_def
|
1215
1213
|
|
1216
1214
|
expect(server_def[:iam_instance_profile_name]).to eq(['iam-role'])
|
1217
1215
|
end
|
1218
1216
|
|
1219
1217
|
it "doesn't set an IAM server role by default" do
|
1220
|
-
server_def =
|
1218
|
+
server_def = knife_ec2_create.create_server_def
|
1221
1219
|
|
1222
1220
|
expect(server_def[:iam_instance_profile_name]).to eq(nil)
|
1223
1221
|
end
|
1224
1222
|
|
1225
1223
|
it "doesn't use IAM profile by default" do
|
1226
|
-
server_def =
|
1224
|
+
server_def = knife_ec2_create.create_server_def
|
1227
1225
|
|
1228
1226
|
expect(server_def[:use_iam_profile]).to eq(nil)
|
1229
1227
|
end
|
1230
1228
|
|
1231
1229
|
it 'Set Tenancy Dedicated when both VPC mode and Flag is True' do
|
1232
|
-
|
1233
|
-
allow(
|
1234
|
-
server_def =
|
1230
|
+
knife_ec2_create.config[:dedicated_instance] = true
|
1231
|
+
allow(knife_ec2_create).to receive_messages(:vpc_mode? => true)
|
1232
|
+
server_def = knife_ec2_create.create_server_def
|
1235
1233
|
expect(server_def[:tenancy]).to eq("dedicated")
|
1236
1234
|
end
|
1237
1235
|
|
1238
1236
|
it 'Tenancy should be default with no vpc mode even is specified' do
|
1239
|
-
|
1240
|
-
server_def =
|
1237
|
+
knife_ec2_create.config[:dedicated_instance] = true
|
1238
|
+
server_def = knife_ec2_create.create_server_def
|
1241
1239
|
expect(server_def[:tenancy]).to eq(nil)
|
1242
1240
|
end
|
1243
1241
|
|
1244
1242
|
it 'Tenancy should be default with vpc but not requested' do
|
1245
|
-
allow(
|
1246
|
-
server_def =
|
1243
|
+
allow(knife_ec2_create).to receive_messages(:vpc_mode? => true)
|
1244
|
+
server_def = knife_ec2_create.create_server_def
|
1247
1245
|
expect(server_def[:tenancy]).to eq(nil)
|
1248
1246
|
end
|
1249
1247
|
|
1250
1248
|
it "sets associate_public_ip to true if specified and in vpc_mode" do
|
1251
|
-
|
1252
|
-
|
1253
|
-
server_def =
|
1249
|
+
knife_ec2_create.config[:subnet_id] = 'subnet-1a2b3c4d'
|
1250
|
+
knife_ec2_create.config[:associate_public_ip] = true
|
1251
|
+
server_def = knife_ec2_create.create_server_def
|
1254
1252
|
|
1255
1253
|
expect(server_def[:subnet_id]).to eq('subnet-1a2b3c4d')
|
1256
1254
|
expect(server_def[:associate_public_ip]).to eq(true)
|
1257
1255
|
end
|
1258
1256
|
|
1259
1257
|
it "sets the spot price" do
|
1260
|
-
|
1261
|
-
server_def =
|
1258
|
+
knife_ec2_create.config[:spot_price] = '1.99'
|
1259
|
+
server_def = knife_ec2_create.create_server_def
|
1262
1260
|
|
1263
1261
|
expect(server_def[:price]).to eq('1.99')
|
1264
1262
|
end
|
1265
1263
|
|
1266
1264
|
it "sets the spot instance request type as persistent" do
|
1267
|
-
|
1268
|
-
server_def =
|
1265
|
+
knife_ec2_create.config[:spot_request_type] = 'persistent'
|
1266
|
+
server_def = knife_ec2_create.create_server_def
|
1269
1267
|
|
1270
1268
|
expect(server_def[:request_type]).to eq('persistent')
|
1271
1269
|
end
|
1272
1270
|
|
1273
1271
|
it "sets the spot instance request type as one-time" do
|
1274
|
-
|
1275
|
-
server_def =
|
1272
|
+
knife_ec2_create.config[:spot_request_type] = 'one-time'
|
1273
|
+
server_def = knife_ec2_create.create_server_def
|
1276
1274
|
|
1277
1275
|
expect(server_def[:request_type]).to eq('one-time')
|
1278
1276
|
end
|
1279
1277
|
|
1280
1278
|
context "when using ebs volume type and ebs provisioned iops rate options" do
|
1281
1279
|
before do
|
1282
|
-
allow(
|
1283
|
-
allow(
|
1284
|
-
allow(
|
1285
|
-
allow(
|
1280
|
+
allow(knife_ec2_create).to receive_message_chain(:ami, :root_device_type).and_return("ebs")
|
1281
|
+
allow(knife_ec2_create).to receive_message_chain(:ami, :block_device_mapping).and_return([{"iops" => 123}])
|
1282
|
+
allow(knife_ec2_create).to receive(:msg)
|
1283
|
+
allow(knife_ec2_create).to receive(:puts)
|
1286
1284
|
end
|
1287
1285
|
|
1288
1286
|
it "sets the specified 'standard' ebs volume type" do
|
1289
|
-
|
1290
|
-
server_def =
|
1287
|
+
knife_ec2_create.config[:ebs_volume_type] = 'standard'
|
1288
|
+
server_def = knife_ec2_create.create_server_def
|
1291
1289
|
|
1292
1290
|
expect(server_def[:block_device_mapping].first['Ebs.VolumeType']).to eq('standard')
|
1293
1291
|
end
|
1294
1292
|
|
1295
1293
|
it "sets the specified 'io1' ebs volume type" do
|
1296
|
-
|
1297
|
-
server_def =
|
1294
|
+
knife_ec2_create.config[:ebs_volume_type] = 'io1'
|
1295
|
+
server_def = knife_ec2_create.create_server_def
|
1298
1296
|
|
1299
1297
|
expect(server_def[:block_device_mapping].first['Ebs.VolumeType']).to eq('io1')
|
1300
1298
|
end
|
1301
1299
|
|
1302
1300
|
it "sets the specified 'gp2' ebs volume type" do
|
1303
|
-
|
1304
|
-
server_def =
|
1301
|
+
knife_ec2_create.config[:ebs_volume_type] = 'gp2'
|
1302
|
+
server_def = knife_ec2_create.create_server_def
|
1305
1303
|
|
1306
1304
|
expect(server_def[:block_device_mapping].first['Ebs.VolumeType']).to eq('gp2')
|
1307
1305
|
end
|
1308
1306
|
|
1309
1307
|
it "sets the specified ebs provisioned iops rate" do
|
1310
|
-
|
1311
|
-
|
1312
|
-
server_def =
|
1308
|
+
knife_ec2_create.config[:ebs_provisioned_iops] = '1234'
|
1309
|
+
knife_ec2_create.config[:ebs_volume_type] = 'io1'
|
1310
|
+
server_def = knife_ec2_create.create_server_def
|
1313
1311
|
|
1314
1312
|
expect(server_def[:block_device_mapping].first['Ebs.Iops']).to eq('1234')
|
1315
1313
|
end
|
1316
1314
|
|
1317
1315
|
it "disallows non integer ebs provisioned iops rate" do
|
1318
|
-
|
1316
|
+
knife_ec2_create.config[:ebs_provisioned_iops] = "123abcd"
|
1319
1317
|
|
1320
|
-
expect {
|
1318
|
+
expect { knife_ec2_create.create_server_def }.to raise_error SystemExit
|
1321
1319
|
end
|
1322
1320
|
|
1323
1321
|
it "sets the iops rate from ami" do
|
1324
|
-
|
1325
|
-
server_def =
|
1322
|
+
knife_ec2_create.config[:ebs_volume_type] = 'io1'
|
1323
|
+
server_def = knife_ec2_create.create_server_def
|
1326
1324
|
|
1327
1325
|
expect(server_def[:block_device_mapping].first['Ebs.Iops']).to eq('123')
|
1328
1326
|
end
|
@@ -1334,16 +1332,16 @@ describe Chef::Knife::Ec2ServerCreate do
|
|
1334
1332
|
let(:hostname) { 'test.host.com' }
|
1335
1333
|
|
1336
1334
|
it "should wait for tunnelled ssh if a ssh gateway is provided" do
|
1337
|
-
allow(
|
1338
|
-
expect(
|
1339
|
-
|
1335
|
+
allow(knife_ec2_create).to receive(:get_ssh_gateway_for).and_return(gateway)
|
1336
|
+
expect(knife_ec2_create).to receive(:wait_for_tunnelled_sshd).with(gateway, hostname)
|
1337
|
+
knife_ec2_create.wait_for_sshd(hostname)
|
1340
1338
|
end
|
1341
1339
|
|
1342
1340
|
it "should wait for direct ssh if a ssh gateway is not provided" do
|
1343
|
-
allow(
|
1344
|
-
|
1345
|
-
expect(
|
1346
|
-
|
1341
|
+
allow(knife_ec2_create).to receive(:get_ssh_gateway_for).and_return(nil)
|
1342
|
+
knife_ec2_create.config[:ssh_port] = 22
|
1343
|
+
expect(knife_ec2_create).to receive(:wait_for_direct_sshd).with(hostname, 22)
|
1344
|
+
knife_ec2_create.wait_for_sshd(hostname)
|
1347
1345
|
end
|
1348
1346
|
end
|
1349
1347
|
|
@@ -1353,88 +1351,88 @@ describe Chef::Knife::Ec2ServerCreate do
|
|
1353
1351
|
|
1354
1352
|
it "should give precedence to the ssh gateway specified in the knife configuration" do
|
1355
1353
|
allow(Net::SSH::Config).to receive(:for).and_return(:proxy => Net::SSH::Proxy::Command.new("ssh some.other.gateway.com nc %h %p"))
|
1356
|
-
|
1357
|
-
expect(
|
1354
|
+
knife_ec2_create.config[:ssh_gateway] = gateway
|
1355
|
+
expect(knife_ec2_create.get_ssh_gateway_for(hostname)).to eq(gateway)
|
1358
1356
|
end
|
1359
1357
|
|
1360
1358
|
it "should return the ssh gateway specified in the ssh configuration even if the config option is not set" do
|
1361
1359
|
# This should already be false, but test this explicitly for regression
|
1362
|
-
|
1360
|
+
knife_ec2_create.config[:ssh_gateway] = false
|
1363
1361
|
allow(Net::SSH::Config).to receive(:for).and_return(:proxy => Net::SSH::Proxy::Command.new("ssh #{gateway} nc %h %p"))
|
1364
|
-
expect(
|
1362
|
+
expect(knife_ec2_create.get_ssh_gateway_for(hostname)).to eq(gateway)
|
1365
1363
|
end
|
1366
1364
|
|
1367
1365
|
it "should return nil if the ssh gateway cannot be parsed from the ssh proxy command" do
|
1368
1366
|
allow(Net::SSH::Config).to receive(:for).and_return(:proxy => Net::SSH::Proxy::Command.new("cannot parse host"))
|
1369
|
-
expect(
|
1367
|
+
expect(knife_ec2_create.get_ssh_gateway_for(hostname)).to be_nil
|
1370
1368
|
end
|
1371
1369
|
|
1372
1370
|
it "should return nil if the ssh proxy is not a proxy command" do
|
1373
1371
|
allow(Net::SSH::Config).to receive(:for).and_return(:proxy => Net::SSH::Proxy::HTTP.new("httphost.com"))
|
1374
|
-
expect(
|
1372
|
+
expect(knife_ec2_create.get_ssh_gateway_for(hostname)).to be_nil
|
1375
1373
|
end
|
1376
1374
|
|
1377
1375
|
it "returns nil if the ssh config has no proxy" do
|
1378
1376
|
allow(Net::SSH::Config).to receive(:for).and_return(:user => "darius")
|
1379
|
-
expect(
|
1377
|
+
expect(knife_ec2_create.get_ssh_gateway_for(hostname)).to be_nil
|
1380
1378
|
end
|
1381
1379
|
|
1382
1380
|
end
|
1383
1381
|
|
1384
1382
|
describe "ssh_connect_host" do
|
1385
1383
|
before(:each) do
|
1386
|
-
allow(
|
1384
|
+
allow(new_ec2_server).to receive_messages(
|
1387
1385
|
:dns_name => 'public.example.org',
|
1388
1386
|
:private_ip_address => '192.168.1.100',
|
1389
1387
|
:custom => 'custom',
|
1390
1388
|
:public_ip_address => '111.111.111.111'
|
1391
1389
|
)
|
1392
|
-
allow(
|
1390
|
+
allow(knife_ec2_create).to receive_messages(:server => new_ec2_server)
|
1393
1391
|
end
|
1394
1392
|
|
1395
1393
|
describe "by default" do
|
1396
1394
|
it 'should use public dns name' do
|
1397
|
-
expect(
|
1395
|
+
expect(knife_ec2_create.ssh_connect_host).to eq('public.example.org')
|
1398
1396
|
end
|
1399
1397
|
end
|
1400
1398
|
|
1401
1399
|
describe "when dns name not exist" do
|
1402
1400
|
it 'should use public_ip_address ' do
|
1403
|
-
allow(
|
1404
|
-
expect(
|
1401
|
+
allow(new_ec2_server).to receive(:dns_name).and_return(nil)
|
1402
|
+
expect(knife_ec2_create.ssh_connect_host).to eq('111.111.111.111')
|
1405
1403
|
end
|
1406
1404
|
end
|
1407
1405
|
|
1408
1406
|
context "when vpc_mode? is true" do
|
1409
1407
|
before do
|
1410
|
-
allow(
|
1408
|
+
allow(knife_ec2_create).to receive_messages(:vpc_mode? => true)
|
1411
1409
|
end
|
1412
1410
|
|
1413
1411
|
context "--associate-public-ip is specified" do
|
1414
1412
|
it "uses the dns_name or public_ip_address" do
|
1415
|
-
|
1416
|
-
expect(
|
1413
|
+
knife_ec2_create.config[:associate_public_ip] = true
|
1414
|
+
expect(knife_ec2_create.ssh_connect_host).to eq('public.example.org')
|
1417
1415
|
end
|
1418
1416
|
end
|
1419
1417
|
|
1420
1418
|
context "--associate-eip is specified" do
|
1421
1419
|
it "uses the dns_name or public_ip_address" do
|
1422
|
-
|
1423
|
-
expect(
|
1420
|
+
knife_ec2_create.config[:associate_eip] = '111.111.111.111'
|
1421
|
+
expect(knife_ec2_create.ssh_connect_host).to eq('public.example.org')
|
1424
1422
|
end
|
1425
1423
|
end
|
1426
1424
|
|
1427
1425
|
context "with no other ip flags" do
|
1428
1426
|
it 'uses private_ip_address' do
|
1429
|
-
expect(
|
1427
|
+
expect(knife_ec2_create.ssh_connect_host).to eq('192.168.1.100')
|
1430
1428
|
end
|
1431
1429
|
end
|
1432
1430
|
end
|
1433
1431
|
|
1434
1432
|
describe "with custom server attribute" do
|
1435
1433
|
it 'should use custom server attribute' do
|
1436
|
-
|
1437
|
-
expect(
|
1434
|
+
knife_ec2_create.config[:server_connect_attribute] = 'custom'
|
1435
|
+
expect(knife_ec2_create.ssh_connect_host).to eq('custom')
|
1438
1436
|
end
|
1439
1437
|
end
|
1440
1438
|
end
|
@@ -1446,14 +1444,14 @@ describe Chef::Knife::Ec2ServerCreate do
|
|
1446
1444
|
let(:local_port) { 23 }
|
1447
1445
|
|
1448
1446
|
before(:each) do
|
1449
|
-
allow(
|
1447
|
+
allow(knife_ec2_create).to receive(:configure_ssh_gateway).and_return(gateway)
|
1450
1448
|
end
|
1451
1449
|
|
1452
1450
|
it "should test ssh through a gateway" do
|
1453
|
-
|
1451
|
+
knife_ec2_create.config[:ssh_port] = 22
|
1454
1452
|
expect(gateway).to receive(:open).with(hostname, 22).and_yield(local_port)
|
1455
|
-
expect(
|
1456
|
-
expect(
|
1453
|
+
expect(knife_ec2_create).to receive(:tcp_test_ssh).with('localhost', local_port).and_return(true)
|
1454
|
+
expect(knife_ec2_create.tunnel_test_ssh(gateway_host, hostname)).to eq(true)
|
1457
1455
|
end
|
1458
1456
|
end
|
1459
1457
|
|
@@ -1464,81 +1462,81 @@ describe Chef::Knife::Ec2ServerCreate do
|
|
1464
1462
|
it "configures a ssh gateway with no user and the default port when the SSH Config is empty" do
|
1465
1463
|
allow(Net::SSH::Config).to receive(:for).and_return({})
|
1466
1464
|
expect(Net::SSH::Gateway).to receive(:new).with(gateway_host, nil, :port => 22)
|
1467
|
-
|
1465
|
+
knife_ec2_create.configure_ssh_gateway(gateway_host)
|
1468
1466
|
end
|
1469
1467
|
|
1470
1468
|
it "configures a ssh gateway with the user specified in the SSH Config" do
|
1471
1469
|
allow(Net::SSH::Config).to receive(:for).and_return({ :user => gateway_user })
|
1472
1470
|
expect(Net::SSH::Gateway).to receive(:new).with(gateway_host, gateway_user, :port => 22)
|
1473
|
-
|
1471
|
+
knife_ec2_create.configure_ssh_gateway(gateway_host)
|
1474
1472
|
end
|
1475
1473
|
|
1476
1474
|
it "configures a ssh gateway with the user specified in the ssh gateway string" do
|
1477
1475
|
allow(Net::SSH::Config).to receive(:for).and_return({ :user => gateway_user })
|
1478
1476
|
expect(Net::SSH::Gateway).to receive(:new).with(gateway_host, 'override_user', :port => 22)
|
1479
|
-
|
1477
|
+
knife_ec2_create.configure_ssh_gateway("override_user@#{gateway_host}")
|
1480
1478
|
end
|
1481
1479
|
|
1482
1480
|
it "configures a ssh gateway with the port specified in the ssh gateway string" do
|
1483
1481
|
allow(Net::SSH::Config).to receive(:for).and_return({})
|
1484
1482
|
expect(Net::SSH::Gateway).to receive(:new).with(gateway_host, nil, :port => '24')
|
1485
|
-
|
1483
|
+
knife_ec2_create.configure_ssh_gateway("#{gateway_host}:24")
|
1486
1484
|
end
|
1487
1485
|
|
1488
1486
|
it "configures a ssh gateway with the keys specified in the SSH Config" do
|
1489
1487
|
allow(Net::SSH::Config).to receive(:for).and_return({ :keys => ['configuredkey'] })
|
1490
1488
|
expect(Net::SSH::Gateway).to receive(:new).with(gateway_host, nil, :port => 22, :keys => ['configuredkey'])
|
1491
|
-
|
1489
|
+
knife_ec2_create.configure_ssh_gateway(gateway_host)
|
1492
1490
|
end
|
1493
1491
|
|
1494
1492
|
it "configures the ssh gateway with the key specified on the knife config / command line" do
|
1495
|
-
|
1493
|
+
knife_ec2_create.config[:ssh_gateway_identity] = "/home/fireman/.ssh/gateway.pem"
|
1496
1494
|
#Net::SSH::Config.stub(:for).and_return({ :keys => ['configuredkey'] })
|
1497
1495
|
expect(Net::SSH::Gateway).to receive(:new).with(gateway_host, nil, :port => 22, :keys => ['/home/fireman/.ssh/gateway.pem'])
|
1498
|
-
|
1496
|
+
knife_ec2_create.configure_ssh_gateway(gateway_host)
|
1499
1497
|
end
|
1500
1498
|
|
1501
1499
|
it "prefers the knife config over the ssh config for the gateway keys" do
|
1502
|
-
|
1500
|
+
knife_ec2_create.config[:ssh_gateway_identity] = "/home/fireman/.ssh/gateway.pem"
|
1503
1501
|
allow(Net::SSH::Config).to receive(:for).and_return({ :keys => ['not_this_key_dude'] })
|
1504
1502
|
expect(Net::SSH::Gateway).to receive(:new).with(gateway_host, nil, :port => 22, :keys => ['/home/fireman/.ssh/gateway.pem'])
|
1505
|
-
|
1503
|
+
knife_ec2_create.configure_ssh_gateway(gateway_host)
|
1506
1504
|
end
|
1507
1505
|
end
|
1508
1506
|
|
1509
1507
|
describe "tcp_test_ssh" do
|
1510
1508
|
# Normally we would only get the header after we send a client header, e.g. 'SSH-2.0-client'
|
1511
1509
|
it "should return true if we get an ssh header" do
|
1512
|
-
|
1510
|
+
knife_ec2_create = Chef::Knife::Ec2ServerCreate.new
|
1513
1511
|
allow(TCPSocket).to receive(:new).and_return(StringIO.new("SSH-2.0-OpenSSH_6.1p1 Debian-4"))
|
1514
1512
|
allow(IO).to receive(:select).and_return(true)
|
1515
|
-
expect(
|
1516
|
-
|
1513
|
+
expect(knife_ec2_create).to receive(:tcp_test_ssh).and_yield.and_return(true)
|
1514
|
+
knife_ec2_create.tcp_test_ssh("blackhole.ninja", 22) {nil}
|
1517
1515
|
end
|
1518
1516
|
|
1519
1517
|
it "should return false if we do not get an ssh header" do
|
1520
|
-
|
1518
|
+
knife_ec2_create = Chef::Knife::Ec2ServerCreate.new
|
1521
1519
|
allow(TCPSocket).to receive(:new).and_return(StringIO.new(""))
|
1522
1520
|
allow(IO).to receive(:select).and_return(true)
|
1523
|
-
expect(
|
1521
|
+
expect(knife_ec2_create.tcp_test_ssh("blackhole.ninja", 22)).to be_falsey
|
1524
1522
|
end
|
1525
1523
|
|
1526
1524
|
it "should return false if the socket isn't ready" do
|
1527
|
-
|
1525
|
+
knife_ec2_create = Chef::Knife::Ec2ServerCreate.new
|
1528
1526
|
allow(TCPSocket).to receive(:new)
|
1529
1527
|
allow(IO).to receive(:select).and_return(false)
|
1530
|
-
expect(
|
1528
|
+
expect(knife_ec2_create.tcp_test_ssh("blackhole.ninja", 22)).to be_falsey
|
1531
1529
|
end
|
1532
1530
|
end
|
1533
1531
|
|
1534
1532
|
describe 'ssl_config_user_data' do
|
1535
1533
|
before do
|
1536
|
-
|
1534
|
+
knife_ec2_create.config[:winrm_password] = "ec2@123"
|
1537
1535
|
end
|
1538
1536
|
|
1539
|
-
context 'For domain user' do
|
1537
|
+
context 'For domain user' do
|
1540
1538
|
before do
|
1541
|
-
|
1539
|
+
knife_ec2_create.config[:winrm_user] = "domain\\ec2"
|
1542
1540
|
@ssl_config_data = <<-EOH
|
1543
1541
|
|
1544
1542
|
If (-Not (Get-Service WinRM | Where-Object {$_.status -eq "Running"})) {
|
@@ -1559,15 +1557,15 @@ netsh advfirewall firewall add rule name="WinRM HTTPS" protocol=TCP dir=in Local
|
|
1559
1557
|
end
|
1560
1558
|
|
1561
1559
|
it 'gets ssl config user data' do
|
1562
|
-
expect(
|
1560
|
+
expect(knife_ec2_create.ssl_config_user_data).to be == @ssl_config_data
|
1563
1561
|
end
|
1564
1562
|
end
|
1565
1563
|
|
1566
1564
|
context 'For local user' do
|
1567
1565
|
before do
|
1568
|
-
|
1566
|
+
knife_ec2_create.config[:winrm_user] = ".\\ec2"
|
1569
1567
|
@ssl_config_data = <<-EOH
|
1570
|
-
net user /add ec2 ec2@123;
|
1568
|
+
net user /add ec2 ec2@123;
|
1571
1569
|
net localgroup Administrators /add ec2;
|
1572
1570
|
|
1573
1571
|
If (-Not (Get-Service WinRM | Where-Object {$_.status -eq "Running"})) {
|
@@ -1589,7 +1587,7 @@ netsh advfirewall firewall add rule name="WinRM HTTPS" protocol=TCP dir=in Local
|
|
1589
1587
|
end
|
1590
1588
|
|
1591
1589
|
it 'gets ssl config user data' do
|
1592
|
-
expect(
|
1590
|
+
expect(knife_ec2_create.ssl_config_user_data).to be == @ssl_config_data
|
1593
1591
|
end
|
1594
1592
|
end
|
1595
1593
|
end
|
@@ -1598,9 +1596,9 @@ netsh advfirewall firewall add rule name="WinRM HTTPS" protocol=TCP dir=in Local
|
|
1598
1596
|
|
1599
1597
|
before(:each) do
|
1600
1598
|
@user_user_data = 'user_user_data.ps1'
|
1601
|
-
|
1602
|
-
|
1603
|
-
|
1599
|
+
knife_ec2_create.config[:winrm_user] = "domain\\ec2"
|
1600
|
+
knife_ec2_create.config[:winrm_password] = "ec2@123"
|
1601
|
+
knife_ec2_create.config[:aws_user_data] = @user_user_data
|
1604
1602
|
end
|
1605
1603
|
|
1606
1604
|
context 'ssl config data does not exist in user supplied user_data' do
|
@@ -1614,7 +1612,7 @@ user_command_4
|
|
1614
1612
|
end
|
1615
1613
|
|
1616
1614
|
it 'returns false' do
|
1617
|
-
expect(
|
1615
|
+
expect(knife_ec2_create.ssl_config_data_already_exist?).to eq(false)
|
1618
1616
|
end
|
1619
1617
|
end
|
1620
1618
|
|
@@ -1648,25 +1646,25 @@ netsh advfirewall firewall add rule name="WinRM HTTPS" protocol=TCP dir=in Local
|
|
1648
1646
|
end
|
1649
1647
|
|
1650
1648
|
it 'returns false' do
|
1651
|
-
expect(
|
1649
|
+
expect(knife_ec2_create.ssl_config_data_already_exist?).to eq(true)
|
1652
1650
|
end
|
1653
1651
|
end
|
1654
1652
|
|
1655
1653
|
after(:each) do
|
1656
|
-
|
1654
|
+
knife_ec2_create.config.delete(:aws_user_data)
|
1657
1655
|
FileUtils.rm_rf @user_user_data
|
1658
1656
|
end
|
1659
1657
|
end
|
1660
1658
|
|
1661
1659
|
describe 'attach ssl config into user data when transport is ssl' do
|
1662
1660
|
before(:each) do
|
1663
|
-
allow(Fog::Compute::AWS).to receive(:new).and_return(
|
1661
|
+
allow(Fog::Compute::AWS).to receive(:new).and_return(ec2_connection)
|
1664
1662
|
Chef::Config[:knife][:ssh_key_name] = "mykey"
|
1665
|
-
|
1666
|
-
|
1667
|
-
|
1668
|
-
|
1669
|
-
|
1663
|
+
knife_ec2_create.config[:ssh_key_name] = "ssh_key_name"
|
1664
|
+
knife_ec2_create.config[:winrm_transport] = "ssl"
|
1665
|
+
knife_ec2_create.config[:create_ssl_listener] = true
|
1666
|
+
knife_ec2_create.config[:winrm_user] = "domain\\ec2"
|
1667
|
+
knife_ec2_create.config[:winrm_password] = "ec2@123"
|
1670
1668
|
end
|
1671
1669
|
|
1672
1670
|
context 'when user_data script provided by user contains only <script> section' do
|
@@ -1707,17 +1705,17 @@ netsh advfirewall firewall add rule name="WinRM HTTPS" protocol=TCP dir=in Local
|
|
1707
1705
|
|
1708
1706
|
</powershell>
|
1709
1707
|
EOH
|
1710
|
-
|
1708
|
+
knife_ec2_create.config[:aws_user_data] = @user_user_data
|
1711
1709
|
end
|
1712
1710
|
|
1713
1711
|
it "appends ssl config to user supplied user_data after <script> tag section" do
|
1714
|
-
server_def =
|
1712
|
+
server_def = knife_ec2_create.create_server_def
|
1715
1713
|
|
1716
1714
|
expect(server_def[:user_data]).to eq(@server_def_user_data)
|
1717
1715
|
end
|
1718
1716
|
|
1719
1717
|
after do
|
1720
|
-
|
1718
|
+
knife_ec2_create.config.delete(:aws_user_data)
|
1721
1719
|
FileUtils.rm_rf @user_user_data
|
1722
1720
|
end
|
1723
1721
|
end
|
@@ -1754,17 +1752,17 @@ netsh advfirewall firewall add rule name="WinRM HTTPS" protocol=TCP dir=in Local
|
|
1754
1752
|
|
1755
1753
|
</powershell>
|
1756
1754
|
EOH
|
1757
|
-
|
1755
|
+
knife_ec2_create.config[:aws_user_data] = @user_user_data
|
1758
1756
|
end
|
1759
1757
|
|
1760
1758
|
it "appends ssl config to user supplied user_data at the end of <powershell> tag section" do
|
1761
|
-
server_def =
|
1759
|
+
server_def = knife_ec2_create.create_server_def
|
1762
1760
|
|
1763
1761
|
expect(server_def[:user_data]).to eq(@server_def_user_data)
|
1764
1762
|
end
|
1765
1763
|
|
1766
1764
|
after do
|
1767
|
-
|
1765
|
+
knife_ec2_create.config.delete(:aws_user_data)
|
1768
1766
|
FileUtils.rm_rf @user_user_data
|
1769
1767
|
end
|
1770
1768
|
end
|
@@ -1816,17 +1814,17 @@ netsh advfirewall firewall add rule name="WinRM HTTPS" protocol=TCP dir=in Local
|
|
1816
1814
|
|
1817
1815
|
</powershell>
|
1818
1816
|
EOH
|
1819
|
-
|
1817
|
+
knife_ec2_create.config[:aws_user_data] = @user_user_data
|
1820
1818
|
end
|
1821
1819
|
|
1822
1820
|
it "does no modifications and passes user_data as it is to server_def" do
|
1823
|
-
server_def =
|
1821
|
+
server_def = knife_ec2_create.create_server_def
|
1824
1822
|
|
1825
1823
|
expect(server_def[:user_data]).to eq(@server_def_user_data)
|
1826
1824
|
end
|
1827
1825
|
|
1828
1826
|
after do
|
1829
|
-
|
1827
|
+
knife_ec2_create.config.delete(:aws_user_data)
|
1830
1828
|
FileUtils.rm_rf @user_user_data
|
1831
1829
|
end
|
1832
1830
|
end
|
@@ -1847,16 +1845,16 @@ ipconfig > c:\\ipconfig_data.txt
|
|
1847
1845
|
</script>
|
1848
1846
|
EOH
|
1849
1847
|
end
|
1850
|
-
|
1848
|
+
knife_ec2_create.config[:aws_user_data] = @user_user_data
|
1851
1849
|
end
|
1852
1850
|
|
1853
1851
|
it "gives error and exits" do
|
1854
|
-
expect(
|
1855
|
-
expect {
|
1852
|
+
expect(knife_ec2_create.ui).to receive(:error).with("Provided user_data file is invalid.")
|
1853
|
+
expect { knife_ec2_create.create_server_def }.to raise_error SystemExit
|
1856
1854
|
end
|
1857
1855
|
|
1858
1856
|
after do
|
1859
|
-
|
1857
|
+
knife_ec2_create.config.delete(:aws_user_data)
|
1860
1858
|
FileUtils.rm_rf @user_user_data
|
1861
1859
|
end
|
1862
1860
|
end
|
@@ -1905,17 +1903,17 @@ ipconfig > c:\\ipconfig_data.txt
|
|
1905
1903
|
|
1906
1904
|
</script>
|
1907
1905
|
EOH
|
1908
|
-
|
1906
|
+
knife_ec2_create.config[:aws_user_data] = @user_user_data
|
1909
1907
|
end
|
1910
1908
|
|
1911
1909
|
it "appends ssl config to user supplied user_data at the end of <powershell> tag section" do
|
1912
|
-
server_def =
|
1910
|
+
server_def = knife_ec2_create.create_server_def
|
1913
1911
|
|
1914
1912
|
expect(server_def[:user_data]).to eq(@server_def_user_data)
|
1915
1913
|
end
|
1916
1914
|
|
1917
1915
|
after do
|
1918
|
-
|
1916
|
+
knife_ec2_create.config.delete(:aws_user_data)
|
1919
1917
|
FileUtils.rm_rf @user_user_data
|
1920
1918
|
end
|
1921
1919
|
end
|
@@ -1944,7 +1942,7 @@ netsh advfirewall firewall add rule name="WinRM HTTPS" protocol=TCP dir=in Local
|
|
1944
1942
|
end
|
1945
1943
|
|
1946
1944
|
it "creates user_data only with default ssl configuration" do
|
1947
|
-
server_def =
|
1945
|
+
server_def = knife_ec2_create.create_server_def
|
1948
1946
|
|
1949
1947
|
expect(server_def[:user_data]).to eq(@server_def_user_data)
|
1950
1948
|
end
|
@@ -1952,7 +1950,7 @@ netsh advfirewall firewall add rule name="WinRM HTTPS" protocol=TCP dir=in Local
|
|
1952
1950
|
|
1953
1951
|
context "when user has specified --no-create-ssl-listener along with his/her own user_data on cli" do
|
1954
1952
|
before do
|
1955
|
-
|
1953
|
+
knife_ec2_create.config[:create_ssl_listener] = false
|
1956
1954
|
@user_user_data = 'user_user_data.ps1'
|
1957
1955
|
File.open(@user_user_data,"w+") do |f|
|
1958
1956
|
f.write <<-EOH
|
@@ -1980,48 +1978,48 @@ ipconfig > c:\\ipconfig_data.txt
|
|
1980
1978
|
|
1981
1979
|
</script>
|
1982
1980
|
EOH
|
1983
|
-
|
1981
|
+
knife_ec2_create.config[:aws_user_data] = @user_user_data
|
1984
1982
|
end
|
1985
1983
|
|
1986
1984
|
it "does not attach ssl config into the user_data supplied by user on cli" do
|
1987
|
-
server_def =
|
1985
|
+
server_def = knife_ec2_create.create_server_def
|
1988
1986
|
|
1989
1987
|
expect(server_def[:user_data]).to eq(@server_def_user_data)
|
1990
1988
|
end
|
1991
1989
|
|
1992
1990
|
after do
|
1993
|
-
|
1991
|
+
knife_ec2_create.config.delete(:aws_user_data)
|
1994
1992
|
FileUtils.rm_rf @user_user_data
|
1995
1993
|
end
|
1996
1994
|
end
|
1997
1995
|
|
1998
1996
|
context "when user has specified --no-create-ssl-listener with no user_data on cli" do
|
1999
1997
|
before do
|
2000
|
-
|
1998
|
+
knife_ec2_create.config[:create_ssl_listener] = false
|
2001
1999
|
@server_def_user_data = nil
|
2002
2000
|
end
|
2003
2001
|
|
2004
2002
|
it "creates nil or empty user_data" do
|
2005
|
-
server_def =
|
2003
|
+
server_def = knife_ec2_create.create_server_def
|
2006
2004
|
|
2007
2005
|
expect(server_def[:user_data]).to eq(@server_def_user_data)
|
2008
2006
|
end
|
2009
2007
|
end
|
2010
2008
|
|
2011
2009
|
after(:each) do
|
2012
|
-
|
2010
|
+
knife_ec2_create.config.delete(:ssh_key_name)
|
2013
2011
|
Chef::Config[:knife].delete(:ssh_key_name)
|
2014
|
-
|
2015
|
-
|
2012
|
+
knife_ec2_create.config.delete(:winrm_transport)
|
2013
|
+
knife_ec2_create.config.delete(:create_ssl_listener)
|
2016
2014
|
end
|
2017
2015
|
end
|
2018
2016
|
|
2019
2017
|
describe "do not attach ssl config into user data when transport is plaintext" do
|
2020
2018
|
before(:each) do
|
2021
|
-
allow(Fog::Compute::AWS).to receive(:new).and_return(
|
2019
|
+
allow(Fog::Compute::AWS).to receive(:new).and_return(ec2_connection)
|
2022
2020
|
Chef::Config[:knife][:ssh_key_name] = "mykey"
|
2023
|
-
|
2024
|
-
|
2021
|
+
knife_ec2_create.config[:ssh_key_name] = "ssh_key_name"
|
2022
|
+
knife_ec2_create.config[:winrm_transport] = "plaintext"
|
2025
2023
|
end
|
2026
2024
|
|
2027
2025
|
context "when user_data is supplied on cli" do
|
@@ -2037,7 +2035,7 @@ netstat > c:\\netstat_data.txt
|
|
2037
2035
|
</script>
|
2038
2036
|
EOH
|
2039
2037
|
end
|
2040
|
-
|
2038
|
+
knife_ec2_create.config[:aws_user_data] = @user_user_data
|
2041
2039
|
@server_def_user_data = <<-EOH
|
2042
2040
|
<script>
|
2043
2041
|
|
@@ -2049,13 +2047,13 @@ netstat > c:\\netstat_data.txt
|
|
2049
2047
|
end
|
2050
2048
|
|
2051
2049
|
it "user_data is created only with user's user_data" do
|
2052
|
-
server_def =
|
2050
|
+
server_def = knife_ec2_create.create_server_def
|
2053
2051
|
|
2054
2052
|
expect(server_def[:user_data]).to eq(@server_def_user_data)
|
2055
2053
|
end
|
2056
2054
|
|
2057
2055
|
after do
|
2058
|
-
|
2056
|
+
knife_ec2_create.config.delete(:aws_user_data)
|
2059
2057
|
FileUtils.rm_rf @user_user_data
|
2060
2058
|
end
|
2061
2059
|
end
|
@@ -2066,16 +2064,16 @@ netstat > c:\\netstat_data.txt
|
|
2066
2064
|
end
|
2067
2065
|
|
2068
2066
|
it "creates nil or empty user_data" do
|
2069
|
-
server_def =
|
2067
|
+
server_def = knife_ec2_create.create_server_def
|
2070
2068
|
|
2071
2069
|
expect(server_def[:user_data]).to eq(@server_def_user_data)
|
2072
2070
|
end
|
2073
2071
|
end
|
2074
2072
|
|
2075
2073
|
after(:each) do
|
2076
|
-
|
2074
|
+
knife_ec2_create.config.delete(:ssh_key_name)
|
2077
2075
|
Chef::Config[:knife].delete(:ssh_key_name)
|
2078
|
-
|
2076
|
+
knife_ec2_create.config.delete(:winrm_transport)
|
2079
2077
|
end
|
2080
2078
|
end
|
2081
2079
|
|
@@ -2083,50 +2081,50 @@ netstat > c:\\netstat_data.txt
|
|
2083
2081
|
context 'spot instance' do
|
2084
2082
|
context 'disable_api_termination is not passed on CLI or in knife config' do
|
2085
2083
|
before do
|
2086
|
-
allow(Fog::Compute::AWS).to receive(:new).and_return(
|
2087
|
-
|
2084
|
+
allow(Fog::Compute::AWS).to receive(:new).and_return(ec2_connection)
|
2085
|
+
knife_ec2_create.config[:spot_price] = 0.001
|
2088
2086
|
end
|
2089
2087
|
|
2090
2088
|
it "does not set disable_api_termination option in server_def" do
|
2091
|
-
server_def =
|
2089
|
+
server_def = knife_ec2_create.create_server_def
|
2092
2090
|
expect(server_def[:disable_api_termination]).to be == nil
|
2093
2091
|
end
|
2094
2092
|
|
2095
2093
|
it "does not raise error" do
|
2096
|
-
expect(
|
2094
|
+
expect(knife_ec2_create.ui).to_not receive(:error).with(
|
2097
2095
|
"spot-price and disable-api-termination options cannot be passed together as 'Termination Protection' cannot be enabled for spot instances."
|
2098
2096
|
)
|
2099
|
-
expect {
|
2097
|
+
expect { knife_ec2_create.validate! }.to_not raise_error
|
2100
2098
|
end
|
2101
2099
|
end
|
2102
2100
|
|
2103
2101
|
context 'disable_api_termination is passed on CLI' do
|
2104
2102
|
before do
|
2105
|
-
allow(Fog::Compute::AWS).to receive(:new).and_return(
|
2106
|
-
|
2107
|
-
|
2103
|
+
allow(Fog::Compute::AWS).to receive(:new).and_return(ec2_connection)
|
2104
|
+
knife_ec2_create.config[:spot_price] = 0.001
|
2105
|
+
knife_ec2_create.config[:disable_api_termination] = true
|
2108
2106
|
end
|
2109
2107
|
|
2110
2108
|
it "raises error" do
|
2111
|
-
expect(
|
2109
|
+
expect(knife_ec2_create.ui).to receive(:error).with(
|
2112
2110
|
"spot-price and disable-api-termination options cannot be passed together as 'Termination Protection' cannot be enabled for spot instances."
|
2113
2111
|
)
|
2114
|
-
expect {
|
2112
|
+
expect { knife_ec2_create.validate! }.to raise_error(SystemExit)
|
2115
2113
|
end
|
2116
2114
|
end
|
2117
2115
|
|
2118
2116
|
context 'disable_api_termination is passed in knife config' do
|
2119
2117
|
before do
|
2120
|
-
allow(Fog::Compute::AWS).to receive(:new).and_return(
|
2121
|
-
|
2118
|
+
allow(Fog::Compute::AWS).to receive(:new).and_return(ec2_connection)
|
2119
|
+
knife_ec2_create.config[:spot_price] = 0.001
|
2122
2120
|
Chef::Config[:knife][:disable_api_termination] = true
|
2123
2121
|
end
|
2124
2122
|
|
2125
2123
|
it "raises error" do
|
2126
|
-
expect(
|
2124
|
+
expect(knife_ec2_create.ui).to receive(:error).with(
|
2127
2125
|
"spot-price and disable-api-termination options cannot be passed together as 'Termination Protection' cannot be enabled for spot instances."
|
2128
2126
|
)
|
2129
|
-
expect {
|
2127
|
+
expect { knife_ec2_create.validate! }.to raise_error(SystemExit)
|
2130
2128
|
end
|
2131
2129
|
end
|
2132
2130
|
end
|
@@ -2134,59 +2132,117 @@ netstat > c:\\netstat_data.txt
|
|
2134
2132
|
context 'non-spot instance' do
|
2135
2133
|
context 'when disable_api_termination option is not passed on the CLI or in the knife config' do
|
2136
2134
|
before do
|
2137
|
-
allow(Fog::Compute::AWS).to receive(:new).and_return(
|
2135
|
+
allow(Fog::Compute::AWS).to receive(:new).and_return(ec2_connection)
|
2138
2136
|
end
|
2139
2137
|
|
2140
2138
|
it "sets disable_api_termination option in server_def with value as false" do
|
2141
|
-
server_def =
|
2139
|
+
server_def = knife_ec2_create.create_server_def
|
2142
2140
|
expect(server_def[:disable_api_termination]).to be == false
|
2143
2141
|
end
|
2144
2142
|
|
2145
2143
|
it "does not raise error" do
|
2146
|
-
expect(
|
2144
|
+
expect(knife_ec2_create.ui).to_not receive(:error).with(
|
2147
2145
|
"spot-price and disable-api-termination options cannot be passed together as 'Termination Protection' cannot be enabled for spot instances."
|
2148
2146
|
)
|
2149
|
-
expect {
|
2147
|
+
expect { knife_ec2_create.validate! }.to_not raise_error
|
2150
2148
|
end
|
2151
2149
|
end
|
2152
2150
|
|
2153
2151
|
context "when disable_api_termination option is passed on the CLI" do
|
2154
2152
|
before do
|
2155
|
-
allow(Fog::Compute::AWS).to receive(:new).and_return(
|
2156
|
-
|
2153
|
+
allow(Fog::Compute::AWS).to receive(:new).and_return(ec2_connection)
|
2154
|
+
knife_ec2_create.config[:disable_api_termination] = true
|
2157
2155
|
end
|
2158
2156
|
|
2159
2157
|
it "sets disable_api_termination option in server_def with value as true" do
|
2160
|
-
server_def =
|
2158
|
+
server_def = knife_ec2_create.create_server_def
|
2161
2159
|
expect(server_def[:disable_api_termination]).to be == true
|
2162
2160
|
end
|
2163
2161
|
|
2164
2162
|
it "does not raise error" do
|
2165
|
-
expect(
|
2163
|
+
expect(knife_ec2_create.ui).to_not receive(:error).with(
|
2166
2164
|
"spot-price and disable-api-termination options cannot be passed together as 'Termination Protection' cannot be enabled for spot instances."
|
2167
2165
|
)
|
2168
|
-
expect {
|
2166
|
+
expect { knife_ec2_create.validate! }.to_not raise_error
|
2169
2167
|
end
|
2170
2168
|
end
|
2171
2169
|
|
2172
2170
|
context "when disable_api_termination option is passed in the knife config" do
|
2173
2171
|
before do
|
2174
|
-
allow(Fog::Compute::AWS).to receive(:new).and_return(
|
2172
|
+
allow(Fog::Compute::AWS).to receive(:new).and_return(ec2_connection)
|
2175
2173
|
Chef::Config[:knife][:disable_api_termination] = true
|
2176
2174
|
end
|
2177
2175
|
|
2178
2176
|
it "sets disable_api_termination option in server_def with value as true" do
|
2179
|
-
server_def =
|
2177
|
+
server_def = knife_ec2_create.create_server_def
|
2180
2178
|
expect(server_def[:disable_api_termination]).to be == true
|
2181
2179
|
end
|
2182
2180
|
|
2183
2181
|
it "does not raise error" do
|
2184
|
-
expect(
|
2182
|
+
expect(knife_ec2_create.ui).to_not receive(:error).with(
|
2185
2183
|
"spot-price and disable-api-termination options cannot be passed together as 'Termination Protection' cannot be enabled for spot instances."
|
2186
2184
|
)
|
2187
|
-
expect {
|
2185
|
+
expect { knife_ec2_create.validate! }.to_not raise_error
|
2188
2186
|
end
|
2189
2187
|
end
|
2190
2188
|
end
|
2191
2189
|
end
|
2190
|
+
|
2191
|
+
describe '--security-group-ids option' do
|
2192
|
+
before do
|
2193
|
+
allow(Fog::Compute::AWS).to receive(:new).and_return(ec2_connection)
|
2194
|
+
end
|
2195
|
+
|
2196
|
+
context 'when comma seprated values are provided from cli' do
|
2197
|
+
let(:ec2_server_create) { Chef::Knife::Ec2ServerCreate.new(['--security-group-ids', 'sg-aabbccdd,sg-3764sdss,sg-00aa11bb'])}
|
2198
|
+
it 'creates array of security group ids' do
|
2199
|
+
server_def = ec2_server_create.create_server_def
|
2200
|
+
expect(server_def[:security_group_ids]).to eq(['sg-aabbccdd', 'sg-3764sdss', 'sg-00aa11bb'])
|
2201
|
+
end
|
2202
|
+
end
|
2203
|
+
|
2204
|
+
context 'when mulitple values provided from cli for e.g. --security-group-ids sg-aab343ytr --security-group-ids sg-3764sdss' do
|
2205
|
+
let(:ec2_server_create) { Chef::Knife::Ec2ServerCreate.new(['--security-group-ids', 'sg-aab343ytr', '--security-group-ids', 'sg-3764sdss'])}
|
2206
|
+
it 'creates array of security group ids' do
|
2207
|
+
server_def = ec2_server_create.create_server_def
|
2208
|
+
expect(server_def[:security_group_ids]).to eq(['sg-aab343ytr', 'sg-3764sdss'])
|
2209
|
+
end
|
2210
|
+
end
|
2211
|
+
|
2212
|
+
context 'when comma seprated input is provided from knife.rb' do
|
2213
|
+
it 'raises error' do
|
2214
|
+
Chef::Config[:knife][:security_group_ids] = 'sg-aabbccdd, sg-3764sdss, sg-00aa11bb'
|
2215
|
+
expect { knife_ec2_create.validate! }.to raise_error(SystemExit)
|
2216
|
+
end
|
2217
|
+
end
|
2218
|
+
|
2219
|
+
context 'when security group ids array is provided from knife.rb' do
|
2220
|
+
it 'allows --security-group-ids set from an array in knife.rb' do
|
2221
|
+
Chef::Config[:knife][:security_group_ids] = ['sg-aabbccdd', 'sg-3764sdss', 'sg-00aa11bb']
|
2222
|
+
expect { knife_ec2_create.validate! }.to_not raise_error(SystemExit)
|
2223
|
+
end
|
2224
|
+
end
|
2225
|
+
end
|
2226
|
+
|
2227
|
+
describe '--security-group-id option' do
|
2228
|
+
before do
|
2229
|
+
allow(Fog::Compute::AWS).to receive(:new).and_return(ec2_connection)
|
2230
|
+
end
|
2231
|
+
|
2232
|
+
context 'when mulitple values provided from cli for e.g. -g sg-aab343ytr -g sg-3764sdss' do
|
2233
|
+
let(:ec2_server_create) { Chef::Knife::Ec2ServerCreate.new(['-g', 'sg-aab343ytr', '-g', 'sg-3764sdss'])}
|
2234
|
+
it 'creates array of security group ids' do
|
2235
|
+
server_def = ec2_server_create.create_server_def
|
2236
|
+
expect(server_def[:security_group_ids]).to eq(['sg-aab343ytr', 'sg-3764sdss'])
|
2237
|
+
end
|
2238
|
+
end
|
2239
|
+
|
2240
|
+
context 'when single value provided from cli for e.g. --security-group-id 3764sdss' do
|
2241
|
+
let(:ec2_server_create) { Chef::Knife::Ec2ServerCreate.new(['--security-group-id', 'sg-aab343ytr'])}
|
2242
|
+
it 'creates array of security group ids' do
|
2243
|
+
server_def = ec2_server_create.create_server_def
|
2244
|
+
expect(server_def[:security_group_ids]).to eq(['sg-aab343ytr'])
|
2245
|
+
end
|
2246
|
+
end
|
2247
|
+
end
|
2192
2248
|
end
|