sfn-serverspec 0.1.4 → 1.0.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
  SHA1:
3
- metadata.gz: 8d3b72ce916426b2f61d0bd4320710a4d6da2641
4
- data.tar.gz: 4925870d5dfa43ad2efa6ac166b44e2eb48289b4
3
+ metadata.gz: ccd4bbd9aa84c7c01f81362705ca87427f0f58c4
4
+ data.tar.gz: af2e752a8837ae830052777437c1629bf991bc83
5
5
  SHA512:
6
- metadata.gz: 0dff77605a821496db4cef14cf91f5f6d044092fb13b95041b52c35b9ea7006458558366e86b9054df752671adc5cc90170cb8511d43372696f3c44626c10a4d
7
- data.tar.gz: 6c0264e4022cb4afb548ac84693832bb0d6cd726f58a78396d690497ab0a05bb71b95c59b9f13e32344ad6c7ce3ea29d19a8061bdc7d051b867078af3da14e7f
6
+ metadata.gz: 5ef3581092910aeaf2bb8950eaf57decd5f1c3d198a0a2929aa53be89fe93c8daa1bb77d1cac29f8b442385a6eeef7be2621c33e3d6eca93e03f25c1d52c0c25
7
+ data.tar.gz: 3865714053ff9d2218468113107ced84bbb044e64a43b586743160b159e06a215b1e8d94d74451ccf8c7f9596b03f4f1597519a67ba1ce61b22fc2ff62bc4e2f
@@ -1,3 +1,8 @@
1
+ # v1.0.0
2
+ * Added support for validating compute resources in nested stacks (#5)
3
+ * Added alias for `after_update` callback (#6)
4
+ * Breaking: updated `sfn` dependency to >= 3.0, < 4.0 (#7)
5
+
1
6
  # v0.1.4
2
7
  * Relax sfn constraint to allow 2.0 versions
3
8
 
data/README.md CHANGED
@@ -11,6 +11,7 @@ Callbacks are configured via the `.sfn` configuration file. First, the callback
11
11
  ```ruby
12
12
  Configuration.new do
13
13
  callbacks do
14
+ # requiring sfn-serverspec here is optional when using bundler
14
15
  require ['sfn-serverspec']
15
16
  default ['serverspec_validator']
16
17
  end
@@ -66,12 +67,16 @@ The following configuration options specified at the resource level will overrid
66
67
 
67
68
  ### On-demand validation
68
69
 
69
- Provided that you are using Bundler, this callback also adds a `serverspec` command to sfn, enabling on-demand validation of a running stack. You'll want to configure sfn-serverspec thusly:
70
+ Provided that you are using Bundler, this callback also adds a `serverspec` command to sfn, enabling on-demand validation of a running stack. You'll want to add sfn-serverspec to your Gemfile thusly:
70
71
 
71
72
  ```ruby
72
- gem 'sfn-serverspec', :require => 'sfn-serverspec'
73
+ group :sfn do
74
+ gem 'sfn-serverspec'
75
+ end
73
76
  ```
74
77
 
78
+ Note that placing sfn and its friends in the `:sfn` group ensures that they'll be automatically `require`-d by sfn at run time.
79
+
75
80
  The `serverspec` command requires both a stack name and a template to use as the source of Serverspec configuration. The template may be provided via command line flag or interactive file path prompt:
76
81
 
77
82
  ```
@@ -44,94 +44,105 @@ module Sfn
44
44
  config.fetch(:sfn_serverspec, :ssh_key_passphrase, nil)
45
45
  )
46
46
 
47
- instances = expand_compute_resource(args.first[:api_stack], resource)
48
-
49
- instances.each do |instance|
50
- target_host = case ssh_proxy_command.nil?
51
- when true
52
- instance.addresses_public.first.address
53
- when false
54
- instance.addresses_private.first.address
55
- end
56
-
57
- begin
58
- rspec_config = RSpec.configuration
59
- rspec_config.reset
60
- rspec_config.reset_filters
61
- RSpec.world.reset
62
-
63
- rspec_formatter = RSpec::Core::Formatters::DocumentationFormatter.new(
64
- rspec_config.output_stream
65
- )
66
-
67
- rspec_reporter = RSpec::Core::Reporter.new(rspec_config)
68
-
69
- rspec_config.instance_variable_set(:@reporter, rspec_reporter)
70
- rspec_loader = rspec_config.send(:formatter_loader)
71
- rspec_notifications = rspec_loader.send(
72
- :notifications_for,
73
- RSpec::Core::Formatters::DocumentationFormatter
74
- )
75
- rspec_reporter.register_listener(
76
- rspec_formatter,
77
- *rspec_notifications
78
- )
79
-
80
- global_specs = [
81
- config.fetch(:sfn_serverspec, :global_spec_patterns, [])
82
- ].flatten.compact
83
-
84
- resource_specs = [
85
- resource_config.fetch(:spec_patterns, [])
86
- ].flatten.compact
87
-
88
- spec_patterns = global_specs + resource_specs
89
-
90
- ui.debug "spec loading patterns: #{spec_patterns.inspect}"
91
- ui.debug "using SSH proxy commmand #{ssh_proxy_command}" unless ssh_proxy_command.nil?
92
- ui.info "Serverspec validating #{instance.id} (#{target_host})"
93
-
94
- Specinfra.configuration.backend :ssh
95
- Specinfra.configuration.request_pty true
96
- Specinfra.configuration.host target_host
97
-
98
- connection_options = {
99
- user: resource_config.fetch(
100
- :ssh_user,
101
- config.fetch(:sfn_serverspec, :ssh_user, 'ec2-user')
102
- ),
103
- port: resource_config.fetch(
104
- :ssh_port,
105
- config.fetch(:sfn_serverspec, :ssh_port, 22)
47
+ target_stack = args.first[:api_stack]
48
+ nested_stacks = target_stack.nested_stacks
49
+
50
+ stacks = nested_stacks.empty? ? [target_stack] : nested_stacks
51
+
52
+ ui.debug "Expanded #{target_stack} to #{stacks.map(&:inspect).join(', ')}"
53
+
54
+ stacks.each do |s|
55
+ instances = expand_compute_resource(s, resource)
56
+
57
+ instances.each do |instance|
58
+ target_host = case ssh_proxy_command.nil?
59
+ when true
60
+ instance.addresses_public.first.address
61
+ when false
62
+ instance.addresses_private.first.address
63
+ end
64
+
65
+ begin
66
+ rspec_config = RSpec.configuration
67
+ rspec_config.reset
68
+ rspec_config.reset_filters
69
+ RSpec.world.reset
70
+
71
+ rspec_formatter = RSpec::Core::Formatters::DocumentationFormatter.new(
72
+ rspec_config.output_stream
106
73
  )
107
- }
108
74
 
109
- unless ssh_proxy_command.nil?
110
- connection_options[:proxy] = Net::SSH::Proxy::Command.new(ssh_proxy_command)
111
- ui.debug "using ssh proxy command: #{ssh_proxy_command}"
112
- end
75
+ rspec_reporter = RSpec::Core::Reporter.new(rspec_config)
113
76
 
114
- unless ssh_key_paths.empty?
115
- connection_options[:keys] = ssh_key_paths
116
- ui.debug "using ssh key paths #{connection_options[:keys]} exclusively"
117
- end
77
+ rspec_config.instance_variable_set(:@reporter, rspec_reporter)
78
+ rspec_loader = rspec_config.send(:formatter_loader)
79
+ rspec_notifications = rspec_loader.send(
80
+ :notifications_for,
81
+ RSpec::Core::Formatters::DocumentationFormatter
82
+ )
83
+ rspec_reporter.register_listener(
84
+ rspec_formatter,
85
+ *rspec_notifications
86
+ )
118
87
 
119
- unless ssh_key_passphrase.nil?
120
- connection_options[:passphrase] = ssh_key_passphrase
121
- end
88
+ global_specs = [
89
+ config.fetch(:sfn_serverspec, :global_spec_patterns, [])
90
+ ].flatten.compact
91
+
92
+ resource_specs = [
93
+ resource_config.fetch(:spec_patterns, [])
94
+ ].flatten.compact
122
95
 
123
- Specinfra.configuration.ssh_options connection_options
96
+ spec_patterns = global_specs + resource_specs
124
97
 
125
- RSpec::Core::Runner.run(spec_patterns.map { |p| Dir.glob(p) })
98
+ ui.debug "spec loading patterns: #{spec_patterns.inspect}"
99
+ ui.debug "using SSH proxy commmand #{ssh_proxy_command}" unless ssh_proxy_command.nil?
100
+ ui.info "Serverspec validating #{instance.id} (#{target_host})"
126
101
 
127
- rescue => e
128
- ui.error "Something unexpected happened when running rspec: #{e.inspect}"
102
+ Specinfra.configuration.backend :ssh
103
+ Specinfra::Backend::Ssh.clear
104
+ Specinfra.configuration.request_pty true
105
+ Specinfra.configuration.host target_host
106
+
107
+ connection_options = {
108
+ user: resource_config.fetch(
109
+ :ssh_user,
110
+ config.fetch(:sfn_serverspec, :ssh_user, 'ec2-user')
111
+ ),
112
+ port: resource_config.fetch(
113
+ :ssh_port,
114
+ config.fetch(:sfn_serverspec, :ssh_port, 22)
115
+ )
116
+ }
117
+
118
+ unless ssh_proxy_command.nil?
119
+ connection_options[:proxy] = Net::SSH::Proxy::Command.new(ssh_proxy_command)
120
+ ui.debug "using ssh proxy command: #{ssh_proxy_command}"
121
+ end
122
+
123
+ unless ssh_key_paths.empty?
124
+ connection_options[:keys] = ssh_key_paths
125
+ ui.debug "using ssh key paths #{connection_options[:keys]} exclusively"
126
+ end
127
+
128
+ unless ssh_key_passphrase.nil?
129
+ connection_options[:passphrase] = ssh_key_passphrase
130
+ end
131
+
132
+ Specinfra.configuration.ssh_options connection_options
133
+
134
+ RSpec::Core::Runner.run(spec_patterns.map { |p| Dir.glob(p) })
135
+
136
+ rescue => e
137
+ ui.error "Something unexpected happened when running rspec: #{e.inspect}"
138
+ end
129
139
  end
130
140
  end
131
141
  end
132
142
  end
133
143
 
134
144
  alias_method :after_serverspec, :after_create
145
+ alias_method :after_update, :after_create
135
146
 
136
147
  COMPUTE_RESOURCE_TYPES = ['AWS::EC2::Instance', 'AWS::AutoScaling::AutoScalingGroup']
137
148
 
@@ -149,6 +160,10 @@ module Sfn
149
160
  end
150
161
  end
151
162
 
163
+ def quiet
164
+ true unless config[:debug]
165
+ end
166
+
152
167
  private
153
168
 
154
169
  # look up stack resource by name, return array of expanded compute instances
@@ -161,6 +176,8 @@ module Sfn
161
176
  resource.logical_id == name
162
177
  end
163
178
 
179
+ return [] if compute_resource.nil?
180
+
164
181
  if compute_resource.within?(:compute, :servers)
165
182
  [compute_resource.expand]
166
183
  else
@@ -1,5 +1,5 @@
1
1
  # SfnServerspec internal constants
2
2
  module SfnServerspec
3
3
  # Current version
4
- VERSION = Gem::Version.new('0.1.4')
4
+ VERSION = Gem::Version.new('1.0.0')
5
5
  end
@@ -10,7 +10,7 @@ Gem::Specification.new do |s|
10
10
  s.description = 'Executes Serverspec assertions against stack compute resources'
11
11
  s.license = 'Apache-2.0'
12
12
  s.require_path = 'lib'
13
- s.add_runtime_dependency 'sfn', '>= 1.0', '< 3.0'
13
+ s.add_runtime_dependency 'sfn', '>= 3.0', '< 4.0'
14
14
  s.add_runtime_dependency 'serverspec', '~> 2.24'
15
15
  s.add_development_dependency 'rake'
16
16
  s.add_development_dependency 'rubocop', '~> 0.35.0'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sfn-serverspec
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Heavy Water Operations
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-01-22 00:00:00.000000000 Z
11
+ date: 2016-05-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sfn
@@ -16,20 +16,20 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '1.0'
19
+ version: '3.0'
20
20
  - - "<"
21
21
  - !ruby/object:Gem::Version
22
- version: '3.0'
22
+ version: '4.0'
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
26
26
  requirements:
27
27
  - - ">="
28
28
  - !ruby/object:Gem::Version
29
- version: '1.0'
29
+ version: '3.0'
30
30
  - - "<"
31
31
  - !ruby/object:Gem::Version
32
- version: '3.0'
32
+ version: '4.0'
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: serverspec
35
35
  requirement: !ruby/object:Gem::Requirement