kitchen-ec2 1.3.2 → 1.4.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -27,7 +27,7 @@ describe Kitchen::Driver::Aws::InstanceGenerator do
27
27
  let(:config) { Hash.new }
28
28
  let(:resource) { instance_double(Aws::EC2::Resource) }
29
29
  let(:ec2) { instance_double(Kitchen::Driver::Aws::Client, :resource => resource) }
30
- let(:logger) { instance_double(Logger) }
30
+ let(:logger) { instance_double(Logger) }
31
31
  let(:generator) { Kitchen::Driver::Aws::InstanceGenerator.new(config, ec2, logger) }
32
32
 
33
33
  describe "#prepared_user_data" do
@@ -57,6 +57,14 @@ describe Kitchen::Driver::Aws::InstanceGenerator do
57
57
  expect(decoded).to eq("foo\nbar")
58
58
  end
59
59
  end
60
+
61
+ context "when config[:user_data] is binary" do
62
+ let(:config) { { :user_data => "foo\0bar" } }
63
+
64
+ it "handles nulls in user_data" do
65
+ expect(Base64.decode64(generator.prepared_user_data)).to eq "foo\0bar"
66
+ end
67
+ end
60
68
  end
61
69
 
62
70
  describe "#ec2_instance_data" do
@@ -67,8 +75,8 @@ describe Kitchen::Driver::Aws::InstanceGenerator do
67
75
  :subnets => [
68
76
  {
69
77
  :subnet_id => "s-123",
70
- :tags => [{ :key => "foo", :value => "bar" }]
71
- }
78
+ :tags => [{ :key => "foo", :value => "bar" }],
79
+ },
72
80
  ]
73
81
  )
74
82
 
@@ -77,8 +85,8 @@ describe Kitchen::Driver::Aws::InstanceGenerator do
77
85
  :security_groups => [
78
86
  {
79
87
  :group_id => "sg-123",
80
- :tags => [{ :key => "foo", :value => "bar" }]
81
- }
88
+ :tags => [{ :key => "foo", :value => "bar" }],
89
+ },
82
90
  ]
83
91
  )
84
92
 
@@ -100,7 +108,7 @@ describe Kitchen::Driver::Aws::InstanceGenerator do
100
108
  :ebs_optimized => true,
101
109
  :image_id => "ami-123",
102
110
  :subnet_id => "s-456",
103
- :private_ip_address => "0.0.0.0"
111
+ :private_ip_address => "0.0.0.0",
104
112
  }
105
113
  end
106
114
 
@@ -124,7 +132,7 @@ describe Kitchen::Driver::Aws::InstanceGenerator do
124
132
  :image_id => "ami-123",
125
133
  :aws_ssh_key_id => "key",
126
134
  :subnet_id => "s-456",
127
- :private_ip_address => "0.0.0.0"
135
+ :private_ip_address => "0.0.0.0",
128
136
  }
129
137
  end
130
138
 
@@ -152,8 +160,8 @@ describe Kitchen::Driver::Aws::InstanceGenerator do
152
160
  :subnet_filter =>
153
161
  {
154
162
  :tag => "foo",
155
- :value => "bar"
156
- }
163
+ :value => "bar",
164
+ },
157
165
  }
158
166
  end
159
167
 
@@ -163,8 +171,8 @@ describe Kitchen::Driver::Aws::InstanceGenerator do
163
171
  :filters => [
164
172
  {
165
173
  :name => "tag:foo",
166
- :values => ["bar"]
167
- }
174
+ :values => ["bar"],
175
+ },
168
176
  ]
169
177
  ).and_return(ec2_stub.describe_subnets)
170
178
  expect(generator.ec2_instance_data[:subnet_id]).to eq("s-123")
@@ -184,8 +192,8 @@ describe Kitchen::Driver::Aws::InstanceGenerator do
184
192
  :security_group_filter =>
185
193
  {
186
194
  :tag => "foo",
187
- :value => "bar"
188
- }
195
+ :value => "bar",
196
+ },
189
197
  }
190
198
  end
191
199
 
@@ -195,8 +203,8 @@ describe Kitchen::Driver::Aws::InstanceGenerator do
195
203
  :filters => [
196
204
  {
197
205
  :name => "tag:foo",
198
- :values => ["bar"]
199
- }
206
+ :values => ["bar"],
207
+ },
200
208
  ]
201
209
  ).and_return(ec2_stub.describe_security_groups)
202
210
  expect(generator.ec2_instance_data[:security_group_ids]).to eq(["sg-123"])
@@ -212,7 +220,7 @@ describe Kitchen::Driver::Aws::InstanceGenerator do
212
220
  :aws_ssh_key_id => "key",
213
221
  :subnet_id => "s-456",
214
222
  :private_ip_address => "0.0.0.0",
215
- :block_device_mappings => []
223
+ :block_device_mappings => [],
216
224
  }
217
225
  end
218
226
 
@@ -232,7 +240,7 @@ describe Kitchen::Driver::Aws::InstanceGenerator do
232
240
  let(:config) do
233
241
  {
234
242
  :region => "eu-east-1",
235
- :availability_zone => "eu-west-1c"
243
+ :availability_zone => "eu-west-1c",
236
244
  }
237
245
  end
238
246
  it "returns that in the instance data" do
@@ -252,7 +260,7 @@ describe Kitchen::Driver::Aws::InstanceGenerator do
252
260
  let(:config) do
253
261
  {
254
262
  :region => "eu-east-1",
255
- :availability_zone => "c"
263
+ :availability_zone => "c",
256
264
  }
257
265
  end
258
266
  it "adds the region to it in the instance data" do
@@ -271,7 +279,7 @@ describe Kitchen::Driver::Aws::InstanceGenerator do
271
279
  context "when availability_zone is not provided" do
272
280
  let(:config) do
273
281
  {
274
- :region => "eu-east-1"
282
+ :region => "eu-east-1",
275
283
  }
276
284
  end
277
285
  it "is not added to the instance data" do
@@ -291,7 +299,7 @@ describe Kitchen::Driver::Aws::InstanceGenerator do
291
299
  {
292
300
  :region => "eu-east-1",
293
301
  :availability_zone => "c",
294
- :tenancy => "dedicated"
302
+ :tenancy => "dedicated",
295
303
  }
296
304
  end
297
305
  it "adds the region to it in the instance data" do
@@ -312,7 +320,7 @@ describe Kitchen::Driver::Aws::InstanceGenerator do
312
320
  let(:config) do
313
321
  {
314
322
  :region => "eu-east-1",
315
- :tenancy => "default"
323
+ :tenancy => "default",
316
324
  }
317
325
  end
318
326
  it "is not added to the instance data" do
@@ -332,7 +340,7 @@ describe Kitchen::Driver::Aws::InstanceGenerator do
332
340
  let(:config) do
333
341
  {
334
342
  :region => "eu-east-1",
335
- :tenancy => "ephemeral"
343
+ :tenancy => "ephemeral",
336
344
  }
337
345
  end
338
346
  it "is not added to the instance data" do
@@ -352,7 +360,7 @@ describe Kitchen::Driver::Aws::InstanceGenerator do
352
360
  {
353
361
  :region => "eu-east-1",
354
362
  :availability_zone => "c",
355
- :tenancy => "dedicated"
363
+ :tenancy => "dedicated",
356
364
  }
357
365
  end
358
366
  it "adds the region to it in the instance data" do
@@ -373,7 +381,7 @@ describe Kitchen::Driver::Aws::InstanceGenerator do
373
381
  let(:config) do
374
382
  {
375
383
  :region => "eu-east-1",
376
- :tenancy => "default"
384
+ :tenancy => "default",
377
385
  }
378
386
  end
379
387
  it "is not added to the instance data" do
@@ -393,7 +401,7 @@ describe Kitchen::Driver::Aws::InstanceGenerator do
393
401
  let(:config) do
394
402
  {
395
403
  :region => "eu-east-1",
396
- :tenancy => "ephemeral"
404
+ :tenancy => "ephemeral",
397
405
  }
398
406
  end
399
407
  it "is not added to the instance data" do
@@ -411,7 +419,7 @@ describe Kitchen::Driver::Aws::InstanceGenerator do
411
419
  context "when subnet_id is provided" do
412
420
  let(:config) do
413
421
  {
414
- :subnet_id => "s-456"
422
+ :subnet_id => "s-456",
415
423
  }
416
424
  end
417
425
 
@@ -430,7 +438,7 @@ describe Kitchen::Driver::Aws::InstanceGenerator do
430
438
  context "when associate_public_ip is provided" do
431
439
  let(:config) do
432
440
  {
433
- :associate_public_ip => true
441
+ :associate_public_ip => true,
434
442
  }
435
443
  end
436
444
 
@@ -445,7 +453,7 @@ describe Kitchen::Driver::Aws::InstanceGenerator do
445
453
  :network_interfaces => [{
446
454
  :device_index => 0,
447
455
  :associate_public_ip_address => true,
448
- :delete_on_termination => true
456
+ :delete_on_termination => true,
449
457
  }]
450
458
  )
451
459
  end
@@ -454,7 +462,7 @@ describe Kitchen::Driver::Aws::InstanceGenerator do
454
462
  let(:config) do
455
463
  {
456
464
  :associate_public_ip => true,
457
- :subnet_id => "s-456"
465
+ :subnet_id => "s-456",
458
466
  }
459
467
  end
460
468
 
@@ -469,7 +477,7 @@ describe Kitchen::Driver::Aws::InstanceGenerator do
469
477
  :device_index => 0,
470
478
  :associate_public_ip_address => true,
471
479
  :delete_on_termination => true,
472
- :subnet_id => "s-456"
480
+ :subnet_id => "s-456",
473
481
  }]
474
482
  )
475
483
  end
@@ -479,7 +487,7 @@ describe Kitchen::Driver::Aws::InstanceGenerator do
479
487
  let(:config) do
480
488
  {
481
489
  :associate_public_ip => true,
482
- :security_group_ids => ["sg-789"]
490
+ :security_group_ids => ["sg-789"],
483
491
  }
484
492
  end
485
493
 
@@ -495,7 +503,7 @@ describe Kitchen::Driver::Aws::InstanceGenerator do
495
503
  :device_index => 0,
496
504
  :associate_public_ip_address => true,
497
505
  :delete_on_termination => true,
498
- :groups => ["sg-789"]
506
+ :groups => ["sg-789"],
499
507
  }]
500
508
  )
501
509
  end
@@ -508,7 +516,7 @@ describe Kitchen::Driver::Aws::InstanceGenerator do
508
516
  :device_index => 0,
509
517
  :associate_public_ip_address => true,
510
518
  :delete_on_termination => true,
511
- :groups => ["only-one"]
519
+ :groups => ["only-one"],
512
520
  }]
513
521
  )
514
522
  end
@@ -518,7 +526,7 @@ describe Kitchen::Driver::Aws::InstanceGenerator do
518
526
  let(:config) do
519
527
  {
520
528
  :associate_public_ip => true,
521
- :private_ip_address => "0.0.0.0"
529
+ :private_ip_address => "0.0.0.0",
522
530
  }
523
531
  end
524
532
 
@@ -533,7 +541,7 @@ describe Kitchen::Driver::Aws::InstanceGenerator do
533
541
  :device_index => 0,
534
542
  :associate_public_ip_address => true,
535
543
  :delete_on_termination => true,
536
- :private_ip_address => "0.0.0.0"
544
+ :private_ip_address => "0.0.0.0",
537
545
  }]
538
546
  )
539
547
  end
@@ -558,14 +566,14 @@ describe Kitchen::Driver::Aws::InstanceGenerator do
558
566
  :volume_size => 15,
559
567
  :delete_on_termination => false,
560
568
  :volume_type => "gp2",
561
- :snapshot_id => "id"
562
- }
563
- }
569
+ :snapshot_id => "id",
570
+ },
571
+ },
564
572
  ],
565
573
  :security_group_ids => ["sg-789"],
566
574
  :user_data => "foo",
567
575
  :iam_profile_name => "iam-123",
568
- :associate_public_ip => true
576
+ :associate_public_ip => true,
569
577
  }
570
578
  end
571
579
 
@@ -583,9 +591,9 @@ describe Kitchen::Driver::Aws::InstanceGenerator do
583
591
  :volume_size => 15,
584
592
  :delete_on_termination => false,
585
593
  :volume_type => "gp2",
586
- :snapshot_id => "id"
587
- }
588
- }
594
+ :snapshot_id => "id",
595
+ },
596
+ },
589
597
  ],
590
598
  :iam_instance_profile => { :name => "iam-123" },
591
599
  :network_interfaces => [{
@@ -594,7 +602,7 @@ describe Kitchen::Driver::Aws::InstanceGenerator do
594
602
  :subnet_id => "s-456",
595
603
  :delete_on_termination => true,
596
604
  :groups => ["sg-789"],
597
- :private_ip_address => "0.0.0.0"
605
+ :private_ip_address => "0.0.0.0",
598
606
  }],
599
607
  :placement => { :availability_zone => "eu-west-1a" },
600
608
  :user_data => Base64.encode64("foo")
@@ -29,7 +29,7 @@ describe Kitchen::Driver::Ec2 do
29
29
  {
30
30
  :aws_ssh_key_id => "key",
31
31
  :image_id => "ami-1234567",
32
- :block_duration_minutes => 60
32
+ :block_duration_minutes => 60,
33
33
  }
34
34
  end
35
35
  let(:platform) { Kitchen::Platform.new(:name => "fooos-99") }
@@ -79,18 +79,18 @@ describe Kitchen::Driver::Ec2 do
79
79
  allow(instance).to receive(:name).and_return("instance_name")
80
80
  end
81
81
  context "Windows 2016" do
82
- let(:image) {
82
+ let(:image) do
83
83
  FakeImage.new(:name => "Windows_Server-2016-English-Full-Base-2017.01.11")
84
- }
84
+ end
85
85
  it "sets :user_data to something" do
86
86
  expect(driver[:user_data]).to include
87
87
  '$logfile=C:\\ProgramData\\Amazon\\EC2-Windows\\Launch\\Log\\kitchen-ec2.log'
88
88
  end
89
89
  end
90
90
  context "Windows 2012R2" do
91
- let(:image) {
91
+ let(:image) do
92
92
  FakeImage.new(:name => "Windows_Server-2012-R2_RTM-English-64Bit-Base-2017.01.11")
93
- }
93
+ end
94
94
  it "sets :user_data to something" do
95
95
  expect(driver[:user_data]).to include
96
96
  '$logfile=C:\\Program Files\\Amazon\\Ec2ConfigService\\Logs\\kitchen-ec2.log'
@@ -104,14 +104,14 @@ describe Kitchen::Driver::Ec2 do
104
104
  let(:private_dns_name) { nil }
105
105
  let(:public_ip_address) { nil }
106
106
  let(:private_ip_address) { nil }
107
- let(:server) {
107
+ let(:server) do
108
108
  double("server",
109
109
  :public_dns_name => public_dns_name,
110
110
  :private_dns_name => private_dns_name,
111
111
  :public_ip_address => public_ip_address,
112
112
  :private_ip_address => private_ip_address
113
113
  )
114
- }
114
+ end
115
115
 
116
116
  it "returns nil if all sources are nil" do
117
117
  expect(driver.hostname(server)).to eq(nil)
@@ -235,9 +235,9 @@ describe Kitchen::Driver::Ec2 do
235
235
 
236
236
  describe "#submit_spot" do
237
237
  let(:state) { {} }
238
- let(:response) {
238
+ let(:response) do
239
239
  { :spot_instance_requests => [{ :spot_instance_request_id => "id" }] }
240
- }
240
+ end
241
241
 
242
242
  before do
243
243
  expect(driver).to receive(:instance).at_least(:once).and_return(instance)
@@ -265,7 +265,7 @@ describe Kitchen::Driver::Ec2 do
265
265
  expect(server).to receive(:create_tags).with(
266
266
  :tags => [
267
267
  { :key => :key1, :value => :value1 },
268
- { :key => :key2, :value => :value2 }
268
+ { :key => :key2, :value => :value2 },
269
269
  ]
270
270
  )
271
271
  driver.tag_server(server)
@@ -286,7 +286,7 @@ describe Kitchen::Driver::Ec2 do
286
286
  expect(volume).to receive(:create_tags).with(
287
287
  :tags => [
288
288
  { :key => :key1, :value => :value1 },
289
- { :key => :key2, :value => :value2 }
289
+ { :key => :key2, :value => :value2 },
290
290
  ]
291
291
  )
292
292
  driver.tag_volumes(server)
@@ -407,7 +407,7 @@ describe Kitchen::Driver::Ec2 do
407
407
  let(:tries) { 111 }
408
408
  let(:sleep) { 222 }
409
409
  let(:msg) { "msg" }
410
- given_block = lambda do; end
410
+ given_block = lambda { ; }
411
411
 
412
412
  before do
413
413
  config[:retryable_sleep] = sleep
@@ -429,14 +429,14 @@ describe Kitchen::Driver::Ec2 do
429
429
  expect(server).to receive(:wait_until).and_raise(::Aws::Waiters::Errors::WaiterFailed)
430
430
  expect(driver).to receive(:destroy).with(state)
431
431
  expect(driver).to receive(:error).with(/#{msg}/)
432
- expect {
432
+ expect do
433
433
  driver.wait_with_destroy(server, state, msg, &given_block)
434
- }.to raise_error(::Aws::Waiters::Errors::WaiterFailed)
434
+ end.to raise_error(::Aws::Waiters::Errors::WaiterFailed)
435
435
  end
436
436
  end
437
437
 
438
438
  describe "#create" do
439
- let(:server) { double("aws server object", :id => id) }
439
+ let(:server) { double("aws server object", :id => id, :image_id => "ami-3f807145") }
440
440
  let(:id) { "i-12345" }
441
441
 
442
442
  it "returns if the instance is already created" do
@@ -444,6 +444,10 @@ describe Kitchen::Driver::Ec2 do
444
444
  expect(driver.create(state)).to eq(nil)
445
445
  end
446
446
 
447
+ image_data = Aws::EC2::Types::Image.new(:root_device_type => "ebs")
448
+ ec2_stub = Aws::EC2::Types::DescribeImagesResult.new
449
+ ec2_stub.images = [image_data]
450
+
447
451
  shared_examples "common create" do
448
452
  it "successfully creates and tags the instance" do
449
453
  expect(server).to receive(:wait_until_exists)
@@ -452,6 +456,7 @@ describe Kitchen::Driver::Ec2 do
452
456
  expect(driver).to receive(:tag_volumes).with(server)
453
457
  expect(driver).to receive(:wait_until_volumes_ready).with(server, state)
454
458
  expect(driver).to receive(:wait_until_ready).with(server, state)
459
+ allow(actual_client).to receive(:describe_images).with({ :image_ids => [server.image_id] }).and_return(ec2_stub)
455
460
  expect(transport).to receive_message_chain("connection.wait_until_ready")
456
461
  expect(driver).to receive(:create_ec2_json).with(state)
457
462
  driver.create(state)
@@ -459,7 +464,7 @@ describe Kitchen::Driver::Ec2 do
459
464
  end
460
465
  end
461
466
 
462
- context "non-windows on-depand instance" do
467
+ context "non-windows on-demand instance" do
463
468
  before do
464
469
  expect(driver).to receive(:submit_server).and_return(server)
465
470
  end
@@ -476,6 +481,21 @@ describe Kitchen::Driver::Ec2 do
476
481
  include_examples "common create"
477
482
  end
478
483
 
484
+ context "instance is not ebs-backed" do
485
+ before do
486
+ ec2_stub.images[0].root_device_type = "instance-store"
487
+ end
488
+
489
+ it "does not tag volumes or wait for volumes to be ready" do
490
+ expect(driver).to_not receive(:tag_volumes).with(server)
491
+ expect(driver).to_not receive(:wait_until_volumes_ready).with(server, state)
492
+ end
493
+
494
+ after do
495
+ ec2_stub.images[0].root_device_type = "ebs"
496
+ end
497
+ end
498
+
479
499
  context "instance is a windows machine" do
480
500
  before do
481
501
  expect(driver).to receive(:windows_os?).and_return(true)