kitchen-verifier-serverspec 0.1.1 → 0.2.0
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 +28 -6
- data/lib/kitchen/verifier/serverspec.rb +119 -67
- data/lib/kitchen/verifier/serverspec_version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 0a15d723ec9a15097cd9937d8903374c30408438
|
|
4
|
+
data.tar.gz: f2201b8fa6d7621adb32f48f472341ed009b71a9
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: f48925f82a68c43bbf635c13e452433633a03fc4daca10e2ca662ea23e5c55b1c1bd7ea192b77980d6ad10d78417f05518979c88c08ce2e8664e0975088446df
|
|
7
|
+
data.tar.gz: a19a8ac674eba1cc0fd7e636c5d0ec018da585fce00e1fac76b4f138bf113c07f5cad6776463a17c5a9b9030bef1909ea888a144bb6c6c61602d9a07eaf5793e
|
data/README.md
CHANGED
|
@@ -6,9 +6,8 @@
|
|
|
6
6
|
|
|
7
7
|
A Test Kitchen Serverspec Verifer without having to transit the Busser layer.
|
|
8
8
|
|
|
9
|
-
This
|
|
10
|
-
|
|
11
|
-
don't cover all the possible options yet.
|
|
9
|
+
This supports running supports running serverspec but remotely on the server and locally on your workstation.
|
|
10
|
+
In the next version runners will be supported to provide logic to run serverspec initially supporting ansiblespec.
|
|
12
11
|
|
|
13
12
|
|
|
14
13
|
## Installation
|
|
@@ -25,7 +24,8 @@ Or install it yourself as:
|
|
|
25
24
|
|
|
26
25
|
$ gem install kitchen-verifier-serverspec
|
|
27
26
|
|
|
28
|
-
When it runs it install serverspec on the remote server
|
|
27
|
+
When it runs it install serverspec on the remote server or the workstation if remote_exec set to false.
|
|
28
|
+
This can be configured by passing a Gemfile like this:
|
|
29
29
|
|
|
30
30
|
```
|
|
31
31
|
source 'https://rubygems.org'
|
|
@@ -34,7 +34,7 @@ gem 'net-ssh','~> 2.9'
|
|
|
34
34
|
gem 'serverspec'
|
|
35
35
|
```
|
|
36
36
|
|
|
37
|
-
this allows extra dependencies to be specified and the version of serverspec specified.
|
|
37
|
+
this allows extra dependencies to be specified and the version of serverspec specified.
|
|
38
38
|
|
|
39
39
|
## Usage
|
|
40
40
|
|
|
@@ -52,7 +52,7 @@ suites:
|
|
|
52
52
|
- modules/mycompany_base/spec/acceptance/base_spec.rb
|
|
53
53
|
```
|
|
54
54
|
|
|
55
|
-
See example [https://github.com/neillturner/
|
|
55
|
+
See example [https://github.com/neillturner/puppet_repo](https://github.com/neillturner/puppet_repo)
|
|
56
56
|
|
|
57
57
|
or with environment variables
|
|
58
58
|
|
|
@@ -73,12 +73,34 @@ suites:
|
|
|
73
73
|
SSH_KEY: 'spec/tomcat_private_key.pem'
|
|
74
74
|
```
|
|
75
75
|
|
|
76
|
+
or run on your workstation
|
|
77
|
+
|
|
78
|
+
```yaml
|
|
79
|
+
verifier:
|
|
80
|
+
name: serverspec
|
|
81
|
+
remote_exec: false
|
|
82
|
+
|
|
83
|
+
suites:
|
|
84
|
+
- name: base
|
|
85
|
+
provisioner:
|
|
86
|
+
custom_facts:
|
|
87
|
+
role_name1: base
|
|
88
|
+
verifier:
|
|
89
|
+
patterns:
|
|
90
|
+
- modules_mycompany/mycompany_base/spec/acceptance/base_local_spec.rb
|
|
91
|
+
env_vars:
|
|
92
|
+
TARGET_HOST: 127.0.0.1
|
|
93
|
+
TARGET_PORT: 2222
|
|
94
|
+
LOGIN_USER: vagrant
|
|
95
|
+
SSH_KEY: 'c:/repository/puppet_repo/private_key.pem'
|
|
96
|
+
```
|
|
76
97
|
|
|
77
98
|
# Serverspec Verifier Options
|
|
78
99
|
|
|
79
100
|
key | default value | Notes
|
|
80
101
|
----|---------------|--------
|
|
81
102
|
sleep | 0 |
|
|
103
|
+
remote_exec | true | specify false to run serverspec on workstation
|
|
82
104
|
serverspec_command | nil | custom command to run serverspec
|
|
83
105
|
format | 'documentation' | format of serverspec output
|
|
84
106
|
color | true | enable color in the output
|
|
@@ -17,7 +17,6 @@ require 'kitchen/verifier/base'
|
|
|
17
17
|
module Kitchen
|
|
18
18
|
module Verifier
|
|
19
19
|
# Serverspec verifier for Kitchen.
|
|
20
|
-
#
|
|
21
20
|
class Serverspec < Kitchen::Verifier::Base
|
|
22
21
|
require 'mixlib/shellout'
|
|
23
22
|
|
|
@@ -54,7 +53,9 @@ module Kitchen
|
|
|
54
53
|
conn.execute(serverspec_commands)
|
|
55
54
|
end
|
|
56
55
|
else
|
|
57
|
-
|
|
56
|
+
config[:default_path] = Dir.pwd if config[:default_path] == '/tmp/kitchen'
|
|
57
|
+
install_command
|
|
58
|
+
serverspec_commands
|
|
58
59
|
end
|
|
59
60
|
debug("[#{name}] Verify completed.")
|
|
60
61
|
end
|
|
@@ -62,86 +63,124 @@ module Kitchen
|
|
|
62
63
|
## for legacy drivers.
|
|
63
64
|
def run_command
|
|
64
65
|
sleep_if_set
|
|
65
|
-
|
|
66
|
-
serverspec_commands
|
|
67
|
-
else
|
|
68
|
-
shellout
|
|
69
|
-
init
|
|
70
|
-
end
|
|
66
|
+
serverspec_commands
|
|
71
67
|
end
|
|
72
68
|
|
|
73
69
|
def setup_cmd
|
|
74
70
|
sleep_if_set
|
|
75
|
-
|
|
76
|
-
install_command
|
|
77
|
-
else
|
|
78
|
-
shellout
|
|
79
|
-
init
|
|
80
|
-
end
|
|
71
|
+
install_command
|
|
81
72
|
end
|
|
82
73
|
|
|
83
74
|
private
|
|
84
75
|
|
|
85
76
|
def serverspec_commands
|
|
86
|
-
if config[:
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
<<-INSTALL
|
|
92
|
-
if [ -d #{config[:default_path]} ]; then
|
|
93
|
-
cd #{config[:default_path]}
|
|
94
|
-
#{rspec_commands}
|
|
95
|
-
#{remove_default_path}
|
|
77
|
+
if config[:remote_exec]
|
|
78
|
+
if config[:serverspec_command]
|
|
79
|
+
<<-INSTALL
|
|
80
|
+
#{config[:serverspec_command]}
|
|
81
|
+
INSTALL
|
|
96
82
|
else
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
83
|
+
<<-INSTALL
|
|
84
|
+
if [ -d #{config[:default_path]} ]; then
|
|
85
|
+
cd #{config[:default_path]}
|
|
86
|
+
#{rspec_commands}
|
|
87
|
+
#{remove_default_path}
|
|
88
|
+
else
|
|
89
|
+
echo "ERROR: Default path '#{config[:default_path]}' does not exist"
|
|
90
|
+
exit 1
|
|
91
|
+
fi
|
|
92
|
+
INSTALL
|
|
93
|
+
end
|
|
94
|
+
elsif config[:serverspec_command]
|
|
95
|
+
info("Running command: #{config[:serverspec_command]}")
|
|
96
|
+
system config[:serverspec_command]
|
|
97
|
+
else
|
|
98
|
+
c = rspec_commands
|
|
99
|
+
info("Running command: #{c}")
|
|
100
|
+
system c
|
|
101
101
|
end
|
|
102
102
|
end
|
|
103
103
|
|
|
104
104
|
def install_command
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
else
|
|
112
|
-
if [ -f /etc/system-release ] || [ grep -q 'Amazon Linux' /etc/system-release ]; then
|
|
105
|
+
if config[:remote_exec]
|
|
106
|
+
info('Installing ruby, bundler and serverspec')
|
|
107
|
+
<<-INSTALL
|
|
108
|
+
if [ ! $(which ruby) ]; then
|
|
109
|
+
echo '-----> Installing ruby, will try to determine platform os'
|
|
110
|
+
if [ -f /etc/centos-release ] || [ -f /etc/redhat-release ] || [ -f /etc/oracle-release ]; then
|
|
113
111
|
#{sudo_env('yum')} -y install ruby
|
|
114
112
|
else
|
|
115
|
-
|
|
113
|
+
if [ -f /etc/system-release ] || [ grep -q 'Amazon Linux' /etc/system-release ]; then
|
|
114
|
+
#{sudo_env('yum')} -y install ruby
|
|
115
|
+
else
|
|
116
|
+
#{sudo_env('apt-get')} -y install ruby
|
|
117
|
+
fi
|
|
116
118
|
fi
|
|
117
119
|
fi
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
120
|
+
#{install_bundler}
|
|
121
|
+
if [ -d #{config[:default_path]} ]; then
|
|
122
|
+
#{install_serverspec}
|
|
123
|
+
else
|
|
124
|
+
echo "ERROR: Default path '#{config[:default_path]}' does not exist"
|
|
125
|
+
exit 1
|
|
126
|
+
fi
|
|
127
|
+
INSTALL
|
|
128
|
+
else
|
|
129
|
+
info('Installing bundler and serverspec')
|
|
130
|
+
install_bundler
|
|
131
|
+
install_serverspec
|
|
132
|
+
end
|
|
127
133
|
end
|
|
128
134
|
|
|
129
135
|
def install_bundler
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
#{
|
|
133
|
-
|
|
134
|
-
|
|
136
|
+
if config[:remote_exec]
|
|
137
|
+
<<-INSTALL
|
|
138
|
+
if [ $(#{sudo('gem')} list bundler -i) == 'false' ]; then
|
|
139
|
+
#{sudo_env('gem')} install #{gem_proxy_parm} --no-ri --no-rdoc bundler
|
|
140
|
+
fi
|
|
141
|
+
INSTALL
|
|
142
|
+
else
|
|
143
|
+
begin
|
|
144
|
+
require 'bundler'
|
|
145
|
+
rescue LoadError
|
|
146
|
+
system `gem install --no-ri --no-rdoc bundler`
|
|
147
|
+
end
|
|
148
|
+
end
|
|
135
149
|
end
|
|
136
150
|
|
|
151
|
+
# rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
|
137
152
|
def install_serverspec
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
153
|
+
if config[:remote_exec]
|
|
154
|
+
bundler_cmd = "#{bundler_path}bundler"
|
|
155
|
+
<<-INSTALL
|
|
156
|
+
#{test_serverspec_installed}
|
|
157
|
+
#{install_gemfile}
|
|
158
|
+
#{sudo_env(bundler_cmd)} install --gemfile=#{config[:default_path]}/Gemfile
|
|
159
|
+
#{fi_test_serverspec_installed}
|
|
160
|
+
INSTALL
|
|
161
|
+
else
|
|
162
|
+
if config[:test_serverspec_installed]
|
|
163
|
+
begin
|
|
164
|
+
require 'serverspec'
|
|
165
|
+
return
|
|
166
|
+
rescue LoadError
|
|
167
|
+
info('serverspec not installed installing ...')
|
|
168
|
+
end
|
|
169
|
+
end
|
|
170
|
+
unless config[:gemfile]
|
|
171
|
+
gemfile = "#{config[:default_path]}/Gemfile"
|
|
172
|
+
File.open(gemfile, 'w') do |f|
|
|
173
|
+
f.write("source 'https://rubygems.org'\ngem 'net-ssh','~> 2.9.4'\ngem 'serverspec'")
|
|
174
|
+
end
|
|
175
|
+
end
|
|
176
|
+
gemfile = config[:gemfile] if config[:gemfile]
|
|
177
|
+
begin
|
|
178
|
+
system "bundler install --gemfile=#{gemfile}"
|
|
179
|
+
rescue
|
|
180
|
+
raise ActionFailed, 'Serverspec install failed'
|
|
181
|
+
end
|
|
182
|
+
nil
|
|
183
|
+
end
|
|
145
184
|
end
|
|
146
185
|
|
|
147
186
|
def install_gemfile
|
|
@@ -190,15 +229,28 @@ module Kitchen
|
|
|
190
229
|
|
|
191
230
|
def env_vars
|
|
192
231
|
return nil if config[:env_vars].none?
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
232
|
+
cmd = nil
|
|
233
|
+
if !config[:remote_exec]
|
|
234
|
+
config[:env_vars].map do |k, v|
|
|
235
|
+
info("Environment variable #{k} value #{v}")
|
|
236
|
+
ENV[k.to_s] = v.to_s
|
|
237
|
+
end
|
|
238
|
+
else
|
|
239
|
+
cmd = config[:env_vars].map { |k, v| "#{k}=#{v}" }.join(' ')
|
|
240
|
+
debug(cmd)
|
|
241
|
+
end
|
|
242
|
+
cmd
|
|
196
243
|
end
|
|
197
244
|
|
|
198
245
|
def sudo_env(pm)
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
246
|
+
if config[:remote_exec]
|
|
247
|
+
s = https_proxy ? "https_proxy=#{https_proxy}" : nil
|
|
248
|
+
p = http_proxy ? "http_proxy=#{http_proxy}" : nil
|
|
249
|
+
p || s ? "#{sudo('env')} #{p} #{s} #{pm}" : sudo(pm).to_s
|
|
250
|
+
else
|
|
251
|
+
# TODO: handle proxies
|
|
252
|
+
pm
|
|
253
|
+
end
|
|
202
254
|
end
|
|
203
255
|
|
|
204
256
|
def bundler_path
|
|
@@ -233,11 +285,11 @@ module Kitchen
|
|
|
233
285
|
print '.'
|
|
234
286
|
sleep 1
|
|
235
287
|
end
|
|
236
|
-
puts
|
|
237
288
|
end
|
|
238
289
|
|
|
239
|
-
def shellout
|
|
240
|
-
|
|
290
|
+
def shellout(command)
|
|
291
|
+
info("Running command: #{command}")
|
|
292
|
+
cmd = Mixlib::ShellOut.new(command, config[:shellout_opts])
|
|
241
293
|
cmd.live_stream = config[:live_stream]
|
|
242
294
|
cmd.run_command
|
|
243
295
|
begin
|
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.
|
|
4
|
+
version: 0.2.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-
|
|
11
|
+
date: 2016-02-23 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: test-kitchen
|