convection 0.2.26 → 0.2.27
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 +4 -4
- data/.rubocop_todo.yml +4 -0
- data/example/sqs-queue/Cloudfile +19 -0
- data/example/sqs-queue/README.md +12 -0
- data/lib/convection/control/stack.rb +20 -3
- data/test/convection/tasks/test_after_update_tasks.rb +71 -0
- data/test/convection/tasks/test_before_update_tasks.rb +71 -0
- data/test/test_helper.rb +8 -0
- metadata +8 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 50c21a69cf59ef819ba20bcd4336ef17454a9e38
|
4
|
+
data.tar.gz: 805db980ac9b3ad1912d675cee95eff3943bed9d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6189728b8e296fbc1d06db5551021a416ee3581dc2c7a5e0ea3105849e874f1ebd95627e373c4e29277269bdcca8fda8531c070011eec3a6346789b72f0e1023
|
7
|
+
data.tar.gz: 81311736cfd06d59aef0d0d424b3242b914e392522a014319e89152a51bb185ac3e7aa63e5577adcaa77563a50f4cc2ca6561de8984d5cb7350a8f04f9e2d58d
|
data/.rubocop_todo.yml
CHANGED
@@ -23,6 +23,8 @@ Metrics/AbcSize:
|
|
23
23
|
# Offense count: 3
|
24
24
|
# Configuration parameters: CountComments.
|
25
25
|
Metrics/ClassLength:
|
26
|
+
Exclude:
|
27
|
+
- 'lib/convection/control/stack.rb'
|
26
28
|
Max: 304
|
27
29
|
|
28
30
|
# Offense count: 6
|
@@ -38,6 +40,8 @@ Metrics/LineLength:
|
|
38
40
|
# Offense count: 32
|
39
41
|
# Configuration parameters: CountComments.
|
40
42
|
Metrics/MethodLength:
|
43
|
+
Exclude:
|
44
|
+
- 'lib/convection/control/stack.rb'
|
41
45
|
Max: 37
|
42
46
|
|
43
47
|
# Offense count: 5
|
@@ -0,0 +1,19 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
region 'us-east-1'
|
4
|
+
name 'convection-sqs-queue-example'
|
5
|
+
|
6
|
+
sqs_queue = template do
|
7
|
+
description 'An example template for setting up a SQS queue with Convection'
|
8
|
+
|
9
|
+
sqs_queue 'ExampleSQSQueue' do
|
10
|
+
delay_seconds 0 # The time in seconds that delivery of messages is queued
|
11
|
+
maximum_message_size 262144 # How many bytes a message can contain before it's rejected
|
12
|
+
message_retention_period 345600 # The time in seconds a message stays in the queue
|
13
|
+
queue_name 'ExampleSQSQueue' # The name of the queue
|
14
|
+
receive_message_wait_time_seconds 0 # Set to non-zero to enable long polling
|
15
|
+
visibility_timeout 30 # The time in seconds the queue will be unavailable once a message is delivered
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
stack 'convection-sqs-queue-example', sqs_queue
|
@@ -0,0 +1,12 @@
|
|
1
|
+
# Creating a SQS queue in AWS #
|
2
|
+
|
3
|
+
This example shows how to set up a SQS queue in AWS. The values provided in the
|
4
|
+
template match the default values from the [AWS::SQS::Queue][sqs] resource. If
|
5
|
+
you leave a property blank, it will use the default value.
|
6
|
+
|
7
|
+
Run `convetion diff` to see what the template will create.
|
8
|
+
|
9
|
+
Run `convection converge` to create the example SQS queue.
|
10
|
+
|
11
|
+
|
12
|
+
[sqs]: http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-sqs-queues.html
|
@@ -84,7 +84,7 @@ module Convection
|
|
84
84
|
@id = nil
|
85
85
|
@outputs = {}
|
86
86
|
@resources = {}
|
87
|
-
@tasks = { after_create: [], after_delete: [], before_create: [], before_delete: [] }
|
87
|
+
@tasks = { after_create: [], after_delete: [], after_update: [], before_create: [], before_delete: [], before_update: [] }
|
88
88
|
instance_exec(&block) if block
|
89
89
|
@current_template = {}
|
90
90
|
@last_event_seen = nil
|
@@ -178,13 +178,21 @@ module Convection
|
|
178
178
|
o[:capabilities] = capabilities
|
179
179
|
end
|
180
180
|
|
181
|
-
|
181
|
+
# Get the state of existence before creation
|
182
|
+
existing_stack = exist?
|
183
|
+
if existing_stack
|
182
184
|
if diff.empty? ## No Changes. Just get resources and move on
|
183
185
|
block.call(Model::Event.new(:complete, "Stack #{ name } has no changes", :info)) if block
|
184
186
|
get_status
|
185
187
|
return
|
186
188
|
end
|
187
189
|
|
190
|
+
## Execute before update tasks
|
191
|
+
@tasks[:before_update].delete_if do |task|
|
192
|
+
task.call(self)
|
193
|
+
task.success?
|
194
|
+
end
|
195
|
+
|
188
196
|
## Update
|
189
197
|
@cf_client.update_stack(request_options.tap do |o|
|
190
198
|
o[:stack_name] = id
|
@@ -210,7 +218,8 @@ module Convection
|
|
210
218
|
watch(&block) if block # Block execution on stack status
|
211
219
|
|
212
220
|
## Execute after create tasks
|
213
|
-
|
221
|
+
after_task_type = existing_stack ? :after_update : :after_create
|
222
|
+
@tasks[after_task_type].delete_if do |task|
|
214
223
|
task.call(self)
|
215
224
|
task.success?
|
216
225
|
end
|
@@ -282,6 +291,10 @@ module Convection
|
|
282
291
|
@tasks[:after_delete] << task
|
283
292
|
end
|
284
293
|
|
294
|
+
def after_update_task(task)
|
295
|
+
@tasks[:after_update] << task
|
296
|
+
end
|
297
|
+
|
285
298
|
def before_create_task(task)
|
286
299
|
@tasks[:before_create] << task
|
287
300
|
end
|
@@ -290,6 +303,10 @@ module Convection
|
|
290
303
|
@tasks[:before_delete] << task
|
291
304
|
end
|
292
305
|
|
306
|
+
def before_update_task(task)
|
307
|
+
@tasks[:before_update] << task
|
308
|
+
end
|
309
|
+
|
293
310
|
private
|
294
311
|
|
295
312
|
def get_status(stack_name = id)
|
@@ -0,0 +1,71 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class TestAfterUpdateTasks < Minitest::Test
|
4
|
+
include TestHelper
|
5
|
+
|
6
|
+
def setup
|
7
|
+
@template = ::Convection.template do
|
8
|
+
description 'EC2 VPC Test Template'
|
9
|
+
|
10
|
+
ec2_vpc 'TargetVPC' do
|
11
|
+
network '10.0.0.0'
|
12
|
+
subnet_length 24
|
13
|
+
enable_dns
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_after_update_task_is_registered
|
19
|
+
Aws::CloudFormation::Client.stub :new, mock_cloudformation_client do
|
20
|
+
Aws::EC2::Client.stub :new, mock_ec2_client do
|
21
|
+
# when - a stack is initialized with a after_update_task
|
22
|
+
task = CollectAvailabilityZonesTask.new
|
23
|
+
stack = ::Convection::Control::Stack.new('EC2 VPC Test Stack', @template) do
|
24
|
+
after_update_task task
|
25
|
+
end
|
26
|
+
|
27
|
+
# then - the given stack should be present
|
28
|
+
assert_includes stack.tasks[:after_update], task
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_after_update_task_is_executed
|
34
|
+
Aws::CloudFormation::Client.stub :new, mock_cloudformation_client do
|
35
|
+
Aws::EC2::Client.stub :new, mock_ec2_client do
|
36
|
+
# given - a stack initialized with a after_update_task
|
37
|
+
task = CollectAvailabilityZonesTask.new
|
38
|
+
stack = ::Convection::Control::Stack.new('EC2 VPC Test Stack', @template) do
|
39
|
+
after_update_task task
|
40
|
+
end
|
41
|
+
|
42
|
+
# when - any changes to the stack are applied
|
43
|
+
stub_existence(stack, true) do
|
44
|
+
stack.apply
|
45
|
+
end
|
46
|
+
|
47
|
+
# then - the task should have been executed
|
48
|
+
assert_includes task.availability_zones, 'eu-central-1'
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_after_update_task_is_deregistered
|
54
|
+
Aws::CloudFormation::Client.stub :new, mock_cloudformation_client do
|
55
|
+
Aws::EC2::Client.stub :new, mock_ec2_client do
|
56
|
+
# given - a stack initialized with a after_update_task
|
57
|
+
stack = ::Convection::Control::Stack.new('EC2 VPC Test Stack', @template) do
|
58
|
+
after_update_task CollectAvailabilityZonesTask.new
|
59
|
+
end
|
60
|
+
|
61
|
+
# when - any changes to the stack are applied
|
62
|
+
stub_existence(stack, true) do
|
63
|
+
stack.apply
|
64
|
+
end
|
65
|
+
|
66
|
+
# then - the task should have been deregistered
|
67
|
+
assert_empty stack.tasks[:after_update]
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class TestBeforeUpdateTasks < Minitest::Test
|
4
|
+
include TestHelper
|
5
|
+
|
6
|
+
def setup
|
7
|
+
@template = ::Convection.template do
|
8
|
+
description 'EC2 VPC Test Template'
|
9
|
+
|
10
|
+
ec2_vpc 'TargetVPC' do
|
11
|
+
network '10.0.0.0'
|
12
|
+
subnet_length 24
|
13
|
+
enable_dns
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_before_update_task_is_registered
|
19
|
+
Aws::CloudFormation::Client.stub :new, mock_cloudformation_client do
|
20
|
+
Aws::EC2::Client.stub :new, mock_ec2_client do
|
21
|
+
# when - a stack is initialized with a before_update_task
|
22
|
+
task = CollectAvailabilityZonesTask.new
|
23
|
+
stack = ::Convection::Control::Stack.new('EC2 VPC Test Stack', @template) do
|
24
|
+
before_update_task task
|
25
|
+
end
|
26
|
+
|
27
|
+
# then - the given stack should be present
|
28
|
+
assert_includes stack.tasks[:before_update], task
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_before_update_task_is_executed
|
34
|
+
Aws::CloudFormation::Client.stub :new, mock_cloudformation_client do
|
35
|
+
Aws::EC2::Client.stub :new, mock_ec2_client do
|
36
|
+
# given - a stack initialized with a before_update_task
|
37
|
+
task = CollectAvailabilityZonesTask.new
|
38
|
+
stack = ::Convection::Control::Stack.new('EC2 VPC Test Stack', @template) do
|
39
|
+
before_update_task task
|
40
|
+
end
|
41
|
+
|
42
|
+
# when - any changes to the stack are applied
|
43
|
+
stub_existence(stack, true) do
|
44
|
+
stack.apply
|
45
|
+
end
|
46
|
+
|
47
|
+
# then - the task should have been executed
|
48
|
+
assert_includes task.availability_zones, 'eu-central-1'
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_before_update_task_is_deregistered
|
54
|
+
Aws::CloudFormation::Client.stub :new, mock_cloudformation_client do
|
55
|
+
Aws::EC2::Client.stub :new, mock_ec2_client do
|
56
|
+
# given - a stack initialized with a before_update_task
|
57
|
+
stack = ::Convection::Control::Stack.new('EC2 VPC Test Stack', @template) do
|
58
|
+
before_update_task CollectAvailabilityZonesTask.new
|
59
|
+
end
|
60
|
+
|
61
|
+
# when - any changes to the stack are applied
|
62
|
+
stub_existence(stack, true) do
|
63
|
+
stack.apply
|
64
|
+
end
|
65
|
+
|
66
|
+
# then - the task should have been deregistered
|
67
|
+
assert_empty stack.tasks[:before_update]
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
data/test/test_helper.rb
CHANGED
@@ -41,6 +41,7 @@ module TestHelper
|
|
41
41
|
cf_client.expect(:create_stack, nil, any_args)
|
42
42
|
cf_client.expect(:delete_stack, nil, any_args)
|
43
43
|
cf_client.expect(:describe_stacks, nil)
|
44
|
+
cf_client.expect(:update_stack, nil, any_args)
|
44
45
|
def cf_client.describe_stacks(*)
|
45
46
|
context = nil # we don't need any request context here.
|
46
47
|
raise Aws::CloudFormation::Errors::ValidationError.new(context, 'Stack does not exist.')
|
@@ -61,4 +62,11 @@ module TestHelper
|
|
61
62
|
ec2_client.expect(:describe_availability_zones, availability_zone_description)
|
62
63
|
ec2_client
|
63
64
|
end
|
65
|
+
|
66
|
+
# Stub both exist/exist? since aliases are not overridden when stubbing in minitest.
|
67
|
+
def stub_existence(stack, exists, &block)
|
68
|
+
stack.stub(:exist, exists) do
|
69
|
+
stack.stub(:exist?, exists, &block)
|
70
|
+
end
|
71
|
+
end
|
64
72
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: convection
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.27
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- John Manero
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-06-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: aws-sdk
|
@@ -102,6 +102,8 @@ files:
|
|
102
102
|
- example/instances.rb
|
103
103
|
- example/output/vpc.json
|
104
104
|
- example/security-groups.rb
|
105
|
+
- example/sqs-queue/Cloudfile
|
106
|
+
- example/sqs-queue/README.md
|
105
107
|
- example/trust_cloudtrail.rb
|
106
108
|
- example/vpc.rb
|
107
109
|
- ext/resource_generator.sh
|
@@ -224,8 +226,10 @@ files:
|
|
224
226
|
- test/convection/model/test_vpc_endpoint.rb
|
225
227
|
- test/convection/tasks/test_after_create_tasks.rb
|
226
228
|
- test/convection/tasks/test_after_delete_tasks.rb
|
229
|
+
- test/convection/tasks/test_after_update_tasks.rb
|
227
230
|
- test/convection/tasks/test_before_create_tasks.rb
|
228
231
|
- test/convection/tasks/test_before_delete_tasks.rb
|
232
|
+
- test/convection/tasks/test_before_update_tasks.rb
|
229
233
|
- test/test_helper.rb
|
230
234
|
homepage: https://github.com/rapid7/convection
|
231
235
|
licenses:
|
@@ -266,6 +270,8 @@ test_files:
|
|
266
270
|
- test/convection/model/test_vpc_endpoint.rb
|
267
271
|
- test/convection/tasks/test_after_create_tasks.rb
|
268
272
|
- test/convection/tasks/test_after_delete_tasks.rb
|
273
|
+
- test/convection/tasks/test_after_update_tasks.rb
|
269
274
|
- test/convection/tasks/test_before_create_tasks.rb
|
270
275
|
- test/convection/tasks/test_before_delete_tasks.rb
|
276
|
+
- test/convection/tasks/test_before_update_tasks.rb
|
271
277
|
- test/test_helper.rb
|