kitchen-verifier-serverspec 0.2.0 → 0.3.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: 0a15d723ec9a15097cd9937d8903374c30408438
4
- data.tar.gz: f2201b8fa6d7621adb32f48f472341ed009b71a9
3
+ metadata.gz: 9ebc99abf783948176f30b6938dcd298a74a4ace
4
+ data.tar.gz: 05f588ddbd0119ecebf5b29a0534052122a09991
5
5
  SHA512:
6
- metadata.gz: f48925f82a68c43bbf635c13e452433633a03fc4daca10e2ca662ea23e5c55b1c1bd7ea192b77980d6ad10d78417f05518979c88c08ce2e8664e0975088446df
7
- data.tar.gz: a19a8ac674eba1cc0fd7e636c5d0ec018da585fce00e1fac76b4f138bf113c07f5cad6776463a17c5a9b9030bef1909ea888a144bb6c6c61602d9a07eaf5793e
6
+ metadata.gz: ef57b1eeb3b051359b865c77ecf65f2bd2145b0bfea07198410fa19f5d7dd99f5278b718c5ba6707c2f547078fb695a8cfc1c149e35ceda568ad96ff47c9efdb
7
+ data.tar.gz: 485b3b455ae5840f0dab7e740b9090991a1bc2958cf6fc13725e1ea890290345152c31309679380b83e847787b778babc990e8bd6dd21bbb2e0dfa08013cea95
data/README.md CHANGED
@@ -95,6 +95,32 @@ suites:
95
95
  SSH_KEY: 'c:/repository/puppet_repo/private_key.pem'
96
96
  ```
97
97
 
98
+ # Custom Runners
99
+
100
+ Custon runners can be defined and run to provide further customization.
101
+ There is a runner that automatically runs the ansiblespec files for all the hosts from the
102
+ ansible provisioner.
103
+
104
+ This can be run by specifying in the kitchen yml file:
105
+
106
+ ```yaml
107
+ verifier:
108
+ name: serverspec
109
+
110
+ suites:
111
+ - name: base
112
+ verifier:
113
+ runner_url: https://raw.githubusercontent.com/neillturner/serverspec-runners/master/ansiblespec_runner.rb
114
+ require_runner: true
115
+ bundler_path: '/usr/local/bin'
116
+ rspec_path: '/home/vagrant/bin'
117
+ env_vars:
118
+ TARGET_HOST: 172.28.128.7
119
+ LOGIN_USER: vagrant
120
+ SSH_KEY: 'spec/tomcat_private_key.pem'
121
+ ```
122
+
123
+
98
124
  # Serverspec Verifier Options
99
125
 
100
126
  key | default value | Notes
@@ -117,7 +143,8 @@ sudo | nil | use sudo to run commands
117
143
  env_vars | {} | environment variable to set for rspec
118
144
  bundle_path | nil | path for bundler command
119
145
  rspec_path | nil | path for rspec command
120
-
146
+ runner_url | https://raw.githubusercontent.com /neillturner/serverspec-runners/ master/ansiblespec_runner.rb | url for custom runner
147
+ require_runner | false | run the custom runner instead of rspec directly
121
148
 
122
149
  ## Contributing
123
150
 
@@ -41,6 +41,8 @@ module Kitchen
41
41
  default_config :env_vars, {}
42
42
  default_config :bundle_path, nil
43
43
  default_config :rspec_path, nil
44
+ default_config :require_runner, false
45
+ default_config :runner_url, 'https://raw.githubusercontent.com/neillturner/serverspec-runners/master/ansiblespec_runner.rb'
44
46
 
45
47
  # (see Base#call)
46
48
  def call(state)
@@ -120,6 +122,7 @@ module Kitchen
120
122
  #{install_bundler}
121
123
  if [ -d #{config[:default_path]} ]; then
122
124
  #{install_serverspec}
125
+ #{install_runner}
123
126
  else
124
127
  echo "ERROR: Default path '#{config[:default_path]}' does not exist"
125
128
  exit 1
@@ -129,6 +132,7 @@ module Kitchen
129
132
  info('Installing bundler and serverspec')
130
133
  install_bundler
131
134
  install_serverspec
135
+ install_runner
132
136
  end
133
137
  end
134
138
 
@@ -148,6 +152,20 @@ module Kitchen
148
152
  end
149
153
  end
150
154
 
155
+ def install_runner
156
+ if config[:require_runner]
157
+ if config[:remote_exec]
158
+ <<-INSTALL
159
+ if [ ! -f #{config[:default_path]}/#{runner_filename} ]; then
160
+ #{sudo_env('curl')} -o #{config[:default_path]}/#{runner_filename} #{config[:runner_url]}
161
+ fi
162
+ INSTALL
163
+ else
164
+ raise ActionFailed, 'Serverspec Runners only for remote execution'
165
+ end
166
+ end
167
+ end
168
+
151
169
  # rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
152
170
  def install_serverspec
153
171
  if config[:remote_exec]
@@ -222,9 +240,16 @@ module Kitchen
222
240
  end
223
241
 
224
242
  def rspec_commands
225
- rspec_cmd = "#{rspec_path}rspec"
226
243
  info('Running Serverspec')
227
- config[:patterns].map { |s| "#{env_vars} #{sudo_env(rspec_cmd)} #{color} -f #{config[:format]} --default-path #{config[:default_path]} #{config[:extra_flags]} -P #{s}" }.join('\n')
244
+ if config[:require_runner]
245
+ "#{env_vars} #{sudo_env(rspec_cmd)} #{color} -f #{config[:format]} --default-path #{config[:default_path]} #{rspec_path_option} #{config[:extra_flags]}"
246
+ else
247
+ config[:patterns].map { |s| "#{env_vars} #{sudo_env(rspec_cmd)} #{color} -f #{config[:format]} --default-path #{config[:default_path]} #{config[:extra_flags]} -P #{s}" }.join('\n')
248
+ end
249
+ end
250
+
251
+ def rspec_cmd
252
+ config[:require_runner] ? "ruby #{config[:default_path]}/#{runner_filename}" : "#{rspec_path}rspec"
228
253
  end
229
254
 
230
255
  def env_vars
@@ -261,6 +286,14 @@ module Kitchen
261
286
  config[:rspec_path] ? "#{config[:rspec_path]}/" : nil
262
287
  end
263
288
 
289
+ def rspec_path_option
290
+ config[:rspec_path] ? "--rspec-path #{config[:rspec_path]}/" : nil
291
+ end
292
+
293
+ def runner_filename
294
+ File.basename(config[:runner_url])
295
+ end
296
+
264
297
  def http_proxy
265
298
  config[:http_proxy]
266
299
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Kitchen
4
4
  module Verifier
5
- SERVERSPEC_VERSION = '0.2.0'.freeze
5
+ SERVERSPEC_VERSION = '0.3.0'.freeze
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kitchen-verifier-serverspec
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Neill Turner
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-02-23 00:00:00.000000000 Z
11
+ date: 2016-03-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: test-kitchen