serverspec_launcher 0.2.1 → 0.2.3

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
  SHA256:
3
- metadata.gz: 76cfad81b886a35a1ac5a27b3e6d2e756d7c46b8d3e32e4d6c8eb661220414bf
4
- data.tar.gz: fb6bd787d1246aad83ac4e89a504be1c9a0d47c6f1369c038a59760dede06718
3
+ metadata.gz: 217a10415a16256a4478b48180e91464a29a4f209e404eb61242b199468838dc
4
+ data.tar.gz: 55ecc7919b6656d639dc7394e325ccfbc4926055b54d7ee9ec18cd3bbae3f200
5
5
  SHA512:
6
- metadata.gz: 9a719d32252a27fdf36853e46730f823d136b4432aea72a028643395b2de1cd99ea9ab41e3a5fe34d74ea25f9f21a521119dabd4ad442f1d5120448473e759bd
7
- data.tar.gz: 5657731b4a4fd10086d0f4aed6e89c7d4348b6ddd361cde408477dd60524e8f42500e4fad7f8d8f8e57b8666a43dd78e9eba0c6fcd3515c9e5ce202bc5f3f14a
6
+ metadata.gz: 4a9e79d1fccd7615c1152ffaaab40ed94ae5e2a9cc2c018f8f46475bb7e942314e2357ad217118b7d304ea46e4eba429a7998a113083b02d512013bf734c8dbc
7
+ data.tar.gz: b2ac6435e1e44084e60b94f4809db2ab6e0f97a476122d6166ea7af308d5650c4e7473a36af6b724df459d919786f3d6fbe237b478cb9d4a43b7487de0a2485a
data/README.md CHANGED
@@ -1,8 +1,9 @@
1
1
  # serverspec_launcher
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/serverspec_launcher`. To experiment with that code, run `bin/console` for an interactive prompt.
3
+ Serverspec launcher is utility for managing serverspec tests across servers, virtual machines,
4
+ and containers using a YAML based configuration files.
4
5
 
5
- TODO: Delete this and the text above, and describe your gem
6
+ It allows for spec files (or lists of shared behaviours) to be ran across groups of servers.
6
7
 
7
8
  ## Installation
8
9
 
@@ -22,7 +23,291 @@ Or install it yourself as:
22
23
 
23
24
  ## Usage
24
25
 
25
- TODO: Write usage instructions here
26
+ ### Setup
27
+
28
+ Run ```serverspec_launcher init``` from your applications root directory then add:
29
+
30
+ to spec/spec_helper.rb
31
+ ```ruby
32
+ require 'serverspec_launcher/spec_helper'
33
+ ```
34
+ to Rakefile
35
+ ```ruby
36
+ require 'serverspec_launcher/rake_tasks'
37
+ ```
38
+
39
+ ### properties.yml
40
+ The properties.yml file contains the configuration for your test setup, it consists of a number of sections.
41
+
42
+ ##### targets
43
+ The target section defines the targets (server, container), under test and consists of one or more hashes
44
+ defining the tests. Serverspec launcher will generate a rake task for each target it finds within
45
+ the target section, and a task for any hosts specifed within the targets config.
46
+
47
+ Each target consists of:
48
+
49
+ targetname (hash key): (required) The name of the target
50
+ * backend: (optional) Which backend to run against, supported backend are ssh, exec, docker, and vagrant. Windows based backend will be availible in future versions
51
+ * user: (optional) what user to run the tests as, Defaults to current user
52
+ * hosts: (optional) list or single value specifying the hostname(s) to run this against. defaults to target name
53
+ * spec_type: (optional) which spec file from the spec directory to execute against the target (do not include the _spec.rb). Defaults to role
54
+ * roles: (optional/mandatory if using role spec_type) list of shared behaviors (see below), to run against the target
55
+ * variables: (optional) hash of variables available to the the tests. Each variable specified here will be availible as property[:variables][:name_of_variable].
56
+ Any values specified here will overwrite environment level(not to be confused with environment variables), and global level variables
57
+ * environment: (optional) hash of environment variables which will be set on the target, environment level(not to be confused with environment variables), and global level environment varaibles(see below) that have previously defined values will be overwritten
58
+ * fail_on_err: Stop running the tests if the target fails its checks
59
+
60
+ Example :
61
+
62
+ This would create the rake tasks serverspec:webservers, serverspec:webservers:webserver1 and serverspec:webservers:webserver2
63
+ ```yaml
64
+ targets:
65
+ webservers: # the name of the target
66
+ backend: ssh # use the 'ssh' backend.
67
+ user: ec2-user
68
+ hosts:
69
+ - webserver1
70
+ - webserver2
71
+ spec_type: webserver
72
+ ```
73
+
74
+ ##### environments
75
+ serverspec_launcher supports the concept of environments. Environments are groups of targets organised as a named entity, i.e. test or qa.
76
+
77
+ An environment consists of the following:
78
+
79
+ environment name (hash key): (required) the name of the environment
80
+ * targets: a hash of targets (see above for target definition)
81
+ * variables: (optional) hash of variables available to the the tests. Each variable specified here will be availible as property[:variables][:name_of_variable].
82
+ Any values specified here will override global level variables previously defined.
83
+ * environment: (optional) hash of environment variables which will be set on the target, global level environment varaibles(see below) that have previously defined values will be overwritten
84
+
85
+ Example:
86
+ ```yaml
87
+ environments:
88
+ qa:
89
+ targets:
90
+ webservers: &webservers
91
+ hosts:
92
+ - web1.qa.domain
93
+ - web2.qa.domain
94
+ variables:
95
+ some_thing: new value # Override variable
96
+ variables:
97
+ my_var: enviroment value # Override global variable
98
+ some_thing: a value
99
+
100
+ performance:
101
+ targets:
102
+ webservers:
103
+ # Yaml anchors are supported
104
+ <<: *webservers
105
+ hosts:
106
+ - web1.perf.domain
107
+ - web2.perf.domain
108
+ - web3.perf.domain
109
+ - web4.perf.domain
110
+ ```
111
+ ##### options
112
+ A hash of options to pass to serverspec_launcher
113
+
114
+ * fail_on_err: (optional) stop testing after the first target failure, defaults to true
115
+ * color: (optional) colorize the output, defaults to true
116
+ * formatters: (optional) list of RSpec formatter to process the results with. Supported formatters are:
117
+
118
+ - docs RSpec Documentation Formatter writing to file reports/<target>.docs
119
+ - docs_screen - RSpec Documentation Formatter writing to screen
120
+ - tick - Tick/Cross output to screen
121
+ - tick_file - Tick/Cross output to file reports/<target>.tick
122
+ - html - HTML Reports
123
+ - junit - Unit Reports (useful for jenkins jobs)
124
+ - html_pretty - Pretty HTML Reports
125
+ - json - JSON Output
126
+ - progress - RSpec .F* progress output
127
+
128
+ Example:
129
+ ```yaml
130
+ options:
131
+ fail_on_err: false
132
+ colorize: true
133
+ formatters:
134
+ - tick
135
+ - docs
136
+
137
+ ```
138
+ ##### variables
139
+ A hash containing key value pairs. Each entry will be available as property[:variables][:<key>]
140
+
141
+ Example:
142
+ ```yaml
143
+ variables:
144
+ my_var: some value
145
+ ```
146
+ ##### environment
147
+ A hash containing key value pairs. Each entry will be available as an envirment variable on the target
148
+ Example:
149
+ ```yaml
150
+ environment:
151
+ JAVA_HOME: /usr/lib/java-1.7
152
+ ```
153
+ ##### Complete Example
154
+ ```yaml
155
+ options:
156
+ # Stop the test on the first failure (default: true)
157
+ fail_on_err: true
158
+ # Specify output format defaults is docs_screen multiple formatters can be specified
159
+ formaters:
160
+ # RSpec Documentation Formatter writing to file reports/<target>.docs
161
+ - docs
162
+ # RSpec Documentation Formatter writing to screen
163
+ - docs_screen
164
+ # Tick/Cross output to screen
165
+ - tick
166
+ # Tick/Cross output to file reports/<target>.tick
167
+ - tick_file
168
+ # JUnit Reports
169
+ - junit
170
+ # HTML Reports
171
+ - html
172
+ # Pretty HTML Reports
173
+ - html_pretty
174
+ # JSON Output
175
+ - json
176
+ # RSpec .F* progress bar
177
+ - progress
178
+ # Use colorized output (default: true)
179
+ color: false
180
+
181
+ # Load shared examples from third party gems, useful for sharing infrastucture tests
182
+ # across projects
183
+ shared_example_gems:
184
+ - my_shared_examples
185
+
186
+ # Specify environment variables used on the hosts when testing
187
+ # these are available as ENV['<var name>'] from the tests
188
+ environment:
189
+ SOMEVAR: some value
190
+
191
+ # Specify variable to be used in the tests
192
+ # these are available from the tests as property[:variables][:<variable name>]
193
+ variables:
194
+ my_var: some value
195
+
196
+
197
+ # Target Based Testing
198
+ # For each target specified here there will be a rake task defined which can be invoked via 'serverspec:<target name>'.
199
+ # Targets with multiple hosts will also have 'serverspec:<target name>:<hostname>' defined for each host.
200
+ # Running 'serverspec:<target name>' will execute against all hosts in the target
201
+ # Running the 'serverspec' rake task will invoke all targets and environments
202
+
203
+ targets:
204
+ # Running against a host via ssh
205
+ ssh-example:
206
+ backend: ssh
207
+ # specify host if left blank will use target name as hostname
208
+ hosts: raspberrypi
209
+ # uses specific user
210
+ user: pi
211
+ # run spec file spec/pi_spec.rb
212
+ spec_type: pi
213
+
214
+ # Running against multiple hosts via ssh
215
+ ssh-multi-host-example:
216
+ # Dont really need to specify ssh backend as it is the default but including for completeness
217
+ hosts:
218
+ - raspberrypi
219
+ - blueberrypi
220
+ # uses specific user
221
+ user: pi
222
+ # run spec file spec/pi_spec.rb
223
+ spec_type: pi
224
+ # Don't fail the run if the target fails (if blank uses the global value which defaults to true)
225
+ fail_on_err: true
226
+
227
+ # Run against local host
228
+ exec-example:
229
+ backend: exec
230
+ # Run spec file spec/localhost_spec.rb
231
+ spec_type: localhost
232
+ # Specify variable to be used in tests as property[:variables][:<variable name>]
233
+ variables:
234
+ # Specify a new variable
235
+ some_var: some value
236
+ # Override an existing vale
237
+ my_var: new value
238
+
239
+ # Run tests against a docker images
240
+ docker-image-example:
241
+ backend: docker
242
+ # Run against the mongo docker image from docker hub
243
+ docker_image: mongo
244
+ # Use shared behaviors loaded from spec/shared/.rb
245
+ roles:
246
+ - database::mongo
247
+
248
+ # Run tests against a running docker container
249
+ docker-container-examples:
250
+ backend: docker
251
+ # Run against container named jenkins
252
+ docker_container: jenkins
253
+ # Explicitly specify the role spec file spec/role_spec.rb which should be generated by 'serverspec_launcher init'
254
+ # This isn't really needed as role is the default spec_type
255
+ spec_type: role
256
+ roles:
257
+ # Run role with in context
258
+ - name: build_tools::jenkins
259
+ description: Jenkins Container
260
+
261
+ # Run tests against a docker build file
262
+ dockerfile-examples:
263
+ backend: docker
264
+ # Build image from Dockerfile in current directory
265
+ docker_build_dir: .
266
+ # Run spec file spec/docker_spec.rb
267
+ spec_type: docker
268
+
269
+
270
+ # Run tests against a vagrant file
271
+ vagrant-example:
272
+ backend: vagrant
273
+ roles:
274
+ - debug::environment_vars
275
+ environment:
276
+ # This environment var will only be availble to this target
277
+ MY_VAR: my value
278
+ # Override a globally set environment var
279
+ SOMEVAR: some other value
280
+
281
+ environments:
282
+ qa:
283
+ variables:
284
+ # Override global variable
285
+ my_var: enviroment value
286
+ some_thing: a value
287
+
288
+ targets:
289
+ webservers: &webservers
290
+ hosts:
291
+ - web1.qa.domain
292
+ - web2.qa.domain
293
+ variables:
294
+ # Override variable
295
+ some_thing: new value
296
+
297
+ performance:
298
+ targets:
299
+ webservers:
300
+ # Yaml anchors are supported
301
+ <<: *webservers
302
+ hosts:
303
+ - web1.perf.domain
304
+ - web2.perf.domain
305
+ - web3.perf.domain
306
+ - web4.perf.domain
307
+ variables:
308
+ # Override variable
309
+ some_thing: new value
310
+ ```
26
311
 
27
312
  ## Development
28
313
 
data/Rakefile CHANGED
@@ -1,7 +1,13 @@
1
1
  # frozen_string_literal: true
2
2
  require 'bundler/gem_tasks'
3
3
  require 'rspec/core/rake_task'
4
+ require 'conventional_changelog'
4
5
 
5
6
  RSpec::Core::RakeTask.new(:spec)
6
7
 
7
8
  task default: :spec
9
+
10
+
11
+ task :changelog do
12
+ ConventionalChangelog::Generator.new.generate!
13
+ end
@@ -25,8 +25,6 @@ class ServerspecLauncherRakeTasks
25
25
  def load_tasks
26
26
  task serverspec: 'serverspec:all'
27
27
 
28
- debug_tasks
29
-
30
28
  namespace :serverspec do
31
29
  targets = @properties[:targets] || {}
32
30
  task all: targets.keys.map { |key| 'serverspec:' + key.to_s.split('.')[0] }
@@ -37,9 +35,13 @@ class ServerspecLauncherRakeTasks
37
35
 
38
36
  environments = @properties[:environments] || {}
39
37
  environments.keys.each do |key|
40
- environment = environments[key]
41
- environment[:targets].each do |target, hash|
42
- process_target("#{key}:#{target}", hash, 'environment')
38
+ task key.to_sym => "serverspec:#{key}:all"
39
+ namespace key.to_sym do
40
+ environment = environments[key]
41
+ task all: environment[:targets].map { |target, _hash| "serverspec:#{key}:#{target.to_s.split(':')[0].to_sym}" }
42
+ environment[:targets].each do |target, hash|
43
+ process_target("#{target}", hash, 'environment', key.to_s)
44
+ end
43
45
  end
44
46
  end
45
47
 
@@ -49,22 +51,23 @@ class ServerspecLauncherRakeTasks
49
51
  def task_array(key, spec_type, target, options)
50
52
  desc "Run serverspec to #{key}"
51
53
  task key.to_sym => "serverspec:#{key}:all"
52
- namespace key.to_sym do
53
- task all: target[:hosts].map { |host| "serverspec:#{key}:#{host.split('.')[0].to_sym}" }
54
- target[:hosts].each do |host|
55
- task_name = "#{key}:#{host || target[:name]}"
56
- rake_task(host, key, task_name, spec_type, options)
54
+ namespace key.to_sym do
55
+ task all: target[:hosts].map { |host| "serverspec:#{key}:#{host.split(':')[0].to_sym}" }
56
+ target[:hosts].each do |host|
57
+ task_name = "#{host || target[:name]}"
58
+ rake_task(host, key, task_name, spec_type, options)
59
+ end
57
60
  end
58
- end
59
61
  end
60
62
 
61
63
  def rake_task(host, key, task_name, spec_type, options = {})
62
64
  desc "Run serverspec to #{key}"
63
- RSpec::Core::RakeTask.new(host.to_s.split('.')[0].to_sym) do |t|
65
+ RSpec::Core::RakeTask.new(task_name.to_s.to_sym) do |t|
64
66
  ENV['TARGET_HOST'] = host.to_s
65
67
  ENV['TARGET'] = key.to_s
66
68
  ENV['TASK_NAME'] = task_name.to_s
67
69
  ENV['TASK_SOURCE'] = options[:source]
70
+ ENV['TASK_ENV'] = options[:environment]
68
71
  t.pattern = "spec/#{spec_type}_spec.rb"
69
72
  t.fail_on_error = options[:fail_on_err]
70
73
  set_formatters(task_name, options, t)
@@ -129,16 +132,16 @@ class ServerspecLauncherRakeTasks
129
132
 
130
133
  private
131
134
 
132
- def process_target(key, target, task_source = 'target')
135
+ def process_target(key, target, task_source = 'target', environment = nil)
133
136
  options = {
134
137
  fail_on_err: target[:fail_on_err] || @fail_on_err,
135
138
  formatters: target[:formatters] || @formatters,
136
139
  color: target[:color].nil? ? @colorize : target[:color],
137
- source: task_source
140
+ source: task_source,
141
+ environment: environment
138
142
  }
139
143
  spec_type = target[:spec_type] || 'role'
140
144
  if target[:hosts].is_a?(Array)
141
-
142
145
  task_array(key, spec_type, target, options)
143
146
  elsif target[:hosts]
144
147
  host = target[:hosts]
@@ -22,22 +22,23 @@ class SpecHelper
22
22
 
23
23
  attr_reader :properties, :target_properties, :target_variables
24
24
 
25
- def initialize(host = ENV['TARGET_HOST'], target = ENV['TARGET'], properties = nil, task_source = ENV['TASK_SOURCE'])
25
+ def initialize(host = ENV['TARGET_HOST'], target = ENV['TARGET'], properties = nil, task_source = ENV['TASK_SOURCE'], environment = ENV['TASK_ENV'])
26
26
  @host = host
27
27
  @target = target
28
28
  @source = task_source
29
+ @environment = ENV['TASK_ENV']
29
30
  load_properties properties
30
31
  end
31
32
 
32
33
  def load_properties(properties = nil)
33
34
  @properties = properties ? properties.deep_symbolize_keys : YAML.load_file('properties.yml').deep_symbolize_keys
34
- if @target.include? ':'
35
- @target_properties = @properties[:environments][@target.split(':')[0].to_sym][:targets][@target.split(':')[1].to_sym]
35
+ if @source == 'environment'
36
+ @target_properties = @properties[:environments][@environment.to_sym][:targets][@target.to_sym]
36
37
  else
37
38
  @target_properties = @properties[:targets][@target.to_sym]
38
39
  end
39
40
  if @source == 'environment'
40
- vars = @properties[:environments][@target.split(':')[0].to_sym][:variables] ? @properties[:environments][@target.split(':')[0].to_sym][:variables] : {}
41
+ vars = @properties[:environments][@environment.to_sym][:variables] ? @properties[:environments][@environment.to_sym][:variables] : {}
41
42
  @target_variables = @properties[:variables] ? @properties[:variables].deep_merge(vars) : {}.deep_merge(vars)
42
43
  else
43
44
  @target_variables = @properties[:variables] ? @properties[:variables] : {}
@@ -76,6 +77,7 @@ class SpecHelper
76
77
  end
77
78
 
78
79
  options[:user] ||= ssh_user
80
+ options[:keys] = [@target_properties[:identity_file]] if @target_properties[:identity_file]
79
81
 
80
82
  set :host, options[:host_name] || @host
81
83
  set :ssh_options, options
@@ -149,8 +151,8 @@ class SpecHelper
149
151
  end
150
152
  end
151
153
 
152
- def self.load(host = ENV['TARGET_HOST'], target = ENV['TARGET'], properties = nil, task_source = ENV['TASK_SOURCE'])
153
- helper = SpecHelper.new host, target, properties, task_source
154
+ def self.load(host = ENV['TARGET_HOST'], target = ENV['TARGET'], properties = nil, task_source = ENV['TASK_SOURCE'], environment = '')
155
+ helper = SpecHelper.new host, target, properties, task_source, environment
154
156
  props = helper.properties[:shared_example_gems] || []
155
157
  helper.load_shared_examples props
156
158
  helper.setup_backend
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module ServerspecLauncher
3
- VERSION = '0.2.1'
3
+ VERSION = '0.2.3'
4
4
  end
@@ -30,6 +30,7 @@ Gem::Specification.new do |spec|
30
30
  spec.add_development_dependency 'simplecov'
31
31
  spec.add_development_dependency 'debase'
32
32
  spec.add_development_dependency 'ruby-debug-ide', '0.7.0.beta6'
33
+ spec.add_development_dependency 'conventional-changelog'
33
34
  spec.add_runtime_dependency 'serverspec'
34
35
  spec.add_runtime_dependency 'rspec_junit_formatter'
35
36
  spec.add_runtime_dependency 'rspec-tick-formatter', '0.1.3'
@@ -1,5 +1,4 @@
1
1
  ---
2
-
3
2
  options:
4
3
  # Stop the test on the first failure (default: true)
5
4
  fail_on_err: true
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: serverspec_launcher
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Wardrobe
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-09-22 00:00:00.000000000 Z
11
+ date: 2018-11-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -108,6 +108,20 @@ dependencies:
108
108
  - - '='
109
109
  - !ruby/object:Gem::Version
110
110
  version: 0.7.0.beta6
111
+ - !ruby/object:Gem::Dependency
112
+ name: conventional-changelog
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
111
125
  - !ruby/object:Gem::Dependency
112
126
  name: serverspec
113
127
  requirement: !ruby/object:Gem::Requirement