kitchen-ec2 3.9.0 → 3.11.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: aac8aebec145ee67e00276453fd2f8a1aaae0466d58bec03ffdc8b368f001118
4
- data.tar.gz: f14c9b4f85a0ebd1bf5c6398efc54b93e195e465ef4fc1c944688f96f53f1d39
3
+ metadata.gz: 8db131041ca62ab75984ff3a397e349838a750a6041bb4e57467e6bd74918b3f
4
+ data.tar.gz: 171e39a4ff4eafb0bdf80789c517813360c8438e992329c76562815d3cf31719
5
5
  SHA512:
6
- metadata.gz: d1e8f020cde0872c27abade96517dae1dcafa5d50aa4b08245ec928adfc024e309cc1977e5bdaebb30f3dfcea1f463ee01dabfe62baf4a0640b8bce527aa80b4
7
- data.tar.gz: 958a08022889c1bef5e0becc8cd75d53b5a0cd68445043c0c934bdc9a03822afcd9cc6f6dc49f15fe63928933f61f6d383d3b3bd3b7ad278d851f2c4957726a1
6
+ metadata.gz: ed0a53d4b538412b96dbf872bf7a1dbebd0c64a65ed0620d506164296aade28893d410fb508a7073fa7a9ce7829f0a26afc88ecae1aecd2f972e3cea21bcaff6
7
+ data.tar.gz: 0de4ad1727d5c286ae3d1fabc39d49b61b186dfbccfd6ba9e0275f85d3db00d9ccbf71ed1cfb10c4dd821b027836d6b3dcf3c2a0d7e75be895b21c9dd216b35d
@@ -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
@@ -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-*"
@@ -261,13 +261,14 @@ module Kitchen
261
261
 
262
262
  info("EC2 instance <#{state[:server_id]}> ready (hostname: #{state[:hostname]}).")
263
263
  instance.transport.connection(state).wait_until_ready
264
+ attach_network_interface(state) unless config[:elastic_network_interface_id].nil?
264
265
  create_ec2_json(state) if /chef/i.match?(instance.provisioner.name)
265
266
  debug("ec2:create '#{state[:hostname]}'")
266
- rescue Exception
267
+ rescue Exception => e
267
268
  # Clean up any auto-created security groups or keys on the way out.
268
269
  delete_security_group(state)
269
270
  delete_key(state)
270
- raise
271
+ raise "#{e.message} in the specified region #{config[:region]}. Please check this AMI is available in this region."
271
272
  end
272
273
 
273
274
  def destroy(state)
@@ -284,14 +285,17 @@ module Kitchen
284
285
  # If we are going to clean up an automatic security group, we need
285
286
  # to wait for the instance to shut down. This slightly breaks the
286
287
  # subsystem encapsulation, sorry not sorry.
287
- if state[:auto_security_group_id] && server
288
- server.wait_until_terminated do |waiter|
289
- waiter.max_attempts = config[:retryable_tries]
290
- waiter.delay = config[:retryable_sleep]
291
- waiter.before_attempt do |attempts|
292
- info "Waited #{attempts * waiter.delay}/#{waiter.delay * waiter.max_attempts}s for instance <#{server.id}> to terminate."
293
- end
288
+ if state[:auto_security_group_id] && server && ec2.instance_exists?(state[:server_id])
289
+ wait_log = proc do |attempts|
290
+ c = attempts * config[:retryable_sleep]
291
+ t = config[:retryable_tries] * config[:retryable_sleep]
292
+ info "Waited #{c}/#{t}s for instance <#{server.id}> to terminate."
294
293
  end
294
+ server.wait_until_terminated(
295
+ max_attempts: config[:retryable_tries],
296
+ delay: config[:retryable_sleep],
297
+ before_attempt: wait_log
298
+ )
295
299
  end
296
300
  info("EC2 instance <#{state[:server_id]}> destroyed.")
297
301
  state.delete(:server_id)
@@ -364,7 +368,7 @@ module Kitchen
364
368
  if actual_platform &&
365
369
  instance.transport[:username] == instance.transport.class.defaults[:username]
366
370
  debug("No SSH username specified: using default username #{actual_platform.username} " \
367
- " for image #{config[:image_id]}, which we detected as #{actual_platform}.")
371
+ "for image #{config[:image_id]}, which we detected as #{actual_platform}.")
368
372
  state[:username] = actual_platform.username
369
373
  end
370
374
  end
@@ -824,6 +828,31 @@ module Kitchen
824
828
  state[:ssh_key] = key_path
825
829
  end
826
830
 
831
+ def attach_network_interface(state)
832
+ info("Attaching Network interface <#{config[:elastic_network_interface_id]}> with the instance <#{state[:server_id]}> .")
833
+ client = ::Aws::EC2::Client.new(region: config[:region])
834
+ begin
835
+ check_eni = client.describe_network_interface_attribute({
836
+ attribute: "attachment",
837
+ network_interface_id: config[:elastic_network_interface_id],
838
+ })
839
+ if check_eni.attachment.nil?
840
+ unless state[:server_id].nil?
841
+ client.attach_network_interface({
842
+ device_index: 1,
843
+ instance_id: state[:server_id],
844
+ network_interface_id: config[:elastic_network_interface_id],
845
+ })
846
+ info("Attached Network interface <#{config[:elastic_network_interface_id]}> with the instance <#{state[:server_id]}> .")
847
+ end
848
+ else
849
+ puts "ENI #{config[:elastic_network_interface_id]} already attached."
850
+ end
851
+ rescue ::Aws::EC2::Errors::InvalidNetworkInterfaceIDNotFound => e
852
+ warn("#{e}")
853
+ end
854
+ end
855
+
827
856
  # Clean up a temporary security group for this instance.
828
857
  #
829
858
  # @api private
@@ -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.9.0".freeze
24
+ EC2_VERSION = "3.11.1".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.9.0
4
+ version: 3.11.1
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-04-10 00:00:00.000000000 Z
11
+ date: 2021-11-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: test-kitchen
@@ -19,7 +19,7 @@ dependencies:
19
19
  version: 1.4.1
20
20
  - - "<"
21
21
  - !ruby/object:Gem::Version
22
- version: '3'
22
+ version: '4'
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
@@ -29,7 +29,7 @@ dependencies:
29
29
  version: 1.4.1
30
30
  - - "<"
31
31
  - !ruby/object:Gem::Version
32
- version: '3'
32
+ version: '4'
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: aws-sdk-ec2
35
35
  requirement: !ruby/object:Gem::Requirement
@@ -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.22
109
109
  signing_key:
110
110
  specification_version: 4
111
111
  summary: A Test Kitchen Driver for Amazon EC2