kitchen-ec2 3.0.1 → 3.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/kitchen/driver/aws/instance_generator.rb +28 -13
- data/lib/kitchen/driver/ec2.rb +63 -11
- data/lib/kitchen/driver/ec2_version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0cbb5b5baa43b4a35611f1fce155cf03e02112a442c9b6a92f76cda3ba429114
|
4
|
+
data.tar.gz: 1e9ebf93508345571c1805727e9bc2f978562e66d54ee1d92574252dc259b180
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3781bd12154cb007e3d4ef735862b6411aad1f0923a994815d308507d765e8924d927a9d520649e7ab5a2c12227fe3ba775e5fdd5b78f2c844d743ec59b8cebc
|
7
|
+
data.tar.gz: 83a7d1855e0f8224f6844aa9fe4cb2342106a7966bf7fbd463606a39b8ae38b3e43e894ee8a2d1a5b35c5507f02055203ed4bdbb74505e2feb2f653a3cb14607
|
@@ -62,22 +62,37 @@ module Kitchen
|
|
62
62
|
end
|
63
63
|
|
64
64
|
if config[:security_group_ids].nil? && config[:security_group_filter]
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
65
|
+
security_groups = []
|
66
|
+
filters = [config[:security_group_filter]].flatten
|
67
|
+
filters.each do |sg_filter|
|
68
|
+
r = {}
|
69
|
+
if sg_filter[:name]
|
70
|
+
r[:filters] = [
|
71
|
+
{
|
72
|
+
name: "group-name",
|
73
|
+
values: [sg_filter[:name]],
|
74
|
+
},
|
72
75
|
]
|
73
|
-
|
76
|
+
end
|
74
77
|
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
78
|
+
if sg_filter[:tag]
|
79
|
+
r[:filters] = [
|
80
|
+
{
|
81
|
+
name: "tag:#{sg_filter[:tag]}",
|
82
|
+
values: [sg_filter[:value]],
|
83
|
+
},
|
84
|
+
]
|
85
|
+
end
|
86
|
+
|
87
|
+
security_group = ::Aws::EC2::Client.new(region: config[:region]).describe_security_groups(r)[0][0]
|
88
|
+
|
89
|
+
if security_group
|
90
|
+
security_groups.push(security_group.group_id)
|
91
|
+
else
|
92
|
+
raise "A Security Group matching the following filter could not be found:\n#{sg_filter}"
|
93
|
+
end
|
80
94
|
end
|
95
|
+
config[:security_group_ids] = security_groups
|
81
96
|
end
|
82
97
|
|
83
98
|
i = {
|
data/lib/kitchen/driver/ec2.rb
CHANGED
@@ -74,6 +74,7 @@ module Kitchen
|
|
74
74
|
default_config :spot_price, nil
|
75
75
|
default_config :block_duration_minutes, nil
|
76
76
|
default_config :retryable_tries, 60
|
77
|
+
default_config :spot_wait, 60
|
77
78
|
default_config :retryable_sleep, 5
|
78
79
|
default_config :aws_access_key_id, nil
|
79
80
|
default_config :aws_secret_access_key, nil
|
@@ -229,18 +230,15 @@ module Kitchen
|
|
229
230
|
|
230
231
|
if config[:spot_price]
|
231
232
|
# Spot instance when a price is set
|
232
|
-
server = with_request_limit_backoff(state) {
|
233
|
+
server = with_request_limit_backoff(state) { submit_spots(state) }
|
233
234
|
else
|
234
235
|
# On-demand instance
|
235
236
|
server = with_request_limit_backoff(state) { submit_server }
|
236
237
|
end
|
237
238
|
info("Instance <#{server.id}> requested.")
|
238
239
|
with_request_limit_backoff(state) do
|
239
|
-
|
240
|
-
|
241
|
-
info("Polling AWS for existence, attempt #{attempts}...")
|
242
|
-
end
|
243
|
-
end
|
240
|
+
logging_proc = ->(attempts) { info("Polling AWS for existence, attempt #{attempts}...") }
|
241
|
+
server.wait_until_exists(before_attempt: logging_proc)
|
244
242
|
end
|
245
243
|
|
246
244
|
# See https://github.com/aws/aws-sdk-ruby/issues/859
|
@@ -407,7 +405,7 @@ module Kitchen
|
|
407
405
|
end
|
408
406
|
|
409
407
|
def instance_generator
|
410
|
-
@instance_generator
|
408
|
+
@instance_generator = Aws::InstanceGenerator.new(config, ec2, instance.logger)
|
411
409
|
end
|
412
410
|
|
413
411
|
# Fog AWS helper for creating the instance
|
@@ -422,6 +420,53 @@ module Kitchen
|
|
422
420
|
ec2.create_instance(instance_data)
|
423
421
|
end
|
424
422
|
|
423
|
+
def config
|
424
|
+
return super unless @config
|
425
|
+
@config
|
426
|
+
end
|
427
|
+
|
428
|
+
# Take one config and expand to multiple configs
|
429
|
+
def expand_config(conf, key)
|
430
|
+
configs = []
|
431
|
+
|
432
|
+
if conf[key] && conf[key].kind_of?(Array)
|
433
|
+
values = conf[key]
|
434
|
+
values.each do |value|
|
435
|
+
new_config = conf.clone
|
436
|
+
new_config[key] = value
|
437
|
+
configs.push new_config
|
438
|
+
end
|
439
|
+
else
|
440
|
+
configs.push conf
|
441
|
+
end
|
442
|
+
|
443
|
+
configs
|
444
|
+
end
|
445
|
+
|
446
|
+
def submit_spots(state)
|
447
|
+
configs = [config]
|
448
|
+
expanded = []
|
449
|
+
keys = [:instance_type, :subnet_id]
|
450
|
+
|
451
|
+
keys.each do |key|
|
452
|
+
configs.each do |conf|
|
453
|
+
expanded.push expand_config(conf, key)
|
454
|
+
end
|
455
|
+
configs = expanded.flatten
|
456
|
+
expanded = []
|
457
|
+
end
|
458
|
+
|
459
|
+
configs.each do |conf|
|
460
|
+
begin
|
461
|
+
@config = conf
|
462
|
+
return submit_spot(state)
|
463
|
+
rescue
|
464
|
+
end
|
465
|
+
end
|
466
|
+
|
467
|
+
raise "Could not create a spot"
|
468
|
+
end
|
469
|
+
|
425
470
|
def submit_spot(state)
|
426
471
|
debug("Creating EC2 Spot Instance..")
|
427
472
|
|
@@ -433,11 +478,11 @@ module Kitchen
|
|
433
478
|
:spot_instance_request_fulfilled,
|
434
479
|
spot_instance_request_ids: [spot_request_id]
|
435
480
|
) do |w|
|
436
|
-
w.max_attempts = config[:
|
481
|
+
w.max_attempts = config[:spot_wait] / config[:retryable_sleep]
|
437
482
|
w.delay = config[:retryable_sleep]
|
438
483
|
w.before_attempt do |attempts|
|
439
484
|
c = attempts * config[:retryable_sleep]
|
440
|
-
t = config[:
|
485
|
+
t = config[:spot_wait]
|
441
486
|
info "Waited #{c}/#{t}s for spot request <#{spot_request_id}> to become fulfilled."
|
442
487
|
end
|
443
488
|
end
|
@@ -445,9 +490,15 @@ module Kitchen
|
|
445
490
|
end
|
446
491
|
|
447
492
|
def create_spot_request
|
448
|
-
request_duration = config[:
|
493
|
+
request_duration = config[:spot_wait]
|
494
|
+
config_spot_price = config[:spot_price].to_s
|
495
|
+
if ["ondemand", "on-demand"].include?(config_spot_price)
|
496
|
+
spot_price = ""
|
497
|
+
else
|
498
|
+
spot_price = config_spot_price
|
499
|
+
end
|
449
500
|
request_data = {
|
450
|
-
spot_price:
|
501
|
+
spot_price: spot_price,
|
451
502
|
launch_specification: instance_generator.ec2_instance_data,
|
452
503
|
valid_until: Time.now + request_duration,
|
453
504
|
}
|
@@ -593,6 +644,7 @@ module Kitchen
|
|
593
644
|
"public" => "public_ip_address",
|
594
645
|
"private" => "private_ip_address",
|
595
646
|
"private_dns" => "private_dns_name",
|
647
|
+
"id" => "id",
|
596
648
|
}.freeze
|
597
649
|
|
598
650
|
#
|
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.0
|
4
|
+
version: 3.1.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-
|
11
|
+
date: 2019-08-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: test-kitchen
|