kitchen-ec2 3.11.0 → 3.13.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 862c1fd03a10f0ad6125f5ea8f5126bf5660e1b7050f9b550001bc7ab9302d91
4
- data.tar.gz: f093d5cf16248830e3ab5aa1567354567bf6568e2a9b8d40d5fe5be4711c915f
3
+ metadata.gz: c5ed0f1bbc994d156a6374c98a1c48f00d2f789f8540b0cb33ae0755996ffca5
4
+ data.tar.gz: 0f5f90acb192d7a649ebd9d7861ed2bfbec2ae1665d32c5e66d75685518b1eff
5
5
  SHA512:
6
- metadata.gz: 3dbea4d3b992f1aebb989f8e894e040ed281d877694474a62afe67ceb4335e18e49463b3039b0c7996ad868f6fda843ff30a625fa92fb479912a4f552b591d23
7
- data.tar.gz: 2367f3182eae5baee7e1b86785961b8f54c0820f9a7bfe35e7e1f8ef3f3731514eb5384166a1229f064df02246208d46950173611537d4868b1ff2883d5577e8
6
+ metadata.gz: 890a0a34755ab636605a8fcfbc45ce8c0f055adb0fa5404c48d516060da3089628091d37bbc9ad555601d742f40647183f2b34988dc703ca03477722b3dfb1bf
7
+ data.tar.gz: 617aaee4fdd8b335e17731621abb9ae140b73286e4da2e77adbb46cdc560789f02eeb85f208217e3ffbd03746c52a46f4ae051d93ab1436fb2fb8f3f2b267351
@@ -47,15 +47,19 @@ module Kitchen
47
47
  vpc_id = nil
48
48
  client = ::Aws::EC2::Client.new(region: config[:region])
49
49
  if config[:subnet_id].nil? && config[:subnet_filter]
50
- subnets = client.describe_subnets(
51
- filters: [
50
+ filters = [config[:subnet_filter]].flatten
51
+
52
+ r = { filters: [] }
53
+ filters.each do |subnet_filter|
54
+ r[:filters] <<
52
55
  {
53
- name: "tag:#{config[:subnet_filter][:tag]}",
54
- values: [config[:subnet_filter][:value]],
55
- },
56
- ]
57
- ).subnets
58
- raise "The subnet tagged '#{config[:subnet_filter][:tag]}:#{config[:subnet_filter][:value]}' does not exist!" unless subnets.any?
56
+ name: "tag:#{subnet_filter[:tag]}",
57
+ values: [subnet_filter[:value]],
58
+ }
59
+ end
60
+
61
+ subnets = client.describe_subnets(r).subnets
62
+ raise "Subnets with tags '#{filters}' not found during security group creation" if subnets.empty?
59
63
 
60
64
  # => Select the least-populated subnet if we have multiple matches
61
65
  subnet = subnets.max_by { |s| s[:available_ip_address_count] }
@@ -149,6 +153,7 @@ module Kitchen
149
153
  i[:block_device_mappings] = config[:block_device_mappings]
150
154
  end
151
155
  i[:security_group_ids] = Array(config[:security_group_ids]) if config[:security_group_ids]
156
+ i[:metadata_options] = config[:metadata_options] if config[:metadata_options]
152
157
  i[:user_data] = prepared_user_data if prepared_user_data
153
158
  if config[:iam_profile_name]
154
159
  i[:iam_instance_profile] = { name: config[:iam_profile_name] }
@@ -251,23 +251,14 @@ module Kitchen
251
251
  wait_until_ready(server, state)
252
252
  end
253
253
 
254
- if windows_os? &&
255
- instance.transport[:username] =~ /administrator/i &&
256
- instance.transport[:password].nil?
257
- # If we're logging into the administrator user and a password isn't
258
- # supplied, try to fetch it from the AWS instance
259
- fetch_windows_admin_password(server, state)
260
- end
261
-
262
254
  info("EC2 instance <#{state[:server_id]}> ready (hostname: #{state[:hostname]}).")
263
255
  instance.transport.connection(state).wait_until_ready
264
256
  attach_network_interface(state) unless config[:elastic_network_interface_id].nil?
265
257
  create_ec2_json(state) if /chef/i.match?(instance.provisioner.name)
266
258
  debug("ec2:create '#{state[:hostname]}'")
267
259
  rescue Exception => e
268
- # Clean up any auto-created security groups or keys on the way out.
269
- delete_security_group(state)
270
- delete_key(state)
260
+ # Clean up the instance and any auto-created security groups or keys on the way out.
261
+ destroy(state)
271
262
  raise "#{e.message} in the specified region #{config[:region]}. Please check this AMI is available in this region."
272
263
  end
273
264
 
@@ -286,13 +277,16 @@ module Kitchen
286
277
  # to wait for the instance to shut down. This slightly breaks the
287
278
  # subsystem encapsulation, sorry not sorry.
288
279
  if state[:auto_security_group_id] && server && ec2.instance_exists?(state[:server_id])
289
- server.wait_until_terminated do |waiter|
290
- waiter.max_attempts = config[:retryable_tries]
291
- waiter.delay = config[:retryable_sleep]
292
- waiter.before_attempt do |attempts|
293
- info "Waited #{attempts * waiter.delay}/#{waiter.delay * waiter.max_attempts}s for instance <#{server.id}> to terminate."
294
- end
280
+ wait_log = proc do |attempts|
281
+ c = attempts * config[:retryable_sleep]
282
+ t = config[:retryable_tries] * config[:retryable_sleep]
283
+ info "Waited #{c}/#{t}s for instance <#{server.id}> to terminate."
295
284
  end
285
+ server.wait_until_terminated(
286
+ max_attempts: config[:retryable_tries],
287
+ delay: config[:retryable_sleep],
288
+ before_attempt: wait_log
289
+ )
296
290
  end
297
291
  info("EC2 instance <#{state[:server_id]}> destroyed.")
298
292
  state.delete(:server_id)
@@ -365,7 +359,7 @@ module Kitchen
365
359
  if actual_platform &&
366
360
  instance.transport[:username] == instance.transport.class.defaults[:username]
367
361
  debug("No SSH username specified: using default username #{actual_platform.username} " \
368
- " for image #{config[:image_id]}, which we detected as #{actual_platform}.")
362
+ "for image #{config[:image_id]}, which we detected as #{actual_platform}.")
369
363
  state[:username] = actual_platform.username
370
364
  end
371
365
  end
@@ -430,15 +424,21 @@ module Kitchen
430
424
  else
431
425
  # => Enable cascading through matching subnets
432
426
  client = ::Aws::EC2::Client.new(region: config[:region])
433
- subnets = client.describe_subnets(
434
- filters: [
427
+
428
+ filters = [config[:subnet_filter]].flatten
429
+
430
+ r = { filters: [] }
431
+ filters.each do |subnet_filter|
432
+ r[:filters] <<
435
433
  {
436
- name: "tag:#{config[:subnet_filter][:tag]}",
437
- values: [config[:subnet_filter][:value]],
438
- },
439
- ]
440
- ).subnets
441
- raise "A subnet matching '#{config[:subnet_filter][:tag]}:#{config[:subnet_filter][:value]}' does not exist!" unless subnets.any?
434
+ name: "tag:#{subnet_filter[:tag]}",
435
+ values: [subnet_filter[:value]],
436
+ }
437
+ end
438
+
439
+ subnets = client.describe_subnets(r).subnets
440
+
441
+ raise "Subnets with tags '#{filters}' not found!" if subnets.empty?
442
442
 
443
443
  configs = subnets.map do |subnet|
444
444
  new_config = config.clone
@@ -528,12 +528,19 @@ module Kitchen
528
528
  state[:hostname] = hostname(aws_instance, nil)
529
529
  end
530
530
  if ready && windows_os?
531
- output = server.console_output.output
532
- unless output.nil?
533
- output = Base64.decode64(output)
534
- debug "Console output: --- \n#{output}"
531
+ if instance.transport[:username] =~ /administrator/i &&
532
+ instance.transport[:password].nil?
533
+ # If we're logging into the administrator user and a password isn't
534
+ # supplied, try to fetch it from the AWS instance
535
+ fetch_windows_admin_password(server, state)
536
+ else
537
+ output = server.console_output.output
538
+ unless output.nil?
539
+ output = Base64.decode64(output)
540
+ debug "Console output: --- \n#{output}"
541
+ end
542
+ ready = !!(output =~ /Windows is Ready to use/)
535
543
  end
536
- ready = !!(output =~ /Windows is Ready to use/)
537
544
  end
538
545
  ready
539
546
  end
@@ -748,8 +755,19 @@ module Kitchen
748
755
 
749
756
  subnets.first.vpc_id
750
757
  elsif config[:subnet_filter]
751
- subnets = ec2.client.describe_subnets(filters: [{ name: "tag:#{config[:subnet_filter][:tag]}", values: [config[:subnet_filter][:value]] }]).subnets
752
- raise "Subnets with tag '#{config[:subnet_filter][:tag]}=#{config[:subnet_filter][:value]}' not found during security group creation" if subnets.empty?
758
+ filters = [config[:subnet_filter]].flatten
759
+
760
+ r = { filters: [] }
761
+ filters.each do |subnet_filter|
762
+ r[:filters] << {
763
+ name: "tag:#{subnet_filter[:tag]}",
764
+ values: [subnet_filter[:value]],
765
+ }
766
+ end
767
+
768
+ subnets = ec2.client.describe_subnets(r).subnets
769
+
770
+ raise "Subnets with tags '#{filters}' not found during security group creation" if subnets.empty?
753
771
 
754
772
  subnets.first.vpc_id
755
773
  else
@@ -21,6 +21,6 @@ module Kitchen
21
21
  module Driver
22
22
 
23
23
  # Version string for EC2 Test Kitchen driver
24
- EC2_VERSION = "3.11.0".freeze
24
+ EC2_VERSION = "3.13.0".freeze
25
25
  end
26
26
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kitchen-ec2
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.11.0
4
+ version: 3.13.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Fletcher Nichol
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-11-02 00:00:00.000000000 Z
11
+ date: 2022-05-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: test-kitchen
@@ -105,7 +105,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
105
105
  - !ruby/object:Gem::Version
106
106
  version: '0'
107
107
  requirements: []
108
- rubygems_version: 3.2.22
108
+ rubygems_version: 3.2.3
109
109
  signing_key:
110
110
  specification_version: 4
111
111
  summary: A Test Kitchen Driver for Amazon EC2