aws-must-templates 0.1.6 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +97 -44
- data/lib/tasks/cross-ref.rb +6 -0
- data/lib/tasks/suite.rake +150 -48
- data/lib/test-suites/test_suites.rb +13 -13
- data/mustache/commonDependsOn.mustache +24 -2
- data/mustache/commonRef.mustache +22 -0
- data/mustache/commonValue.mustache +1 -1
- data/mustache/commonXGressRule.mustache +31 -0
- data/mustache/mapping.mustache +3 -1
- data/mustache/mappingAmazonVpcNat.mustache +38 -0
- data/mustache/resource.mustache +4 -0
- data/mustache/resourceInstance.mustache +26 -7
- data/mustache/resourceInternetGateway.mustache +30 -16
- data/mustache/resourceRoute.mustache +50 -0
- data/mustache/resourceRouteTable.mustache +67 -0
- data/mustache/resourceSecurityGroup.mustache +13 -12
- data/mustache/resourceSubnet.mustache +20 -8
- data/mustache/root.mustache +26 -11
- data/spec/aws-must-templates/AllwaysOk/AllwaysOk_spec.rb +35 -0
- data/spec/aws-must-templates/AwsCommandLineInterfaceInstalled/AwsCommandLineInterfaceInstalled_spec.rb +19 -1
- data/spec/aws-must-templates/AwsMustTestRunnerProperties/AwsMustTestRunnerProperties_spec.rb +16 -1
- data/spec/aws-must-templates/CloudFormationHelperScriptsInstalled/CloudFormationHelperScriptsInstalled_spec.rb +17 -0
- data/spec/aws-must-templates/Ec2InstanceType/Ec2InstanceType_spec.rb +47 -0
- data/spec/aws-must-templates/Ec2PrivateIp/Ec2PrivateIp_spec.rb +49 -0
- data/spec/aws-must-templates/Ec2PublicIp/Ec2PublicIp_spec.rb +68 -0
- data/spec/aws-must-templates/Ec2Routes/Ec2Routes_spec.rb +69 -0
- data/spec/aws-must-templates/Ec2SecurityGroups/Ec2SecurityGroups_spec.rb +151 -0
- data/spec/aws-must-templates/Ec2StatusNormal/Ec2StatusNormal_spec.rb +55 -0
- data/spec/aws-must-templates/NetworkCanPing/NetworkCanPing_spec.rb +36 -0
- data/spec/aws-must-templates/ParameterTest/ParameterTest_spec.rb +17 -1
- data/spec/aws-must-templates/RespondsToPing/RespondsToPing_spec.rb +46 -0
- data/spec/aws-must-templates/S3NoAccess/S3NoAccess_spec.rb +17 -3
- data/spec/aws-must-templates/S3ReadAccessAllowed/S3ReadAccessAllowed_spec.rb +18 -1
- data/spec/aws-must-templates/Stack/Stack_spec.rb +28 -1
- data/spec/aws-must-templates/ValidOSVersion/ValidOSVersion_spec.rb +16 -1
- data/spec/aws-must-templates/Vpc/vpc_spec.rb +51 -0
- data/spec/aws-must-templates/table_of_content.mustache +67 -0
- data/spec/lib/test_suites_spec.rb +101 -28
- data/spec/mustache/commonDependsOn_spec.rb +57 -2
- data/spec/mustache/commonInstanceType_spec.rb +1 -1
- data/spec/mustache/mappingAmazonVpcNat_spec.rb +56 -0
- data/spec/mustache/mapping_spec.rb +48 -7
- data/spec/mustache/resourceInstance_spec.rb +102 -1
- data/spec/mustache/resourceInternetGateway_spec.rb +14 -9
- data/spec/mustache/resourcePolicy_spec.rb +1 -1
- data/spec/mustache/resourceS3Bucket_spec.rb +1 -1
- data/spec/mustache/resourceSecurityGroup_spec.rb +3 -3
- data/spec/mustache/resourceSubnet_spec.rb +50 -3
- data/spec/support/lib/aws/aws.rb +6 -0
- data/spec/support/lib/aws/ec2_resource.rb +177 -0
- data/spec/support/lib/aws/mixin_cidr.rb +18 -0
- data/spec/support/lib/aws/mixin_ec2.rb +53 -0
- data/spec/support/lib/aws/mixin_security_group.rb +15 -0
- data/spec/support/lib/aws/mixin_subnet.rb +77 -0
- data/spec/support/lib/aws/mixin_vpc.rb +10 -0
- data/spec/support/lib/aws/route_resource.rb +86 -0
- data/spec/support/lib/aws/security_group_resource.rb +120 -0
- data/spec/support/lib/aws/vpc_resource.rb +69 -0
- data/spec/support/lib/suite_value.rb +38 -0
- data/spec/support/lib/test_parameter.rb +12 -8
- data/spec/support/lib/valid_property.rb +29 -9
- data/spec/support/spec_helper.rb +75 -44
- data/spec/support/utils.rb +4 -0
- metadata +34 -24
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f7ef597a5063b288cc1c4fba6f4a2119cf008391
|
4
|
+
data.tar.gz: b89652f4001fea744e1be3e6d42233ef154bc15f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0f17a8a069e5249a231ec574e3b801e5149a2a7c54aef1f5e98dc5d0cbbacbbc76280568280aaa9fee9d85ea332656ed4fa9048fa7ab58cc2c88a6cd47cbb2ec
|
7
|
+
data.tar.gz: 024b79c1a947156e3ea98347a5312c832188bbb7ace1b09cd37fd54292051a4a1817e45e5c5023b1571ef0cdfeeb8d1a3e1c8f2e12c094e56e80c766a53e8a61
|
data/README.md
CHANGED
@@ -1,11 +1,13 @@
|
|
1
|
-
# aws-must-templates - cloudformation templates for aws-must - $Release:0.1
|
1
|
+
# aws-must-templates - cloudformation templates for aws-must - $Release:0.2.1$
|
2
2
|
|
3
3
|
Set of [extensible](#OVERRIDE)
|
4
4
|
[templates](https://rawgit.com/jarjuk/aws-must-templates/master/generated-docs/aws-must-templates.html)
|
5
5
|
for [aws-must](https://github.com/jarjuk/aws-must) tool to generate
|
6
6
|
CloudFormation JSON from a YAML configuration, and a
|
7
|
-
[Test Runner](#TESTING)
|
8
|
-
|
7
|
+
[Test Runner](#TESTING) with
|
8
|
+
[reusable tests](https://rawgit.com/jarjuk/aws-must-templates/master/generated-docs/aws-must-templates-spec.html)
|
9
|
+
for [validating correctness](#TEST_CASES) of CloudFormation stacks
|
10
|
+
provisioned.
|
9
11
|
|
10
12
|
See blog posts
|
11
13
|
[part1](https://jarjuk.wordpress.com/2015/08/18/announcing-aws-must-templates-part1)
|
@@ -50,8 +52,8 @@ When using code generators, consider
|
|
50
52
|
the threshold to write tests
|
51
53
|
|
52
54
|
3. by allowing users [to reuse](#TEST_CASES)
|
53
|
-
[test cases](generated-docs/
|
54
|
-
|
55
|
+
[test cases](https://rawgit.com/jarjuk/aws-must-templates/master/generated-docs/aws-must-templates-spec.html)
|
56
|
+
from **aws-must-templates** quality assurance
|
55
57
|
|
56
58
|
4. by having the possibility to [include own test](#TEST_CASES)
|
57
59
|
cases to test suites
|
@@ -90,8 +92,12 @@ used to validate **aws-must-templates** implementation. For, example
|
|
90
92
|
bucket, one of the instances (`myInstance`) which is granted a read
|
91
93
|
access to the S3 bucket
|
92
94
|
|
93
|
-
|
94
|
-
|
95
|
+
* [suite2.yaml](suite2.yaml): Creates VPC with Public and Private
|
96
|
+
Subnets (NAT) similar to
|
97
|
+
[scenario 2](http://docs.aws.amazon.com/AmazonVPC/latest/UserGuide/VPC_Scenario2.html)
|
98
|
+
|
99
|
+
See [test report](https://gist.github.com/jarjuk/9ab1c25d436c4e468f5e)
|
100
|
+
of **aws-must-templates** for more information.
|
95
101
|
|
96
102
|
### Generate CloudFormation JSON templates
|
97
103
|
|
@@ -189,18 +195,29 @@ To use the **aws-must-templates** Test Runner
|
|
189
195
|
|
190
196
|
Add following lines to `Rakefile`
|
191
197
|
|
198
|
+
# name of configuration file
|
199
|
+
suite_runner_configs= "suite-runner-configs.yaml"
|
200
|
+
|
201
|
+
# Override configuration in 'suite.rake'
|
202
|
+
$suite_runner_configs = File.exist?(suite_runner_configs) ? YAML.load_file( suite_runner_configs ) : {}
|
203
|
+
|
192
204
|
spec = Gem::Specification.find_by_name 'aws-must-templates'
|
193
205
|
load "#{spec.gem_dir}/lib/tasks/suite.rake"
|
194
206
|
|
195
|
-
|
207
|
+
Optionally, copy
|
208
|
+
[default Test Runner Configurations](https://rawgit.com/jarjuk/aws-must-templates/master/suite-runner-configs.yaml)
|
209
|
+
to `suite-runner-configs.yaml` file in current working directory, and
|
210
|
+
modify settings in the file to override default values.
|
211
|
+
|
212
|
+
Create an empty `test-suites.yaml` -file
|
196
213
|
|
197
214
|
touch test-suites.yaml
|
198
215
|
|
199
216
|
and run
|
200
217
|
|
201
|
-
|
218
|
+
rake -T suite
|
202
219
|
|
203
|
-
For an empty test-suites.yaml the result shows
|
220
|
+
For an empty `test-suites.yaml`, the result shows
|
204
221
|
|
205
222
|
rake suite:all[gen_opts] # Run all suites
|
206
223
|
|
@@ -220,31 +237,60 @@ pair
|
|
220
237
|
|
221
238
|
**Prepare ssh-connection configuration**
|
222
239
|
|
223
|
-
Test Runner uses
|
224
|
-
|
225
|
-
|
226
|
-
ssh
|
240
|
+
Test Runner uses
|
241
|
+
[SSH Client Configuration](http://www.openbsd.org/cgi-bin/man.cgi/OpenBSD-current/man5/ssh_config.5?query=ssh_config&sec=5)
|
242
|
+
in `ssh/config.aws` file. Configuration file `ssh/config.aws` is
|
243
|
+
created automatically, using `ssh/config.init`, if it does not exist.
|
227
244
|
|
228
|
-
For example, the
|
229
|
-
|
230
|
-
key used in **aws-must-templates** test suites.
|
245
|
+
For example, the following configuration in `ssh/config.init`
|
246
|
+
instructs OpenSSH
|
231
247
|
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
248
|
+
Host *.internal
|
249
|
+
ProxyCommand ssh myFront1 -F ssh/config.aws nc -q0 %h 22
|
250
|
+
|
251
|
+
|
252
|
+
# using RHEL Amazon vpc-nat instance --> ec2-user
|
253
|
+
Host myNat
|
254
|
+
user ec2-user
|
255
|
+
|
256
|
+
Host *
|
257
|
+
user ubuntu
|
258
|
+
StrictHostKeyChecking no
|
259
|
+
UserKnownHostsFile=/dev/null
|
260
|
+
IdentityFile ~/.ssh/demo-key/demo-key
|
261
|
+
|
262
|
+
|
263
|
+
* to use user name `ubuntu` and SSH private key in
|
264
|
+
`~/.ssh/demo-key/demo-key` for all hosts, expect for instance
|
265
|
+
`myNat` user name is `ec2-user`.
|
266
|
+
|
267
|
+
* to proxy connections to host names ending `.internal` to proxy
|
268
|
+
connections over instance `myFront1`
|
237
269
|
|
238
|
-
|
239
|
-
|
240
|
-
|
270
|
+
* to prevent OpenSSH from updating your default `.ssh/known_hosts`
|
271
|
+
file with the fingerprint of the (temporary) instance used in
|
272
|
+
testing.
|
273
|
+
|
274
|
+
Once configuration in `ssh/config.init` is in place, running
|
275
|
+
|
276
|
+
rake suite:ec2-sync
|
277
|
+
|
278
|
+
updates EC2 instance metadata in `ssh/config.aws`.
|
279
|
+
|
280
|
+
**Notice** You may need to change `aws_region` setting values in
|
281
|
+
[suite-runner-configs.yaml](#SETUP-TEST-RUNNER).
|
282
|
+
|
283
|
+
See
|
284
|
+
[blog post](https://jarjuk.wordpress.com/2015/09/08/using-openssh-on-aws-platform/#more-273https://jarjuk.wordpress.com/2015/09/08/using-openssh-on-aws-platform)
|
285
|
+
for more information on using OpenSSH on AWS platform.
|
241
286
|
|
242
287
|
### Implement Test Cases<a id="TEST_CASES"/>
|
243
288
|
|
244
|
-
Test Runner
|
245
|
-
|
246
|
-
|
247
|
-
|
289
|
+
Test Runner allows user to implement own Test Cases, or to
|
290
|
+
[reuse](https://rawgit.com/jarjuk/aws-must-templates/master/generated-docs/aws-must-templates-spec.html)
|
291
|
+
existing tests in **aws-must-templates**. It first searches Test
|
292
|
+
Cases locally under sub-directory `spec/aws-must-templates`, and if
|
293
|
+
not found, tries to locate Test Cases in Gem **aws-must-templates**.
|
248
294
|
|
249
295
|
Test runner uses Rspec with [serverspec](http://serverspec.org/)
|
250
296
|
library. For example, `ValidOSVersion` Test Case in
|
@@ -269,9 +315,9 @@ with the code shown:
|
|
269
315
|
|
270
316
|
|
271
317
|
For more information on Test Cases, see
|
272
|
-
[test report](
|
273
|
-
[test-suites](test-suites.yaml) in
|
274
|
-
|
318
|
+
[test report](https://gist.github.com/jarjuk/9ab1c25d436c4e468f5e)
|
319
|
+
generated, when running [test-suites](test-suites.yaml) in
|
320
|
+
**aws-must-templates** development.
|
275
321
|
|
276
322
|
|
277
323
|
### Configure Test Suites <a id="TEST-SUITES"/>
|
@@ -284,12 +330,12 @@ The picture below present main elements used in `test-suites.yaml`.
|
|
284
330
|
![test-suites.yaml elements](./pics/test-suites.jpg)
|
285
331
|
|
286
332
|
A Test Suite validates correctness of a CloudFormation Stack. One Test
|
287
|
-
Suite defines tests for multiple EC2 Instances.
|
288
|
-
|
289
|
-
[ssh/config](#TEST-CONTEXT) -file. An EC2 Instance acts in many
|
290
|
-
Roles. A Role maps to a [Test Case](#TEST_CASES), and
|
291
|
-
|
292
|
-
|
333
|
+
Suite defines tests for multiple EC2 Instances. SSH Client
|
334
|
+
Configuration for a EC2 Instance is looked up in
|
335
|
+
[ssh/config.aws](#TEST-CONTEXT) -file. An EC2 Instance acts in many
|
336
|
+
Roles. A Role maps to a [Test Case](#TEST_CASES), and defines values
|
337
|
+
for the Test Case Parameters. The parameter may be a constant, or a
|
338
|
+
reference to Stack Parameter, or to Stack Output.
|
293
339
|
|
294
340
|
As an example, the Test Suite for `mystack` is
|
295
341
|
|
@@ -327,16 +373,23 @@ a more detailed explanation, and for more examples.
|
|
327
373
|
|
328
374
|
**NOTICE** It advisable to check on AWS console that all stack
|
329
375
|
resources are deleted successfully after running test suites.
|
376
|
+
|
377
|
+
**Notice** Some of tests included in **aws-must-templates** use AWS
|
378
|
+
[SDK for Ruby - Version 2](http://docs.aws.amazon.com/sdkforruby/api/index.html). The
|
379
|
+
SDK searches `ENV['AWS_REGION']` for a region information. You have
|
380
|
+
the option to set the environment variable, or configure property
|
381
|
+
`aws_region` in [suite-runner-configs.yaml](#SETUP-TEST-RUNNER).
|
382
|
+
|
330
383
|
|
331
384
|
To run test suite `mystack` defined in in `test-suites.yml` using
|
332
385
|
default templates in **aws-must-templates** use the command
|
333
386
|
|
334
|
-
|
387
|
+
rake suite:mystack
|
335
388
|
|
336
389
|
To [override](#OVERRIDE) default implementation with templates in
|
337
390
|
directory `myextensions`, use the command
|
338
391
|
|
339
|
-
|
392
|
+
rake suite:mystack['-m myextensions/ aws-must-templates']
|
340
393
|
|
341
394
|
|
342
395
|
For a Test Suite, Test Runner
|
@@ -345,17 +398,17 @@ For a Test Suite, Test Runner
|
|
345
398
|
* uses the JSON template to provision a stack on Amazon platform,
|
346
399
|
* and, once the `StackStatus` is `CREATE_COMPLETE`,
|
347
400
|
* iterates EC2 Instances and runs Test Cases in the EC2 Instance Role
|
348
|
-
* creates
|
401
|
+
* creates test reports to `generated-doc/suites` directory
|
349
402
|
* finally, after the test execution, the stack is deleted from Amazon platform.
|
350
403
|
|
351
404
|
|
352
405
|
To run all test suites defined in `test-suites.yaml`, use the command
|
353
406
|
|
354
|
-
|
407
|
+
rake suite:all
|
355
408
|
|
356
409
|
or to override the default implementation
|
357
410
|
|
358
|
-
|
411
|
+
rake suite:all['-m myextensions/ aws-must-templates']
|
359
412
|
|
360
413
|
Command
|
361
414
|
|
@@ -375,7 +428,7 @@ See [RELEASES](RELEASES.md)
|
|
375
428
|
|
376
429
|
Add more tests, e.g.
|
377
430
|
|
378
|
-
*
|
431
|
+
* SNS
|
379
432
|
* install Chef
|
380
433
|
|
381
434
|
Add more template support
|
data/lib/tasks/cross-ref.rb
CHANGED
@@ -49,6 +49,12 @@ def xref_to_dot( xref_suite_X_test, xref_test_X_suite )
|
|
49
49
|
puts <<-EOS
|
50
50
|
digraph {
|
51
51
|
rankdir=TB
|
52
|
+
|
53
|
+
// options for neato
|
54
|
+
// http://stackoverflow.com/questions/7670304/how-to-deal-with-densely-connected-graphs-with-neato
|
55
|
+
overlap=false;
|
56
|
+
splines=true;
|
57
|
+
|
52
58
|
|
53
59
|
node [ fontname = "Courier"
|
54
60
|
fontsize = 8
|
data/lib/tasks/suite.rake
CHANGED
@@ -8,6 +8,18 @@ require 'json'
|
|
8
8
|
require 'rake'
|
9
9
|
require 'rspec/core/rake_task'
|
10
10
|
|
11
|
+
# ------------------------------------------------------------------
|
12
|
+
# configuration extesions (see task 'suite-runner-configs' for documentation)
|
13
|
+
|
14
|
+
default_suite_runner_configs = {
|
15
|
+
'ssh_config_file' => "ssh/config.aws",
|
16
|
+
'ssh_config_init' => "ssh/config.init",
|
17
|
+
'aws_region' => nil,
|
18
|
+
}
|
19
|
+
|
20
|
+
suite_runner_configs =
|
21
|
+
default_suite_runner_configs.merge( $suite_runner_configs ? $suite_runner_configs : {} )
|
22
|
+
|
11
23
|
# ------------------------------------------------------------------
|
12
24
|
# test-suites.yaml
|
13
25
|
|
@@ -33,6 +45,45 @@ END_STATES = SUCESS_STATES + FAILURE_STATES
|
|
33
45
|
|
34
46
|
namespace :suite do
|
35
47
|
|
48
|
+
# **********
|
49
|
+
# desc "Outpu configuration"
|
50
|
+
task "suite-runner-configs" do
|
51
|
+
|
52
|
+
# puts( default_suite_runner_configs.to_yaml)
|
53
|
+
doc = <<EOS
|
54
|
+
---
|
55
|
+
# Test Runner suite-runner-default
|
56
|
+
# ------------------------------------------------------------------
|
57
|
+
#
|
58
|
+
# copy this file to cwd with the name 'suite-runner-configs.yaml' and
|
59
|
+
# add following lines to Rakefile
|
60
|
+
#
|
61
|
+
# suite_runner_configs= "suite-runner-configs.yaml"
|
62
|
+
# $suite_runner_configs = File.exist?(suite_runner_configs) ? YAML.load_file( suite_runner_configs ) : {}
|
63
|
+
#
|
64
|
+
# spec = Gem::Specification.find_by_name 'aws-must-templates'
|
65
|
+
# load "\#{spec.gem_dir}/lib/tasks/suite.rake"
|
66
|
+
#
|
67
|
+
# ------------------------------------------------------------------
|
68
|
+
|
69
|
+
# SSH Client Configuration file where EC2 Instance Tag Name/DNS Name
|
70
|
+
# mapping is synchronized
|
71
|
+
ssh_config_file: #{default_suite_runner_configs['ssh_config_file']}
|
72
|
+
|
73
|
+
# Name of file, which is used to seed 'ssh_config_file', if
|
74
|
+
# 'ssh_config_file' file does not exist
|
75
|
+
ssh_config_init: #{default_suite_runner_configs['ssh_config_init']}
|
76
|
+
|
77
|
+
# http://docs.aws.amazon.com/sdkforruby/api/index.html#Configuration
|
78
|
+
# "The SDK searches the following locations for a region: ENV['AWS_REGION']"
|
79
|
+
#
|
80
|
+
# Test runner sets ENV['AWS_REGION'] if following property is set
|
81
|
+
#
|
82
|
+
aws_region: #{default_suite_runner_configs['aws_region']}
|
83
|
+
EOS
|
84
|
+
puts doc
|
85
|
+
end
|
86
|
+
|
36
87
|
# suite_properties.each{ |a| a.keys.first }
|
37
88
|
|
38
89
|
# **********
|
@@ -51,6 +102,14 @@ namespace :suite do
|
|
51
102
|
|
52
103
|
end
|
53
104
|
|
105
|
+
# **********
|
106
|
+
desc "Syncrronize ec2 instance metadata to "
|
107
|
+
task "ec2-sync" do
|
108
|
+
aws_ssh_resolver="aws-ssh-resolver.rb"
|
109
|
+
sh "#{aws_ssh_resolver} aws --ssh-config-file #{suite_runner_configs['ssh_config_file']} --ssh-config-init #{suite_runner_configs['ssh_config_init']}"
|
110
|
+
end
|
111
|
+
|
112
|
+
|
54
113
|
# **********
|
55
114
|
all_suites = test_suites.suite_ids.map{ |id| "suite:" + id }
|
56
115
|
task :suites, :gen_opts do |t,args|
|
@@ -91,16 +150,36 @@ namespace :suite do
|
|
91
150
|
# find the stack name for suite
|
92
151
|
stack = test_suites.get_suite_stack_id( suite_id )
|
93
152
|
|
153
|
+
desc "#{suite_id} - syncrhornize #{suite_runner_configs['ssh_config_file']}"
|
154
|
+
task "#{suite_id}-sync", :gen_opts do |t,args|
|
155
|
+
ssh_client_config_synchronize( suite_runner_configs )
|
156
|
+
end
|
157
|
+
|
158
|
+
# json
|
159
|
+
task "#{suite_id}-json", :gen_opts do |t,args|
|
160
|
+
args.with_defaults( :gen_opts => "-m aws-must-templates" )
|
161
|
+
json_template="#{aws_must} gen #{stack}.yaml #{args.gen_opts}"
|
162
|
+
sh "#{json_template}"
|
163
|
+
end
|
164
|
+
|
165
|
+
|
166
|
+
desc "#{suite_id} - create stack '#{stack}', wait to complete, sync #{suite_runner_configs['ssh_config_file']}"
|
167
|
+
task "#{suite_id}-stack-start", :gen_opts do |t,args|
|
168
|
+
Rake::Task["suite:#{suite_id}-stack-create"].invoke(args.gen_opts)
|
169
|
+
Rake::Task["suite:#{suite_id}-stack-wait"].invoke()
|
170
|
+
Rake::Task["suite:#{suite_id}-sync"].invoke()
|
171
|
+
end
|
172
|
+
|
94
173
|
# **********
|
95
174
|
# Create stack for a suite
|
96
|
-
desc "
|
175
|
+
desc "#{suite_id} - create stack '#{stack}'"
|
97
176
|
task "#{suite_id}-stack-create", :gen_opts do |t,args|
|
98
177
|
args.with_defaults( :gen_opts => "-m aws-must-templates" )
|
99
178
|
json_template="#{aws_must} gen #{stack}.yaml #{args.gen_opts}"
|
100
179
|
sh "aws cloudformation create-stack --stack-name #{stack} --capabilities CAPABILITY_IAM --template-body \"$(#{json_template})\" --disable-rollback"
|
101
180
|
end
|
102
181
|
|
103
|
-
desc "
|
182
|
+
desc "#{suite_id} - wait stack #{stack} #{END_STATES.join(', ')} "
|
104
183
|
task "#{suite_id}-stack-wait" do
|
105
184
|
|
106
185
|
while true
|
@@ -123,7 +202,7 @@ namespace :suite do
|
|
123
202
|
|
124
203
|
# **********
|
125
204
|
# delete stack for a suite
|
126
|
-
desc "
|
205
|
+
desc "#{suite_id} - delete stack #{stack}"
|
127
206
|
task "#{suite_id}-stack-delete" do
|
128
207
|
sh "aws cloudformation delete-stack --stack-name #{stack}"
|
129
208
|
end
|
@@ -134,25 +213,28 @@ namespace :suite do
|
|
134
213
|
end
|
135
214
|
|
136
215
|
# **********
|
137
|
-
desc "
|
216
|
+
desc "#{suite_id} - show status for stack #{stack}"
|
138
217
|
task "#{suite_id}-stack-status" do
|
139
218
|
sh "aws cloudformation describe-stacks --stack-name #{stack}"
|
140
219
|
end
|
141
220
|
|
142
221
|
# **********
|
143
222
|
# Test common roles for suite
|
144
|
-
desc "
|
223
|
+
desc "#{suite_id} - common roles"
|
145
224
|
RSpec::Core::RakeTask.new( "#{suite_id}-common" ) do |t|
|
146
|
-
puts "------------------------------------------------------------------"
|
147
|
-
puts "suite=#{suite_id }"
|
148
225
|
|
149
|
-
|
150
|
-
|
226
|
+
set_rspec_task( t, suite_runner_configs, test_suites, suite_id )
|
227
|
+
|
228
|
+
# puts "------------------------------------------------------------------"
|
229
|
+
# puts "suite=#{suite_id }"
|
230
|
+
|
231
|
+
# # see spec/spec_helper.rb
|
232
|
+
# ENV['TARGET_SUITE_ID'] = suite_id
|
151
233
|
|
152
234
|
# test all roles for the instance
|
153
|
-
t.rspec_opts = rspec_opts( suite_id )
|
154
|
-
t.fail_on_error = false
|
155
|
-
t.ruby_opts= rspec_ruby_opts
|
235
|
+
# t.rspec_opts = rspec_opts( suite_id )
|
236
|
+
# t.fail_on_error = false
|
237
|
+
# t.ruby_opts= rspec_ruby_opts
|
156
238
|
# t.pattern = suite["roles"].map { |r| spec_pattern( r ) }.join(",")
|
157
239
|
t.pattern = test_suites.suite_role_ids( suite_id ).map{ |r| spec_pattern( r ) }.join(",")
|
158
240
|
|
@@ -161,18 +243,18 @@ namespace :suite do
|
|
161
243
|
|
162
244
|
|
163
245
|
# **********
|
164
|
-
# Run tasks for
|
246
|
+
# Run tasks for 'suite_id'
|
165
247
|
|
166
|
-
desc "
|
248
|
+
desc "#{suite_id} - #{test_suites.get_suite(suite_id)['desc']}"
|
167
249
|
suite_tasks =
|
168
250
|
[
|
169
251
|
"suite:report_dir",
|
170
252
|
[ "suite:#{suite_id}-stack-create", "gen_opts" ],
|
171
|
-
|
253
|
+
"suite:#{suite_id}-stack-wait",
|
254
|
+
"suite:#{suite_id}-sync",
|
172
255
|
] +
|
173
256
|
( Rake::Task.task_defined?( "suite:#{suite_id}-common" ) ? [ "suite:#{suite_id}-common" ] : [] ) +
|
174
|
-
|
175
|
-
( test_suites.suite_instance_ids( suite_id ).each.map{ |instance_id| "suite:#{suite_id}:" + instance_id } ) +
|
257
|
+
( test_suites.suite_instance_names( suite_id ).each.map{ |instance_name| "suite:#{suite_id}:" + instance_name } ) +
|
176
258
|
[ "suite:#{suite_id}-stack-delete" ]
|
177
259
|
|
178
260
|
task suite_id, :gen_opts do |ta,args|
|
@@ -185,6 +267,7 @@ namespace :suite do
|
|
185
267
|
taskname = task.shift
|
186
268
|
Rake::Task[taskname].invoke( *(task.select{ |arg_name| args[arg_name]}.map{ |arg_name| args[arg_name] }) )
|
187
269
|
else
|
270
|
+
taskname = task
|
188
271
|
Rake::Task[task].invoke( args )
|
189
272
|
end
|
190
273
|
failed_tasks << task unless ( $?.nil? || $?.success? )
|
@@ -192,7 +275,7 @@ namespace :suite do
|
|
192
275
|
# sh "rake #{t}; true"
|
193
276
|
rescue => e
|
194
277
|
puts "#{e.class}: #{e.message}"
|
195
|
-
failed_tasks <<
|
278
|
+
failed_tasks << taskname
|
196
279
|
# puts e.backtrace
|
197
280
|
puts "continue with next task"
|
198
281
|
end
|
@@ -213,37 +296,19 @@ namespace :suite do
|
|
213
296
|
namespace suite_id do
|
214
297
|
|
215
298
|
# suite["instances"].each do |instance_map|
|
216
|
-
test_suites.
|
299
|
+
test_suites.suite_instance_names( suite_id ).each do |instance_name|
|
217
300
|
|
218
|
-
#
|
219
|
-
# instance = instance_map[
|
301
|
+
# instance_name = instance_map.keys.first
|
302
|
+
# instance = instance_map[instance_name]
|
220
303
|
|
221
304
|
# **********
|
222
|
-
desc "
|
223
|
-
RSpec::Core::RakeTask.new(
|
224
|
-
|
225
|
-
puts "------------------------------------------------------------------"
|
226
|
-
puts "suite=#{suite_id }, instance=#{instance_id}"
|
227
|
-
|
228
|
-
# see spec/spec_helper.rb
|
229
|
-
ENV['TARGET_SUITE_ID'] = suite_id
|
230
|
-
ENV['TARGET_INSTANCE_ID'] = instance_id
|
231
|
-
|
232
|
-
t.rspec_opts = rspec_opts( suite_id, instance_id )
|
233
|
-
t.fail_on_error = false
|
234
|
-
t.ruby_opts= rspec_ruby_opts
|
235
|
-
|
236
|
-
# test all roles for the instance
|
237
|
-
pattern = test_suites.suite_instance_role_ids( suite_id, instance_id ).map{ |r| spec_pattern( r ) }.join(",")
|
238
|
-
raise <<-EOS if pattern.nil? || pattern.empty?
|
305
|
+
desc "#{suite_id} - test instance '#{instance_name}'"
|
306
|
+
RSpec::Core::RakeTask.new( instance_name ) do |t|
|
239
307
|
|
240
|
-
|
241
|
-
|
242
|
-
EOS
|
243
|
-
t.pattern = pattern
|
308
|
+
set_rspec_task( t, suite_runner_configs, test_suites, suite_id, instance_name )
|
244
309
|
|
245
310
|
end
|
246
|
-
end #
|
311
|
+
end # instance_names
|
247
312
|
end # ns suite_id
|
248
313
|
|
249
314
|
end # suite_properties.each
|
@@ -278,20 +343,57 @@ namespace :suite do
|
|
278
343
|
end
|
279
344
|
|
280
345
|
# to pass to rpsec
|
281
|
-
def rspec_opts( suite_id,
|
346
|
+
def rspec_opts( suite_id, instance_name=nil )
|
282
347
|
# "--format documentation"
|
283
|
-
# "--format progress --format documentation --out generated-docs/suites/#{suite_id}#{
|
284
|
-
"--format progress --format documentation --out #{suite_test_report_filepath( suite_id,
|
348
|
+
# "--format progress --format documentation --out generated-docs/suites/#{suite_id}#{ instance_name ? '-'+instance_name : ""}.txt"
|
349
|
+
"--format progress --format documentation --out #{suite_test_report_filepath( suite_id, instance_name )}"
|
285
350
|
end
|
286
351
|
|
287
|
-
def suite_test_report_filepath( suite_id,
|
288
|
-
"#{suite_test_report_dirpath()}/#{suite_id}#{
|
352
|
+
def suite_test_report_filepath( suite_id, instance_name=nil )
|
353
|
+
"#{suite_test_report_dirpath()}/#{suite_id}#{ instance_name ? '-' + instance_name : ""}.txt"
|
289
354
|
end
|
290
355
|
|
291
356
|
def suite_test_report_dirpath
|
292
357
|
"generated-docs/suites"
|
293
358
|
end
|
294
359
|
|
360
|
+
# read ec2 instance metadata && update 'ssh_config_file'
|
361
|
+
def ssh_client_config_synchronize( suite_runner_configs )
|
362
|
+
aws_ssh_resolver="aws-ssh-resolver.rb"
|
363
|
+
sh "#{aws_ssh_resolver} aws --ssh-config-file #{suite_runner_configs['ssh_config_file']} --ssh-config-init #{suite_runner_configs['ssh_config_init']}"
|
364
|
+
end
|
365
|
+
|
366
|
+
def set_rspec_task( t, suite_runner_configs, test_suites, suite_id, instance_name=nil )
|
367
|
+
|
368
|
+
puts "------------------------------------------------------------------"
|
369
|
+
puts "suite=#{suite_id } #{instance_name ? ' instance: ' + instance_name : ''}"
|
370
|
+
|
371
|
+
# see spec/spec_helper.rb
|
372
|
+
ENV['TARGET_SUITE_ID'] = suite_id
|
373
|
+
if instance_name then
|
374
|
+
ENV['TARGET_INSTANCE_NAME'] = instance_name
|
375
|
+
else
|
376
|
+
ENV.delete('TARGET_INSTANCE_NAME')
|
377
|
+
end
|
378
|
+
ENV['AWS_REGION'] = suite_runner_configs["aws_region"] if suite_runner_configs["aws_region"]
|
379
|
+
|
380
|
+
t.rspec_opts = rspec_opts( suite_id, instance_name )
|
381
|
+
t.fail_on_error = false
|
382
|
+
t.ruby_opts= rspec_ruby_opts
|
383
|
+
|
384
|
+
# test all roles for the instance
|
385
|
+
pattern = (instance_name ?
|
386
|
+
test_suites.suite_instance_role_ids( suite_id, instance_name ).map{ |r| spec_pattern( r ) }.join(",") :
|
387
|
+
test_suites.suite_role_ids( suite_id ).map{ |r| spec_pattern( r ) }.join(",") )
|
388
|
+
|
389
|
+
raise <<-EOS if pattern.nil? || pattern.empty?
|
390
|
+
|
391
|
+
No tests defined for an instance in suite=#{suite_id } #{instance_name ? ' for instance ' + instance_name : ''}
|
392
|
+
|
393
|
+
EOS
|
394
|
+
t.pattern = pattern
|
395
|
+
|
396
|
+
end
|
295
397
|
|
296
398
|
|
297
399
|
end # ns suite
|
@@ -53,7 +53,7 @@ module AwsMustTemplates
|
|
53
53
|
|
54
54
|
# ------------------------------------------------------------------
|
55
55
|
# return list of instanceid for a suite
|
56
|
-
def
|
56
|
+
def suite_instance_names( suite_id )
|
57
57
|
suite = get_suite( suite_id )
|
58
58
|
return nil unless suite
|
59
59
|
return suite["instances"] ? suite["instances"].map{ |instance_hash| instance_hash.keys.first } : []
|
@@ -75,21 +75,21 @@ module AwsMustTemplates
|
|
75
75
|
return suite_id
|
76
76
|
end
|
77
77
|
|
78
|
-
# return array of role_ids for '
|
79
|
-
def suite_instance_role_ids( suite_id,
|
80
|
-
roles = suite_instance_roles( suite_id,
|
78
|
+
# return array of role_ids for 'instance_name' in 'suite_id'
|
79
|
+
def suite_instance_role_ids( suite_id, instance_name )
|
80
|
+
roles = suite_instance_roles( suite_id, instance_name )
|
81
81
|
return roles unless roles
|
82
82
|
return roles.map{ |r| r.is_a?( Hash ) ? r.keys.first : r }
|
83
83
|
end
|
84
84
|
|
85
|
-
# return roles for '
|
86
|
-
def suite_instance_roles( suite_id,
|
87
|
-
instance = suite_instance( suite_id,
|
85
|
+
# return roles for 'instance_name' in 'suite_id'
|
86
|
+
def suite_instance_roles( suite_id, instance_name )
|
87
|
+
instance = suite_instance( suite_id, instance_name )
|
88
88
|
return nil unless instance
|
89
|
-
return [] unless instance[
|
90
|
-
return [] unless instance[
|
89
|
+
return [] unless instance[instance_name]
|
90
|
+
return [] unless instance[instance_name]["roles"]
|
91
91
|
# roles may be a hash or a string
|
92
|
-
return instance[
|
92
|
+
return instance[instance_name]["roles"]
|
93
93
|
end
|
94
94
|
|
95
95
|
|
@@ -98,11 +98,11 @@ module AwsMustTemplates
|
|
98
98
|
|
99
99
|
private
|
100
100
|
|
101
|
-
# instance sub document for `
|
102
|
-
def suite_instance( suite_id,
|
101
|
+
# instance sub document for `instance_name` in `suite_id`
|
102
|
+
def suite_instance( suite_id, instance_name )
|
103
103
|
suite = get_suite( suite_id )
|
104
104
|
return nil unless suite && suite["instances"]
|
105
|
-
return suite["instances"].select { |i| i.keys.first ==
|
105
|
+
return suite["instances"].select { |i| i.keys.first == instance_name }.first
|
106
106
|
end
|
107
107
|
|
108
108
|
|