kitchen-verifier-serverspec 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +84 -0
- data/kitchen-verifier-serverspec.gemspec +25 -0
- data/lib/kitchen/verifier/serverspec.rb +242 -0
- data/lib/kitchen/verifier/serverspec_version.rb +7 -0
- metadata +78 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 45596196f4147bbd86339157709190ad793aff46
|
4
|
+
data.tar.gz: 31b268ebeec5166107f965bbe2064331a902a4c0
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b9765cf70d0cea811609f74ee390c061ccdf7da528afcc271947be7c709ee00dc738961827b853ea6ac6ebd54f424fe3e211beb709676989b50eecb0f2d65909
|
7
|
+
data.tar.gz: 6aaddb1ef845aaf60d00c7660e8711d1f3fcd6987a3aaa0d4dd19544cf57f3210d491def18fab0948e03662ad601f464107b7ff579067eaaed44c8e86cfb76e8
|
data/README.md
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
[![Gem Version](https://badge.fury.io/rb/kitchen-verifier-serverspec.svg)](http://badge.fury.io/rb/kitchen-verifier-serverspec)
|
2
|
+
[![Gem Downloads](http://ruby-gem-downloads-badge.herokuapp.com/kitchen-verifier-serverspec?type=total&color=brightgreen)](https://rubygems.org/gems/kitchen-verifier-serverspec)
|
3
|
+
[![Build Status](https://travis-ci.org/neillturner/kitchen-verifier-serverspec.png)](https://travis-ci.org/neillturner/kitchen-verifier-serverspec)
|
4
|
+
|
5
|
+
# Kitchen::Verifier::Serverspec
|
6
|
+
|
7
|
+
A Test Kitchen Serverspec Verifer without having to transit the Busser layer.
|
8
|
+
|
9
|
+
This is a first version. Currently it only supports running serverspec remotely on the server.
|
10
|
+
It could be easily enhanced to run serverspec locally on your workstation. Also the installs
|
11
|
+
don't cover all the possible options yet.
|
12
|
+
|
13
|
+
|
14
|
+
## Installation
|
15
|
+
|
16
|
+
On your workstation add this line to your Gemfile:
|
17
|
+
|
18
|
+
gem 'kitchen-verifier-serverspec'
|
19
|
+
|
20
|
+
And then execute:
|
21
|
+
|
22
|
+
$ bundle
|
23
|
+
|
24
|
+
Or install it yourself as:
|
25
|
+
|
26
|
+
$ gem install kitchen-verifier-serverspec
|
27
|
+
|
28
|
+
When it runs it install serverspec on the remote server. This can be configured by passing a Gemfile like this:
|
29
|
+
|
30
|
+
```
|
31
|
+
source 'https://rubygems.org'
|
32
|
+
|
33
|
+
gem 'net-ssh','~> 2.9'
|
34
|
+
gem 'serverspec'
|
35
|
+
```
|
36
|
+
|
37
|
+
this allows extra dependencies to be specified and the version of serverspec specified.
|
38
|
+
|
39
|
+
## Usage
|
40
|
+
|
41
|
+
|
42
|
+
An example of the verifier serverspec options in your `.kitchen.yml` file:
|
43
|
+
|
44
|
+
```yaml
|
45
|
+
verifier:
|
46
|
+
name: serverspec
|
47
|
+
|
48
|
+
suites:
|
49
|
+
- name: base
|
50
|
+
verifier:
|
51
|
+
patterns:
|
52
|
+
- modules/mycompany_base/spec/acceptance/base_spec.rb
|
53
|
+
```
|
54
|
+
|
55
|
+
See example [https://github.com/neillturner/puppet_beaker_repo](https://github.com/neillturner/puppet_beaker_repo)
|
56
|
+
|
57
|
+
# Serverspec Verifier Options
|
58
|
+
|
59
|
+
key | default value | Notes
|
60
|
+
----|---------------|--------
|
61
|
+
sleep | 0 |
|
62
|
+
serverspec_command | nil | custom command to run serverspec
|
63
|
+
format | 'documentation' | format of serverspec output
|
64
|
+
color | true | enable color in the output
|
65
|
+
default_path | '/tmp/kitchen' | Set the default path where serverspec looks for patterns
|
66
|
+
patterns | [] | array of patterns for spec test files
|
67
|
+
gemfile | nil | custom gemfile to use to install serverspec
|
68
|
+
install_commmand | 'bundle install' | command to install serverspec
|
69
|
+
test_serverspec_installed | true | only run install_command if serverspec not installed
|
70
|
+
extra_flags | nil | extra flags to add to ther serverspec command
|
71
|
+
remove_default_path | false | remove the default_path after successful serverspec run
|
72
|
+
http_proxy | nil | use http proxy when installing ruby, serverspec and running serverspec
|
73
|
+
https_proxy | nil | use https proxy when installing puppet, ruby, serverspec and running serverspec
|
74
|
+
sudo | nil | use sudo to run commands
|
75
|
+
|
76
|
+
|
77
|
+
## Contributing
|
78
|
+
|
79
|
+
1. Fork it
|
80
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
81
|
+
3. Run style checks and RSpec tests (`bundle exec rake`)
|
82
|
+
4. Commit your changes (`git commit -am 'Add some feature'`)
|
83
|
+
5. Push to the branch (`git push origin my-new-feature`)
|
84
|
+
6. Create new Pull Request
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
$LOAD_PATH.unshift File.expand_path('../lib', __FILE__)
|
4
|
+
|
5
|
+
require 'kitchen/verifier/serverspec_version'
|
6
|
+
|
7
|
+
Gem::Specification.new do |s|
|
8
|
+
s.name = 'kitchen-verifier-serverspec'
|
9
|
+
s.license = 'Apache-2.0'
|
10
|
+
s.version = Kitchen::Verifier::SERVERSPEC_VERSION
|
11
|
+
s.authors = ['Neill Turner']
|
12
|
+
s.email = ['neillwturner@gmail.com']
|
13
|
+
s.homepage = 'https://github.com/neillturner/kitchen-verifier-serverspec'
|
14
|
+
s.summary = 'Serverspec verifier for Test-Kitchen without having to transit the Busser layer. '
|
15
|
+
candidates = Dir.glob('{lib}/**/*') + ['README.md', 'kitchen-verifier-serverspec.gemspec']
|
16
|
+
s.files = candidates.sort
|
17
|
+
s.platform = Gem::Platform::RUBY
|
18
|
+
s.require_paths = ['lib']
|
19
|
+
s.rubyforge_project = '[none]'
|
20
|
+
s.add_dependency 'test-kitchen', '~> 1.4'
|
21
|
+
s.add_dependency 'net-ssh', '~> 2.0'
|
22
|
+
s.description = <<-EOF
|
23
|
+
Serverspec verifier for Test-Kitchen without having to transit the Busser layer.
|
24
|
+
EOF
|
25
|
+
end
|
@@ -0,0 +1,242 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
|
15
|
+
require 'kitchen/verifier/base'
|
16
|
+
|
17
|
+
module Kitchen
|
18
|
+
module Verifier
|
19
|
+
# Serverspec verifier for Kitchen.
|
20
|
+
#
|
21
|
+
class Serverspec < Kitchen::Verifier::Base
|
22
|
+
require 'mixlib/shellout'
|
23
|
+
|
24
|
+
kitchen_verifier_api_version 1
|
25
|
+
|
26
|
+
plugin_version Kitchen::VERSION
|
27
|
+
|
28
|
+
default_config :sleep, 0
|
29
|
+
default_config :serverspec_command, nil
|
30
|
+
default_config :shellout_opts, {}
|
31
|
+
default_config :live_stream, $stdout
|
32
|
+
default_config :remote_exec, true
|
33
|
+
default_config :format, 'documentation'
|
34
|
+
default_config :color, true
|
35
|
+
default_config :default_path, '/tmp/kitchen'
|
36
|
+
default_config :patterns, []
|
37
|
+
default_config :gemfile, nil
|
38
|
+
default_config :install_commmand, 'bundle install'
|
39
|
+
default_config :test_serverspec_installed, true
|
40
|
+
default_config :extra_flags, nil
|
41
|
+
default_config :remove_default_path, false
|
42
|
+
|
43
|
+
# (see Base#call)
|
44
|
+
def call(state)
|
45
|
+
info("[#{name}] Verify on instance=#{instance} with state=#{state}")
|
46
|
+
sleep_if_set
|
47
|
+
merge_state_to_env(state)
|
48
|
+
if config[:remote_exec]
|
49
|
+
instance.transport.connection(state) do |conn|
|
50
|
+
conn.execute(install_command)
|
51
|
+
conn.execute(serverspec_commands)
|
52
|
+
end
|
53
|
+
else
|
54
|
+
shellout
|
55
|
+
end
|
56
|
+
debug("[#{name}] Verify completed.")
|
57
|
+
end
|
58
|
+
|
59
|
+
## for legacy drivers.
|
60
|
+
def run_command
|
61
|
+
sleep_if_set
|
62
|
+
if config[:remote_exec]
|
63
|
+
serverspec_commands
|
64
|
+
else
|
65
|
+
shellout
|
66
|
+
init
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
def setup_cmd
|
71
|
+
sleep_if_set
|
72
|
+
if config[:remote_exec]
|
73
|
+
install_command
|
74
|
+
else
|
75
|
+
shellout
|
76
|
+
init
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
private
|
81
|
+
|
82
|
+
def serverspec_commands
|
83
|
+
if config[:serverspec_command]
|
84
|
+
<<-INSTALL
|
85
|
+
#{config[:serverspec_command]}
|
86
|
+
INSTALL
|
87
|
+
else
|
88
|
+
<<-INSTALL
|
89
|
+
if [ -d #{config[:default_path]} ]; then
|
90
|
+
cd #{config[:default_path]}
|
91
|
+
#{rspec_commands}
|
92
|
+
#{remove_default_path}
|
93
|
+
else
|
94
|
+
echo "ERROR: Default path '#{config[:default_path]}' does not exist"
|
95
|
+
exit 1
|
96
|
+
fi
|
97
|
+
INSTALL
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
def install_command
|
102
|
+
info('Installing ruby, bundler and serverspec')
|
103
|
+
<<-INSTALL
|
104
|
+
if [ ! $(which ruby) ]; then
|
105
|
+
echo '-----> Installing ruby, will try to determine platform os'
|
106
|
+
if [ -f /etc/centos-release ] || [ -f /etc/redhat-release ] || [ -f /etc/oracle-release ]; then
|
107
|
+
#{sudo_env('yum')} -y install ruby
|
108
|
+
else
|
109
|
+
if [ -f /etc/system-release ] || [ grep -q 'Amazon Linux' /etc/system-release ]; then
|
110
|
+
#{sudo_env('yum')} -y install ruby
|
111
|
+
else
|
112
|
+
#{sudo('apt-get')} -y install ruby
|
113
|
+
fi
|
114
|
+
fi
|
115
|
+
fi
|
116
|
+
#{install_bundler}
|
117
|
+
if [ -d #{config[:default_path]} ]; then
|
118
|
+
#{install_serverspec}
|
119
|
+
else
|
120
|
+
echo "ERROR: Default path '#{config[:default_path]}' does not exist"
|
121
|
+
exit 1
|
122
|
+
fi
|
123
|
+
INSTALL
|
124
|
+
end
|
125
|
+
|
126
|
+
def install_bundler
|
127
|
+
<<-INSTALL
|
128
|
+
if [ $(#{sudo('gem')} list bundler -i) == 'false' ]; then
|
129
|
+
#{sudo('gem')} install #{gem_proxy_parm} --no-ri --no-rdoc bundler
|
130
|
+
fi
|
131
|
+
INSTALL
|
132
|
+
end
|
133
|
+
|
134
|
+
def install_serverspec
|
135
|
+
<<-INSTALL
|
136
|
+
#{test_serverspec_installed}
|
137
|
+
#{install_gemfile}
|
138
|
+
#{sudo_env('bundler')} install --gemfile=#{config[:default_path]}/Gemfile
|
139
|
+
#{fi_test_serverspec_installed}
|
140
|
+
INSTALL
|
141
|
+
end
|
142
|
+
|
143
|
+
def install_gemfile
|
144
|
+
if config[:gemfile]
|
145
|
+
<<-INSTALL
|
146
|
+
#{read_gemfile}
|
147
|
+
INSTALL
|
148
|
+
else
|
149
|
+
<<-INSTALL
|
150
|
+
#{sudo('rm')} -f #{config[:default_path]}/Gemfile
|
151
|
+
#{sudo('echo')} "source 'https://rubygems.org'" >> #{config[:default_path]}/Gemfile
|
152
|
+
#{sudo('echo')} "gem 'net-ssh','~> 2.9'" >> #{config[:default_path]}/Gemfile
|
153
|
+
#{sudo('echo')} "gem 'serverspec'" >> #{config[:default_path]}/Gemfile
|
154
|
+
INSTALL
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
def read_gemfile
|
159
|
+
data = "#{sudo('rm')} -f #{config[:default_path]}/Gemfile\n"
|
160
|
+
f = File.open(config[:gemfile], 'r')
|
161
|
+
f.each_line do |line|
|
162
|
+
data = "#{data}#{sudo('echo')} \"#{line}\" >> #{config[:default_path]}/Gemfile\n"
|
163
|
+
end
|
164
|
+
f.close
|
165
|
+
data
|
166
|
+
end
|
167
|
+
|
168
|
+
def remove_default_path
|
169
|
+
info('Removing default path') if config[:remove_default_path]
|
170
|
+
config[:remove_default_path] ? "rm -rf #{config[:default_path]}" : nil
|
171
|
+
end
|
172
|
+
|
173
|
+
def test_serverspec_installed
|
174
|
+
config[:test_serverspec_installed] ? "if [ $(#{sudo('gem')} list serverspec -i) == 'false' ]; then" : nil
|
175
|
+
end
|
176
|
+
|
177
|
+
def fi_test_serverspec_installed
|
178
|
+
config[:test_serverspec_installed] ? 'fi' : nil
|
179
|
+
end
|
180
|
+
|
181
|
+
def rspec_commands
|
182
|
+
info('Running Serverspec')
|
183
|
+
config[:patterns].map { |s| "rspec #{color} -f #{config[:format]} --default-path #{config[:default_path]} #{config[:extra_flags]} -P #{s}" }.join('\n')
|
184
|
+
end
|
185
|
+
|
186
|
+
def sudo_env(pm)
|
187
|
+
s = https_proxy ? "https_proxy=#{https_proxy}" : nil
|
188
|
+
p = http_proxy ? "http_proxy=#{http_proxy}" : nil
|
189
|
+
p || s ? "#{sudo('env')} #{p} #{s} #{pm}" : sudo(pm).to_s
|
190
|
+
end
|
191
|
+
|
192
|
+
def http_proxy
|
193
|
+
config[:http_proxy]
|
194
|
+
end
|
195
|
+
|
196
|
+
def https_proxy
|
197
|
+
config[:https_proxy]
|
198
|
+
end
|
199
|
+
|
200
|
+
def gem_proxy_parm
|
201
|
+
http_proxy ? "--http-proxy #{http_proxy}" : nil
|
202
|
+
end
|
203
|
+
|
204
|
+
def color
|
205
|
+
config[:color] ? '-c' : nil
|
206
|
+
end
|
207
|
+
|
208
|
+
# Sleep for a period of time, if a value is set in the config.
|
209
|
+
#
|
210
|
+
# @api private
|
211
|
+
def sleep_if_set
|
212
|
+
config[:sleep].to_i.times do
|
213
|
+
print '.'
|
214
|
+
sleep 1
|
215
|
+
end
|
216
|
+
puts
|
217
|
+
end
|
218
|
+
|
219
|
+
def shellout
|
220
|
+
cmd = Mixlib::ShellOut.new(config[:command], config[:shellout_opts])
|
221
|
+
cmd.live_stream = config[:live_stream]
|
222
|
+
cmd.run_command
|
223
|
+
begin
|
224
|
+
cmd.error!
|
225
|
+
rescue Mixlib::ShellOut::ShellCommandFailed
|
226
|
+
raise ActionFailed, "Action #verify failed for #{instance.to_str}."
|
227
|
+
end
|
228
|
+
end
|
229
|
+
|
230
|
+
def merge_state_to_env(state)
|
231
|
+
env_state = { :environment => {} }
|
232
|
+
env_state[:environment]['KITCHEN_INSTANCE'] = instance.name
|
233
|
+
env_state[:environment]['KITCHEN_PLATFORM'] = instance.platform.name
|
234
|
+
env_state[:environment]['KITCHEN_SUITE'] = instance.suite.name
|
235
|
+
state.each_pair do |key, value|
|
236
|
+
env_state[:environment]['KITCHEN_' + key.to_s.upcase] = value
|
237
|
+
end
|
238
|
+
config[:shellout_opts].merge!(env_state)
|
239
|
+
end
|
240
|
+
end
|
241
|
+
end
|
242
|
+
end
|
metadata
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: kitchen-verifier-serverspec
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Neill Turner
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-02-15 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: test-kitchen
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.4'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.4'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: net-ssh
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '2.0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '2.0'
|
41
|
+
description: |
|
42
|
+
Serverspec verifier for Test-Kitchen without having to transit the Busser layer.
|
43
|
+
email:
|
44
|
+
- neillwturner@gmail.com
|
45
|
+
executables: []
|
46
|
+
extensions: []
|
47
|
+
extra_rdoc_files: []
|
48
|
+
files:
|
49
|
+
- README.md
|
50
|
+
- kitchen-verifier-serverspec.gemspec
|
51
|
+
- lib/kitchen/verifier/serverspec.rb
|
52
|
+
- lib/kitchen/verifier/serverspec_version.rb
|
53
|
+
homepage: https://github.com/neillturner/kitchen-verifier-serverspec
|
54
|
+
licenses:
|
55
|
+
- Apache-2.0
|
56
|
+
metadata: {}
|
57
|
+
post_install_message:
|
58
|
+
rdoc_options: []
|
59
|
+
require_paths:
|
60
|
+
- lib
|
61
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
62
|
+
requirements:
|
63
|
+
- - '>='
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: '0'
|
66
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
67
|
+
requirements:
|
68
|
+
- - '>='
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: '0'
|
71
|
+
requirements: []
|
72
|
+
rubyforge_project: '[none]'
|
73
|
+
rubygems_version: 2.0.14
|
74
|
+
signing_key:
|
75
|
+
specification_version: 4
|
76
|
+
summary: Serverspec verifier for Test-Kitchen without having to transit the Busser
|
77
|
+
layer.
|
78
|
+
test_files: []
|