kitchen-ec2 3.10.0 → 3.12.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: b5acaa7d4d497244e97e35e4d8c44f1b0a8771100dfb0ef01cae937a7904a853
4
- data.tar.gz: 92a4bb2ffeb6c84295fc6432e0c0852e63e11f1a4cbea7ae4fad54888ad9869e
3
+ metadata.gz: f76f759771ac4c8597dacffcf992e7d33fe1784c61be5ae6c84f00c77633b141
4
+ data.tar.gz: 324f1dd4944162dcd51bd6569dbfbabe9701ec58f6c1f8bf02ff96811bf48c65
5
5
  SHA512:
6
- metadata.gz: fb7fc3f4d93a893455e274f0744c510526a79c2bd997bf6ef712f9e7774ab13a077b2c038402d7c41eaf8610f7b0bff9abeddddc5633b36c2e1142bfe72c4779
7
- data.tar.gz: 44f07e5fb729c8fd106e3df0030a7d267322ebd80220f19f115e2f8addc6148a1ebd5c2da05bb4e5f84867c74b1889a4131881183f8f89ed5f67bde776e7ac7d
6
+ metadata.gz: 48c946144405da7ec33817582d1115ac68dc76486307d86b8d7519a238d0aa0637d03152a0aad3b96fdfad25955e40eb96c513c862f7794f1ec4aeca3d029558
7
+ data.tar.gz: 136f94bcf170b07848f8bd7dd56d2918e38482003ece6d0da4029790651e60c1cd25ddd0e13749e6d90efdf6f6cf346f9d6d2eba17c45067db04ac8e4662558d
@@ -75,6 +75,13 @@ module Kitchen
75
75
  ).to_a[0]
76
76
  end
77
77
 
78
+ # check if instance exists, given an id
79
+ # @param id [String] aws instance id
80
+ # @return boolean
81
+ def instance_exists?(id)
82
+ resource.instance(id).exists?
83
+ end
84
+
78
85
  def client
79
86
  @client ||= ::Aws::EC2::Client.new
80
87
  end
@@ -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] }
@@ -23,16 +23,17 @@ module Kitchen
23
23
  class Debian < StandardPlatform
24
24
  StandardPlatform.platforms["debian"] = self
25
25
 
26
- # 11/12 are listed last since we default to the first item in the hash
27
- # and 11/12 are not released yet. When they're released move them up
26
+ # 12/13 are listed last since we default to the first item in the hash
27
+ # and 12/13 are not released yet. When they're released move them up
28
28
  DEBIAN_CODENAMES = {
29
+ 11 => "bullseye",
29
30
  10 => "buster",
30
31
  9 => "stretch",
31
32
  8 => "jessie",
32
33
  7 => "wheezy",
33
34
  6 => "squeeze",
34
- 11 => "bullseye",
35
35
  12 => "bookworm",
36
+ 13 => "trixie",
36
37
  }.freeze
37
38
 
38
39
  # default username for this platform's ami
@@ -51,11 +52,23 @@ module Kitchen
51
52
  end
52
53
 
53
54
  def image_search
54
- search = {
55
- "owner-id" => "379101102735",
56
- "name" => "debian-#{codename}-*",
57
- }
55
+ search = {}
56
+
57
+ # The Debian AWS owner ID changed for releases 10 and onwards
58
+ # See https://wiki.debian.org/Amazon/EC2/HowTo/awscli
59
+ if version.nil?
60
+ search["owner-id"] = "136693071363"
61
+ search["name"] = "debian-#{DEBIAN_CODENAMES.keys.first}-*"
62
+ elsif version.to_i >= 10
63
+ search["owner-id"] = "136693071363"
64
+ search["name"] = "debian-#{version.to_i}-*"
65
+ else
66
+ search["owner-id"] = "379101102735"
67
+ search["name"] = "debian-#{codename}-*"
68
+ end
69
+
58
70
  search["architecture"] = architecture if architecture
71
+
59
72
  search
60
73
  end
61
74
 
@@ -134,7 +134,7 @@ module Kitchen
134
134
 
135
135
  def windows_name_filter # rubocop:disable Metrics/MethodLength
136
136
  major, revision, service_pack = windows_version_parts
137
- if major == 2019 || major == 2016
137
+ if major == 2022 || major == 2019 || major == 2016
138
138
  "Windows_Server-#{major}-English-Full-Base-*"
139
139
  elsif major == 1709 || major == 1803
140
140
  "Windows_Server-#{major}-English-Core-ContainersLatest-*"
@@ -265,9 +265,8 @@ module Kitchen
265
265
  create_ec2_json(state) if /chef/i.match?(instance.provisioner.name)
266
266
  debug("ec2:create '#{state[:hostname]}'")
267
267
  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)
268
+ # Clean up the instance and any auto-created security groups or keys on the way out.
269
+ destroy(state)
271
270
  raise "#{e.message} in the specified region #{config[:region]}. Please check this AMI is available in this region."
272
271
  end
273
272
 
@@ -285,14 +284,17 @@ module Kitchen
285
284
  # If we are going to clean up an automatic security group, we need
286
285
  # to wait for the instance to shut down. This slightly breaks the
287
286
  # subsystem encapsulation, sorry not sorry.
288
- if state[:auto_security_group_id] && server
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
287
+ if state[:auto_security_group_id] && server && ec2.instance_exists?(state[:server_id])
288
+ wait_log = proc do |attempts|
289
+ c = attempts * config[:retryable_sleep]
290
+ t = config[:retryable_tries] * config[:retryable_sleep]
291
+ info "Waited #{c}/#{t}s for instance <#{server.id}> to terminate."
295
292
  end
293
+ server.wait_until_terminated(
294
+ max_attempts: config[:retryable_tries],
295
+ delay: config[:retryable_sleep],
296
+ before_attempt: wait_log
297
+ )
296
298
  end
297
299
  info("EC2 instance <#{state[:server_id]}> destroyed.")
298
300
  state.delete(:server_id)
@@ -365,7 +367,7 @@ module Kitchen
365
367
  if actual_platform &&
366
368
  instance.transport[:username] == instance.transport.class.defaults[:username]
367
369
  debug("No SSH username specified: using default username #{actual_platform.username} " \
368
- " for image #{config[:image_id]}, which we detected as #{actual_platform}.")
370
+ "for image #{config[:image_id]}, which we detected as #{actual_platform}.")
369
371
  state[:username] = actual_platform.username
370
372
  end
371
373
  end
@@ -430,15 +432,21 @@ module Kitchen
430
432
  else
431
433
  # => Enable cascading through matching subnets
432
434
  client = ::Aws::EC2::Client.new(region: config[:region])
433
- subnets = client.describe_subnets(
434
- filters: [
435
+
436
+ filters = [config[:subnet_filter]].flatten
437
+
438
+ r = { filters: [] }
439
+ filters.each do |subnet_filter|
440
+ r[:filters] <<
435
441
  {
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?
442
+ name: "tag:#{subnet_filter[:tag]}",
443
+ values: [subnet_filter[:value]],
444
+ }
445
+ end
446
+
447
+ subnets = client.describe_subnets(r).subnets
448
+
449
+ raise "Subnets with tags '#{filters}' not found!" if subnets.empty?
442
450
 
443
451
  configs = subnets.map do |subnet|
444
452
  new_config = config.clone
@@ -748,8 +756,19 @@ module Kitchen
748
756
 
749
757
  subnets.first.vpc_id
750
758
  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?
759
+ filters = [config[:subnet_filter]].flatten
760
+
761
+ r = { filters: [] }
762
+ filters.each do |subnet_filter|
763
+ r[:filters] << {
764
+ name: "tag:#{subnet_filter[:tag]}",
765
+ values: [subnet_filter[:value]],
766
+ }
767
+ end
768
+
769
+ subnets = ec2.client.describe_subnets(r).subnets
770
+
771
+ raise "Subnets with tags '#{filters}' not found during security group creation" if subnets.empty?
753
772
 
754
773
  subnets.first.vpc_id
755
774
  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.10.0".freeze
24
+ EC2_VERSION = "3.12.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.10.0
4
+ version: 3.12.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-07-02 00:00:00.000000000 Z
11
+ date: 2021-12-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: test-kitchen
@@ -98,14 +98,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
98
98
  requirements:
99
99
  - - ">="
100
100
  - !ruby/object:Gem::Version
101
- version: '2.5'
101
+ version: '2.6'
102
102
  required_rubygems_version: !ruby/object:Gem::Requirement
103
103
  requirements:
104
104
  - - ">="
105
105
  - !ruby/object:Gem::Version
106
106
  version: '0'
107
107
  requirements: []
108
- rubygems_version: 3.2.15
108
+ rubygems_version: 3.2.32
109
109
  signing_key:
110
110
  specification_version: 4
111
111
  summary: A Test Kitchen Driver for Amazon EC2