kitchen-ec2 3.1.0 → 3.2.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: 0cbb5b5baa43b4a35611f1fce155cf03e02112a442c9b6a92f76cda3ba429114
4
- data.tar.gz: 1e9ebf93508345571c1805727e9bc2f978562e66d54ee1d92574252dc259b180
3
+ metadata.gz: 828a479cf1ebe8de5423fad1926bc74f1cb66ddc1a1b4f853977424e65dd4709
4
+ data.tar.gz: 67851982c4d376be9ca701040e38d8e7b5cb308a7cf52cd0056da8f898558dcd
5
5
  SHA512:
6
- metadata.gz: 3781bd12154cb007e3d4ef735862b6411aad1f0923a994815d308507d765e8924d927a9d520649e7ab5a2c12227fe3ba775e5fdd5b78f2c844d743ec59b8cebc
7
- data.tar.gz: 83a7d1855e0f8224f6844aa9fe4cb2342106a7966bf7fbd463606a39b8ae38b3e43e894ee8a2d1a5b35c5507f02055203ed4bdbb74505e2feb2f653a3cb14607
6
+ metadata.gz: 1165fa8225401552970c19983091d8cb38f234a08f9f84a68ebb45cdf05b5670271e92b780b9e8fa0fdecc1c18083e3702f3ddace3561a76628226d09f67ce26
7
+ data.tar.gz: abe70ab29dacefda005ec11ffa0710841532e7f8407c203daf6bd782acb1c1da59d95c1c188bfca81cc20bd010d2ce7df5c6e78371eff0960f46dcbf3c885245
@@ -127,7 +127,7 @@ module Kitchen
127
127
  if config[:iam_profile_name]
128
128
  i[:iam_instance_profile] = { name: config[:iam_profile_name] }
129
129
  end
130
- if !config.fetch(:associate_public_ip, nil).nil?
130
+ unless config.fetch(:associate_public_ip, nil).nil?
131
131
  i[:network_interfaces] =
132
132
  [{
133
133
  device_index: 0,
@@ -27,6 +27,7 @@ module Kitchen
27
27
  # Centos 6.x images use root as the username (but the "centos 6"
28
28
  # updateable image uses "centos")
29
29
  return "root" if version && version.start_with?("6.")
30
+
30
31
  "centos"
31
32
  end
32
33
 
@@ -27,8 +27,7 @@ module Kitchen
27
27
  "ec2-user"
28
28
  end
29
29
 
30
- def sudo_command
31
- end
30
+ def sudo_command; end
32
31
 
33
32
  def image_search
34
33
  search = {
@@ -47,6 +47,8 @@ module Kitchen
47
47
  # Windows_Server-2012-R2_RTM-
48
48
  # "windows-2016" -> [2016, 0, nil]
49
49
  # Windows_Server-2016-
50
+ # "windows-2019" -> [2019, 0, nil]
51
+ # Windows_Server-2019-
50
52
  def image_search
51
53
  search = {
52
54
  "owner-alias" => "amazon",
@@ -94,6 +96,7 @@ module Kitchen
94
96
  # 2012sp4 -> [ 2012, 0, 4 ]
95
97
  # 2012rtm -> [ 2012, 0, 0 ]
96
98
  # 2016 -> [ 2016, 0, nil ]
99
+ # 2019 -> [ 2019, 0, nil ]
97
100
  # 1709 -> [ 1709, 0, nil ]
98
101
  # 1803 -> [ 1803, 0, nil ]
99
102
  def windows_version_parts
@@ -129,9 +132,8 @@ module Kitchen
129
132
 
130
133
  def windows_name_filter # rubocop:disable Metrics/MethodLength
131
134
  major, revision, service_pack = windows_version_parts
132
-
133
- if major == 2016
134
- "Windows_Server-2016-English-Full-Base-*"
135
+ if major == 2019 || major == 2016
136
+ "Windows_Server-#{major}-English-Full-Base-*"
135
137
  elsif major == 1709 || major == 1803
136
138
  "Windows_Server-#{major}-English-Core-ContainersLatest-*"
137
139
  else
@@ -56,9 +56,7 @@ module Kitchen
56
56
  default_config :region, ENV["AWS_REGION"] || "us-east-1"
57
57
  default_config :shared_credentials_profile, ENV["AWS_PROFILE"]
58
58
  default_config :availability_zone, nil
59
- default_config :instance_type do |driver|
60
- driver.default_instance_type
61
- end
59
+ default_config :instance_type, &:default_instance_type
62
60
  default_config :ebs_optimized, false
63
61
  default_config :security_group_ids, nil
64
62
  default_config :security_group_filter, nil
@@ -80,9 +78,7 @@ module Kitchen
80
78
  default_config :aws_secret_access_key, nil
81
79
  default_config :aws_session_token, nil
82
80
  default_config :aws_ssh_key_id, ENV["AWS_SSH_KEY_ID"]
83
- default_config :image_id do |driver|
84
- driver.default_ami
85
- end
81
+ default_config :image_id, &:default_ami
86
82
  default_config :image_search, nil
87
83
  default_config :username, nil
88
84
  default_config :associate_public_ip, nil
@@ -110,7 +106,7 @@ module Kitchen
110
106
  end
111
107
 
112
108
  # TODO: remove these in 1.1
113
- deprecated_configs = [:ebs_volume_size, :ebs_delete_on_termination, :ebs_device_name]
109
+ deprecated_configs = %i{ebs_volume_size ebs_delete_on_termination ebs_device_name}
114
110
  deprecated_configs.each do |d|
115
111
  validations[d] = lambda do |attr, val, driver|
116
112
  unless val.nil?
@@ -200,6 +196,7 @@ module Kitchen
200
196
 
201
197
  def create(state)
202
198
  return if state[:server_id]
199
+
203
200
  update_username(state)
204
201
 
205
202
  info(Kitchen::Util.outdent!(<<-END)) unless config[:skip_cost_warning]
@@ -422,6 +419,7 @@ module Kitchen
422
419
 
423
420
  def config
424
421
  return super unless @config
422
+
425
423
  @config
426
424
  end
427
425
 
@@ -429,7 +427,7 @@ module Kitchen
429
427
  def expand_config(conf, key)
430
428
  configs = []
431
429
 
432
- if conf[key] && conf[key].kind_of?(Array)
430
+ if conf[key] && conf[key].is_a?(Array)
433
431
  values = conf[key]
434
432
  values.each do |value|
435
433
  new_config = conf.clone
@@ -446,7 +444,7 @@ module Kitchen
446
444
  def submit_spots(state)
447
445
  configs = [config]
448
446
  expanded = []
449
- keys = [:instance_type, :subnet_id]
447
+ keys = %i{instance_type subnet_id}
450
448
 
451
449
  keys.each do |key|
452
450
  configs.each do |conf|
@@ -492,7 +490,7 @@ module Kitchen
492
490
  def create_spot_request
493
491
  request_duration = config[:spot_wait]
494
492
  config_spot_price = config[:spot_price].to_s
495
- if ["ondemand", "on-demand"].include?(config_spot_price)
493
+ if %w{ondemand on-demand}.include?(config_spot_price)
496
494
  spot_price = ""
497
495
  else
498
496
  spot_price = config_spot_price
@@ -543,8 +541,7 @@ module Kitchen
543
541
  ready_volume_count = 0
544
542
  if aws_instance.exists?
545
543
  described_volume_count = ec2.client.describe_volumes(filters: [
546
- { name: "attachment.instance-id", values: ["#{state[:server_id]}"] }]
547
- ).volumes.length
544
+ { name: "attachment.instance-id", values: ["#{state[:server_id]}"] }]).volumes.length
548
545
  aws_instance.volumes.each { ready_volume_count += 1 }
549
546
  end
550
547
  (described_volume_count > 0) && (described_volume_count == ready_volume_count)
@@ -626,6 +623,7 @@ module Kitchen
626
623
  yield
627
624
  rescue ::Aws::EC2::Errors::RequestLimitExceeded, ::Aws::Waiters::Errors::UnexpectedError => e
628
625
  raise unless retries < 5 && e.message.include?("Request limit exceeded")
626
+
629
627
  retries += 1
630
628
  info("Request limit exceeded for instance <#{state[:server_id]}>." \
631
629
  " Trying again in #{retries**2} seconds.")
@@ -689,7 +687,7 @@ module Kitchen
689
687
  def default_windows_user_data
690
688
  base_script = Kitchen::Util.outdent!(<<-EOH)
691
689
  $OSVersion = (get-itemproperty -Path "HKLM:\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion" -Name ProductName).ProductName
692
- If($OSVersion.contains('2016') -Or $OSVersion -eq 'Windows Server Datacenter') {
690
+ If($OSVersion.contains('2016') -Or $OSVersion.contains('2019') -Or $OSVersion -eq 'Windows Server Datacenter') {
693
691
  New-Item -ItemType Directory -Force -Path 'C:\\ProgramData\\Amazon\\EC2-Windows\\Launch\\Log'
694
692
  $logfile='C:\\ProgramData\\Amazon\\EC2-Windows\\Launch\\Log\\kitchen-ec2.log'
695
693
  # EC2Launch doesn't init extra disks by default
@@ -779,11 +777,17 @@ module Kitchen
779
777
  # @return [void]
780
778
  def create_security_group(state)
781
779
  return if state[:auto_security_group_id]
780
+
782
781
  # Work out which VPC, if any, we are creating in.
783
782
  vpc_id = if config[:subnet_id]
784
783
  # Get the VPC ID for the subnet.
785
784
  subnets = ec2.client.describe_subnets(filters: [{ name: "subnet-id", values: [config[:subnet_id]] }]).subnets
786
785
  raise "Subnet #{config[:subnet_id]} not found during security group creation" if subnets.empty?
786
+
787
+ subnets.first.vpc_id
788
+ elsif config[:subnet_filter]
789
+ subnets = ec2.client.describe_subnets(filters: [{ name: "tag:#{config[:subnet_filter][:tag]}", values: [config[:subnet_filter][:value]] }]).subnets
790
+ raise "Subnets with tag '#{config[:subnet_filter][:tag]}=#{config[:subnet_filter][:value]}' not found during security group creation" if subnets.empty?
787
791
  subnets.first.vpc_id
788
792
  else
789
793
  # Try to check for a default VPC.
@@ -799,13 +803,13 @@ module Kitchen
799
803
  # Create the SG.
800
804
  params = {
801
805
  group_name: "kitchen-#{Array.new(8) { rand(36).to_s(36) }.join}",
802
- description: "Test Kitchen for #{instance.name} by #{Etc.getlogin || 'nologin'} on #{Socket.gethostname}",
806
+ description: "Test Kitchen for #{instance.name} by #{Etc.getlogin || "nologin"} on #{Socket.gethostname}",
803
807
  }
804
808
  params[:vpc_id] = vpc_id if vpc_id
805
809
  resp = ec2.client.create_security_group(params)
806
810
  state[:auto_security_group_id] = resp.group_id
807
811
  info("Created automatic security group #{state[:auto_security_group_id]}")
808
- debug(" in VPC #{vpc_id || 'none'}")
812
+ debug(" in VPC #{vpc_id || "none"}")
809
813
  # Set up SG rules.
810
814
  ec2.client.authorize_security_group_ingress(
811
815
  group_id: state[:auto_security_group_id],
@@ -828,6 +832,7 @@ module Kitchen
828
832
  # @return [void]
829
833
  def create_key(state)
830
834
  return if state[:auto_key_id]
835
+
831
836
  # Encode a bunch of metadata into the name because that's all we can
832
837
  # set for a key pair.
833
838
  name_parts = [
@@ -842,7 +847,7 @@ module Kitchen
842
847
  # to rapidly exhaust local entropy by creating a lot of keys. So this is
843
848
  # probably fine. If you want very high security, probably don't use this
844
849
  # feature anyway.
845
- resp = ec2.client.create_key_pair(key_name: "kitchen-#{name_parts.join('-')}")
850
+ resp = ec2.client.create_key_pair(key_name: "kitchen-#{name_parts.join("-")}")
846
851
  state[:auto_key_id] = resp.key_name
847
852
  info("Created automatic key pair #{state[:auto_key_id]}")
848
853
  # Write the key out with safe permissions
@@ -862,6 +867,7 @@ module Kitchen
862
867
  # @return [void]
863
868
  def delete_security_group(state)
864
869
  return unless state[:auto_security_group_id]
870
+
865
871
  info("Removing automatic security group #{state[:auto_security_group_id]}")
866
872
  ec2.client.delete_security_group(group_id: state[:auto_security_group_id])
867
873
  state.delete(:auto_security_group_id)
@@ -874,6 +880,7 @@ module Kitchen
874
880
  # @return [void]
875
881
  def delete_key(state)
876
882
  return unless state[:auto_key_id]
883
+
877
884
  info("Removing automatic key pair #{state[:auto_key_id]}")
878
885
  ec2.client.delete_key_pair(key_name: state[:auto_key_id])
879
886
  state.delete(:auto_key_id)
@@ -22,6 +22,6 @@ module Kitchen
22
22
  module Driver
23
23
 
24
24
  # Version string for EC2 Test Kitchen driver
25
- EC2_VERSION = "3.1.0".freeze
25
+ EC2_VERSION = "3.2.0".freeze
26
26
  end
27
27
  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.1.0
4
+ version: 3.2.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: 2019-08-08 00:00:00.000000000 Z
11
+ date: 2019-09-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: test-kitchen
@@ -76,16 +76,22 @@ dependencies:
76
76
  name: retryable
77
77
  requirement: !ruby/object:Gem::Requirement
78
78
  requirements:
79
- - - "~>"
79
+ - - ">="
80
80
  - !ruby/object:Gem::Version
81
81
  version: '2.0'
82
+ - - "<"
83
+ - !ruby/object:Gem::Version
84
+ version: '4.0'
82
85
  type: :runtime
83
86
  prerelease: false
84
87
  version_requirements: !ruby/object:Gem::Requirement
85
88
  requirements:
86
- - - "~>"
89
+ - - ">="
87
90
  - !ruby/object:Gem::Version
88
91
  version: '2.0'
92
+ - - "<"
93
+ - !ruby/object:Gem::Version
94
+ version: '4.0'
89
95
  - !ruby/object:Gem::Dependency
90
96
  name: rspec
91
97
  requirement: !ruby/object:Gem::Requirement
@@ -162,14 +168,14 @@ dependencies:
162
168
  requirements:
163
169
  - - '='
164
170
  - !ruby/object:Gem::Version
165
- version: 0.6.0
171
+ version: 0.13.3
166
172
  type: :development
167
173
  prerelease: false
168
174
  version_requirements: !ruby/object:Gem::Requirement
169
175
  requirements:
170
176
  - - '='
171
177
  - !ruby/object:Gem::Version
172
- version: 0.6.0
178
+ version: 0.13.3
173
179
  - !ruby/object:Gem::Dependency
174
180
  name: climate_control
175
181
  requirement: !ruby/object:Gem::Requirement