kumogata 0.4.3 → 0.4.4
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/README.md +2 -2
- data/kumogata.gemspec +1 -0
- data/lib/kumogata/client.rb +9 -1
- data/lib/kumogata/post_processing.rb +1 -1
- data/lib/kumogata/version.rb +1 -1
- data/spec/kumogata_update_spec.rb +69 -25
- data/spec/spec_helper.rb +2 -0
- metadata +15 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: df82f77f6c7023cbdaa9cf336a3857bd76bdbecb
|
4
|
+
data.tar.gz: 0f6e167f920c80123bcf89338dbb023439eb46c8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a53b163c4963b3a216e4c7e2d563f63d75f76073f4f18b0386e75120e417f0717bcc5cfbaefe007d402e16c0c92de04cbe8669c1cff80d450fe5682f68442f1e
|
7
|
+
data.tar.gz: ec3887e27bcecedb0ce01bf7e79a7e0077a0d6e61ee6269c88e51e9de72d9a3fbcb87f79f374c95f0c50547569ffcea2336d0ea2405043908c09e619434b8236
|
data/README.md
CHANGED
@@ -5,8 +5,8 @@
|
|
5
5
|
|
6
6
|
Kumogata is a tool for [AWS CloudFormation](https://aws.amazon.com/cloudformation/).
|
7
7
|
|
8
|
-
[](http://badge.fury.io/rb/kumogata)
|
9
|
+
[](https://drone.io/github.com/winebarrel/kumogata/latest)
|
10
10
|
|
11
11
|
It can define a template in Ruby DSL, such as:
|
12
12
|
|
data/kumogata.gemspec
CHANGED
data/lib/kumogata/client.rb
CHANGED
@@ -39,7 +39,10 @@ class Kumogata::Client
|
|
39
39
|
|
40
40
|
def update(path_or_url, stack_name)
|
41
41
|
validate_stack_name(stack_name)
|
42
|
+
|
43
|
+
@options.delete_stack = false
|
42
44
|
template = open_template(path_or_url)
|
45
|
+
update_deletion_policy(template, :update_metadate => true)
|
43
46
|
add_encryption_password(template)
|
44
47
|
|
45
48
|
outputs = update_stack(template, stack_name)
|
@@ -444,11 +447,16 @@ class Kumogata::Client
|
|
444
447
|
end
|
445
448
|
end
|
446
449
|
|
447
|
-
def update_deletion_policy(template)
|
450
|
+
def update_deletion_policy(template, options = {})
|
448
451
|
if @options.delete_stack? or @options.deletion_policy_retain?
|
449
452
|
template['Resources'].each do |k, v|
|
450
453
|
next if /\AAWS::CloudFormation::/ =~ v['Type']
|
451
454
|
v['DeletionPolicy'] ||= 'Retain'
|
455
|
+
|
456
|
+
if options[:update_metadate]
|
457
|
+
v['Metadata'] ||= {}
|
458
|
+
v['Metadata']['DeletionPolicyUpdateKeyForKumogata'] = "DeletionPolicyUpdateValueForKumogata#{Time.now.to_i}"
|
459
|
+
end
|
452
460
|
end
|
453
461
|
end
|
454
462
|
end
|
@@ -25,7 +25,7 @@ class Kumogata::PostProcessing
|
|
25
25
|
raise "Invalid post processing: #{name} => #{attrs.inspect}"
|
26
26
|
end
|
27
27
|
|
28
|
-
timing = [(attrs['after'] ||
|
28
|
+
timing = [(attrs['after'] || [:create])].flatten.map {|i| i.to_sym }
|
29
29
|
command = attrs['command']
|
30
30
|
|
31
31
|
validate_timing(name, timing)
|
data/lib/kumogata/version.rb
CHANGED
@@ -56,6 +56,69 @@ end
|
|
56
56
|
end
|
57
57
|
end
|
58
58
|
|
59
|
+
it 'update a stack from Ruby template with deletion policy retain' do
|
60
|
+
template = <<-EOS
|
61
|
+
Resources do
|
62
|
+
myEC2Instance do
|
63
|
+
Type "AWS::EC2::Instance"
|
64
|
+
Properties do
|
65
|
+
ImageId "ami-XXXXXXXX"
|
66
|
+
InstanceType "t1.micro"
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
Outputs do
|
72
|
+
AZ do
|
73
|
+
Value do
|
74
|
+
Fn__GetAtt "myEC2Instance", "AvailabilityZone"
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
EOS
|
79
|
+
|
80
|
+
Timecop.freeze(Time.parse('2014/03/13 0:00')) do
|
81
|
+
run_client(:update, :arguments => ['MyStack'], :template => template, :options => {:deletion_policy_retain => true}) do |client, cf|
|
82
|
+
template = eval_template(template, :update_deletion_policy => true)
|
83
|
+
template["Resources"]["myEC2Instance"]["Metadata"] = {
|
84
|
+
"DeletionPolicyUpdateKeyForKumogata" => "DeletionPolicyUpdateValueForKumogata1394636400"
|
85
|
+
}
|
86
|
+
json = template.to_json
|
87
|
+
client.should_receive(:print_event_log).once
|
88
|
+
client.should_receive(:create_event_log).once
|
89
|
+
|
90
|
+
output = make_double('output') do |obj|
|
91
|
+
obj.should_receive(:key) { 'AZ' }
|
92
|
+
obj.should_receive(:value) { 'ap-northeast-1b' }
|
93
|
+
end
|
94
|
+
|
95
|
+
resource_summary = make_double('resource_summary') do |obj|
|
96
|
+
obj.should_receive(:[]).with(:logical_resource_id) { 'myEC2Instance' }
|
97
|
+
obj.should_receive(:[]).with(:physical_resource_id) { 'i-XXXXXXXX' }
|
98
|
+
obj.should_receive(:[]).with(:resource_type) { 'AWS::EC2::Instance' }
|
99
|
+
obj.should_receive(:[]).with(:resource_status) { 'UPDATE_COMPLETE' }
|
100
|
+
obj.should_receive(:[]).with(:resource_status_reason) { nil }
|
101
|
+
obj.should_receive(:[]).with(:last_updated_timestamp) { '2014-03-02 04:35:12 UTC' }
|
102
|
+
end
|
103
|
+
|
104
|
+
stack = make_double('stack') do |obj|
|
105
|
+
obj.should_receive(:update).with(:template => json)
|
106
|
+
obj.should_receive(:status).and_return(
|
107
|
+
'UPDATE_COMPLETE', 'UPDATE_COMPLETE', 'UPDATE_COMPLETE')
|
108
|
+
obj.should_receive(:outputs) { [output] }
|
109
|
+
obj.should_receive(:resource_summaries) { [resource_summary] }
|
110
|
+
end
|
111
|
+
|
112
|
+
stacks = make_double('stacks') do |obj|
|
113
|
+
obj.should_receive(:[])
|
114
|
+
.with('MyStack') { stack }
|
115
|
+
end
|
116
|
+
|
117
|
+
cf.should_receive(:stacks) { stacks }
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
59
122
|
it 'update a stack from Ruby template and run command' do
|
60
123
|
template = <<-TEMPLATE
|
61
124
|
Resources do
|
@@ -137,35 +200,16 @@ end
|
|
137
200
|
|
138
201
|
cf.should_receive(:stacks) { stacks }
|
139
202
|
|
203
|
+
process_status1 = double('process_status1')
|
204
|
+
process_status2 = double('process_status2')
|
140
205
|
|
141
|
-
|
142
|
-
process_status2 = make_double('process_status2') {|obj| obj.should_receive(:to_i).and_return(0) }
|
143
|
-
|
144
|
-
client.instance_variable_get(:@post_processing)
|
145
|
-
.should_receive(:run_shell_command)
|
146
|
-
.with(" echo <%= Key \"AZ\" %>\n echo <%= Key \"Region\" %>\n", {"AZ"=>"ap-northeast-1b", "Region"=>"ap-northeast-1"})
|
147
|
-
.and_return(["ap-northeast-1b\nap-northeast-1\n", "", process_status1])
|
148
|
-
client.instance_variable_get(:@post_processing)
|
149
|
-
.should_receive(:run_shell_command)
|
150
|
-
.with(" echo <%= Key \"Region\" %>\n echo <%= Key \"AZ\" %>\n", {"AZ"=>"ap-northeast-1b", "Region"=>"ap-northeast-1"})
|
151
|
-
.and_return(["ap-northeast-1\nap-northeast-1b\n", "", process_status2])
|
152
|
-
|
153
|
-
client.instance_variable_get(:@post_processing)
|
154
|
-
.should_receive(:print_command).with('command_a')
|
155
|
-
client.instance_variable_get(:@post_processing)
|
156
|
-
.should_receive(:print_command).with('command_b')
|
206
|
+
Open3.should_not_receive(:capture3)
|
157
207
|
|
158
208
|
client.instance_variable_get(:@post_processing)
|
159
|
-
.
|
160
|
-
.with("ap-northeast-1b\nap-northeast-1\n", "", process_status1)
|
161
|
-
client.instance_variable_get(:@post_processing)
|
162
|
-
.should_receive(:print_command_result)
|
163
|
-
.with("ap-northeast-1\nap-northeast-1b\n", "", process_status2)
|
209
|
+
.should_not_receive(:print_command_result)
|
164
210
|
|
165
211
|
client.instance_variable_get(:@post_processing)
|
166
|
-
.
|
167
|
-
.with([{'command_a' => {'ExitStatus' => 0, 'StdOut' => "ap-northeast-1b\nap-northeast-1\n", 'StdErr' => ""}},
|
168
|
-
{'command_b' => {'ExitStatus' => 0, 'StdOut' => "ap-northeast-1\nap-northeast-1b\n", 'StdErr' => ""}}])
|
212
|
+
.should_not_receive(:save_command_results)
|
169
213
|
end
|
170
214
|
end
|
171
215
|
|
@@ -191,6 +235,7 @@ end
|
|
191
235
|
|
192
236
|
_post do
|
193
237
|
ssh_command do
|
238
|
+
after :update
|
194
239
|
ssh do
|
195
240
|
host { Key "PublicIp" }
|
196
241
|
user "ec2-user"
|
@@ -251,7 +296,6 @@ end
|
|
251
296
|
client.instance_variable_get(:@post_processing)
|
252
297
|
.should_receive(:save_command_results)
|
253
298
|
.with([{'ssh_command' => {'ExitStatus' => 0, 'StdOut' => "file1\nfile2\n", 'StdErr' => ""}}])
|
254
|
-
|
255
299
|
end
|
256
300
|
end
|
257
301
|
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kumogata
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Genki Sugawara
|
@@ -206,6 +206,20 @@ dependencies:
|
|
206
206
|
- - '>='
|
207
207
|
- !ruby/object:Gem::Version
|
208
208
|
version: 2.11.0
|
209
|
+
- !ruby/object:Gem::Dependency
|
210
|
+
name: timecop
|
211
|
+
requirement: !ruby/object:Gem::Requirement
|
212
|
+
requirements:
|
213
|
+
- - '>='
|
214
|
+
- !ruby/object:Gem::Version
|
215
|
+
version: '0'
|
216
|
+
type: :development
|
217
|
+
prerelease: false
|
218
|
+
version_requirements: !ruby/object:Gem::Requirement
|
219
|
+
requirements:
|
220
|
+
- - '>='
|
221
|
+
- !ruby/object:Gem::Version
|
222
|
+
version: '0'
|
209
223
|
description: A tool for AWS CloudFormation. It can define a template in Ruby DSL.
|
210
224
|
email:
|
211
225
|
- sgwr_dts@yahoo.co.jp
|