kitchen-goss 0.0.2
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 +7 -0
- data/README.md +57 -0
- data/kitchen-goss.gemspec +34 -0
- data/lib/kitchen/verifier/goss.rb +210 -0
- data/lib/kitchen/verifier/goss_version.rb +7 -0
- metadata +91 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: ee7f23ceef71d0c2ef396aa1abe84a6d17f51743
|
4
|
+
data.tar.gz: 34db15db68c3a9e824b2a3f11e55bc31e3c4c409
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: dbdad7e7d29537f88bd1c1079304dd0bbaf9c58e3c392edad362396314207f27c9da7cbb259a37e7c343627b7fd76f6f890704e7b4b6ff5d66bcfabce44c2be3
|
7
|
+
data.tar.gz: 8ab394d7a74296e8aa7c117e126c8cf2c3b7e34c50b4398a377a0241a1a275ad8afe26d9cad0b2c49a01f277a758a2309f6be012971880a876ed077073b94e8f
|
data/README.md
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
# kitchen-goss
|
2
|
+
A test-kitchen verifier plugin for GOSS
|
3
|
+
|
4
|
+
## Intro
|
5
|
+
[GOSS](https://github.com/aelsabbahy/goss.git) is a tool for validating a server's configuration.
|
6
|
+
This kitchen plugin adds Goss support as a validation to kitchen.
|
7
|
+
|
8
|
+
## How to install
|
9
|
+
|
10
|
+
### Ruby gem
|
11
|
+
```
|
12
|
+
gem install kitchen-goss
|
13
|
+
```
|
14
|
+
|
15
|
+
### To install from code or develop
|
16
|
+
```
|
17
|
+
git clone git@github.com:ahelal/kitchen-goss.git
|
18
|
+
cd kitchen-goss
|
19
|
+
gem build kitchen-goss.gemspec
|
20
|
+
gem install kitchen-goss-<version>.gem
|
21
|
+
```
|
22
|
+
|
23
|
+
## kitchen.yml configuration
|
24
|
+
```yaml
|
25
|
+
verifier :
|
26
|
+
name : "goss"
|
27
|
+
```
|
28
|
+
|
29
|
+
## kitchen.yml options
|
30
|
+
Besides the normal config in kitchen.yml goss validation can accept the following options.
|
31
|
+
|
32
|
+
```ruby
|
33
|
+
default_config :sleep, 0
|
34
|
+
default_config :goss_version, "v0.1.5"
|
35
|
+
default_config :validate_output, "documentation"
|
36
|
+
default_config :custom_install_command, nil
|
37
|
+
default_config :goss_link, "https://github.com/aelsabbahy/goss/releases/download/$VERSION/goss-${DISTRO}-${ARCH}"
|
38
|
+
default_config :goss_download_path, "/tmp/goss-${VERSION}-${DISTRO}-${ARCH}"
|
39
|
+
```
|
40
|
+
|
41
|
+
## Test structure
|
42
|
+
Lets say you have a suite name **simple**
|
43
|
+
the following structure we be required.
|
44
|
+
```bash
|
45
|
+
.kitchen.yml
|
46
|
+
test/
|
47
|
+
\_integration/
|
48
|
+
\_simple/
|
49
|
+
\_goss/
|
50
|
+
\_test1.yml
|
51
|
+
|_test2.yml
|
52
|
+
```
|
53
|
+
|
54
|
+
|
55
|
+
##License
|
56
|
+
|
57
|
+
MIT
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
$:.unshift File.expand_path('../lib', __FILE__)
|
4
|
+
require 'kitchen/verifier/goss_version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "kitchen-goss"
|
8
|
+
gem.version = Kitchen::Verifier::GOSS_VERSION
|
9
|
+
gem.authors = ["Adham Helal"]
|
10
|
+
gem.email = ["adham.helal@gmail.com"]
|
11
|
+
gem.licenses = ['MIT']
|
12
|
+
gem.homepage = "https://github.com/ahelal/kitchen-goss"
|
13
|
+
gem.summary = "A test-kitchen verifier plugin for GOSS"
|
14
|
+
candidates = Dir.glob("{lib}/**/*") + ['README.md', 'kitchen-goss.gemspec']
|
15
|
+
gem.files = candidates.sort
|
16
|
+
gem.platform = Gem::Platform::RUBY
|
17
|
+
gem.require_paths = ['lib']
|
18
|
+
gem.rubyforge_project = '[none]'
|
19
|
+
gem.description = <<-EOF
|
20
|
+
== DESCRIPTION:
|
21
|
+
|
22
|
+
GOSS is a tool for validating a server's configuration.
|
23
|
+
This kitchen plugin adds Goss support as a validation to test-kitchen.
|
24
|
+
|
25
|
+
== FEATURES:
|
26
|
+
|
27
|
+
|
28
|
+
EOF
|
29
|
+
|
30
|
+
gem.add_runtime_dependency 'test-kitchen'
|
31
|
+
gem.add_development_dependency 'rspec'
|
32
|
+
gem.add_development_dependency 'pry'
|
33
|
+
|
34
|
+
end
|
@@ -0,0 +1,210 @@
|
|
1
|
+
require 'kitchen/verifier/base'
|
2
|
+
|
3
|
+
module Kitchen
|
4
|
+
module Verifier
|
5
|
+
class Goss < Kitchen::Verifier::Base
|
6
|
+
require 'mixlib/shellout'
|
7
|
+
require "kitchen/util"
|
8
|
+
require 'pathname'
|
9
|
+
|
10
|
+
kitchen_verifier_api_version 1
|
11
|
+
plugin_version Kitchen::VERSION
|
12
|
+
|
13
|
+
#
|
14
|
+
default_config :sleep, 0
|
15
|
+
default_config :goss_version, "v0.1.5"
|
16
|
+
default_config :validate_output, "documentation"
|
17
|
+
default_config :custom_install_command, nil
|
18
|
+
default_config :goss_link, "https://github.com/aelsabbahy/goss/releases/download/$VERSION/goss-${DISTRO}-${ARCH}"
|
19
|
+
default_config :goss_download_path, "/tmp/goss-${VERSION}-${DISTRO}-${ARCH}"
|
20
|
+
|
21
|
+
def install_command
|
22
|
+
# If cutom install
|
23
|
+
info('Installing with custom install command') if config[:custom_install_command]
|
24
|
+
return config[:custom_install_command] if config[:custom_install_command]
|
25
|
+
|
26
|
+
info('Checking/Installing GOSS')
|
27
|
+
prefix_command(wrap_shell_code(Util.outdent!(<<-CMD)))
|
28
|
+
## Get helper
|
29
|
+
#{Kitchen::Util.shell_helpers}
|
30
|
+
|
31
|
+
#{goss_filename_flags}
|
32
|
+
download_url="#{config[:goss_link]}"
|
33
|
+
goss_download_path="#{config[:goss_download_path]}"
|
34
|
+
|
35
|
+
## Check do we need to download GOSS
|
36
|
+
if [ -f "/${goss_download_path}" ]; then
|
37
|
+
echo "GOSS is installed in ${goss_download_path}"
|
38
|
+
else
|
39
|
+
echo "Checking compatibility"
|
40
|
+
distro="$(uname)"
|
41
|
+
if [ "x${distro}" != "xLinux" ]; then
|
42
|
+
echo "Your distro '${distro}' is not supported."
|
43
|
+
exit 1
|
44
|
+
fi
|
45
|
+
echo "Trying to download GOSS to ${goss_download_path}"
|
46
|
+
do_download ${download_url} ${goss_download_path}
|
47
|
+
chmod +x ${goss_download_path}
|
48
|
+
fi
|
49
|
+
CMD
|
50
|
+
end
|
51
|
+
|
52
|
+
# (see Base#init_command)
|
53
|
+
def init_command
|
54
|
+
return if local_suite_files.empty?
|
55
|
+
debug("Remove root_path on remote server.")
|
56
|
+
<<-CMD
|
57
|
+
suite_dir="#{config[:root_path]}"
|
58
|
+
if [ "${suite_dir}" = "x" ]; then
|
59
|
+
echo "root_path is not configured."
|
60
|
+
exit 1
|
61
|
+
fi
|
62
|
+
## Remove root_path
|
63
|
+
rm -rf #{config[:root_path]}
|
64
|
+
## Create root_path
|
65
|
+
mkdir -p #{config[:root_path]}
|
66
|
+
CMD
|
67
|
+
end
|
68
|
+
|
69
|
+
# Runs the verifier on the instance.
|
70
|
+
#
|
71
|
+
# @param state [Hash] mutable instance state
|
72
|
+
# @raise [ActionFailed] if the action could not be completed
|
73
|
+
def call(state)
|
74
|
+
create_sandbox
|
75
|
+
sandbox_dirs = Dir.glob(File.join(sandbox_path, "*"))
|
76
|
+
|
77
|
+
instance.transport.connection(state) do |conn|
|
78
|
+
conn.execute(install_command)
|
79
|
+
conn.execute(init_command)
|
80
|
+
info("Transferring files to #{instance.to_str}")
|
81
|
+
conn.upload(sandbox_dirs, config[:root_path])
|
82
|
+
debug("Transfer complete")
|
83
|
+
conn.execute(prepare_command)
|
84
|
+
conn.execute(run_command)
|
85
|
+
end
|
86
|
+
rescue Kitchen::Transport::TransportFailed => ex
|
87
|
+
if ex.message .include? "<TEST EXECUTION FAILED>"
|
88
|
+
raise ActionFailed, "Action #verify failed for #{instance.to_str}."
|
89
|
+
else
|
90
|
+
raise ActionFailed, ex.message
|
91
|
+
end
|
92
|
+
ensure
|
93
|
+
cleanup_sandbox
|
94
|
+
end
|
95
|
+
|
96
|
+
# (see Base#run_command)
|
97
|
+
def run_command
|
98
|
+
return if local_suite_files.empty?
|
99
|
+
|
100
|
+
debug("Running tests")
|
101
|
+
prefix_command(wrap_shell_code(Util.outdent!(<<-CMD)))
|
102
|
+
set +e
|
103
|
+
#{goss_filename_flags}
|
104
|
+
command_validate_opts="validate --format #{config[:validate_output]}"
|
105
|
+
#{run_test_command}
|
106
|
+
CMD
|
107
|
+
end
|
108
|
+
|
109
|
+
# Copies all test suite files into the suites directory in the sandbox.
|
110
|
+
#
|
111
|
+
# @api private
|
112
|
+
def prepare_suites
|
113
|
+
base = File.join(config[:test_base_path], config[:suite_name])
|
114
|
+
|
115
|
+
local_suite_files.each do |src|
|
116
|
+
dest = File.join(sandbox_suites_dir, src.sub("#{base}/", ""))
|
117
|
+
FileUtils.mkdir_p(File.dirname(dest))
|
118
|
+
FileUtils.cp(src, dest, :preserve => true)
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
# Returns an Array of test suite filenames for the related suite currently
|
123
|
+
# residing on the local workstation. Any special provisioner-specific
|
124
|
+
# directories (such as a Chef roles/ directory) are excluded.
|
125
|
+
#
|
126
|
+
# @return [Array<String>] array of suite files
|
127
|
+
# @api private
|
128
|
+
def local_suite_files
|
129
|
+
base = File.join(config[:test_base_path], config[:suite_name])
|
130
|
+
glob = File.join(base, "goss/**/*")
|
131
|
+
#testfiles = Dir.glob(glob).reject { |f| File.directory?(f) }
|
132
|
+
Dir.glob(glob).reject { |f| File.directory?(f) }
|
133
|
+
end
|
134
|
+
|
135
|
+
# (see Base#create_sandbox)
|
136
|
+
def create_sandbox
|
137
|
+
super
|
138
|
+
prepare_suites
|
139
|
+
end
|
140
|
+
|
141
|
+
# @return [String] path to suites directory under sandbox path
|
142
|
+
# @api private
|
143
|
+
def sandbox_suites_dir
|
144
|
+
File.join(sandbox_path, "suites")
|
145
|
+
end
|
146
|
+
|
147
|
+
# @return [String] the run command to execute tests
|
148
|
+
# @api private
|
149
|
+
def run_test_command
|
150
|
+
<<-CMD
|
151
|
+
if [ ! -x "#{config[:goss_download_path]}" ]; then
|
152
|
+
echo "Something failed cant execute '${command}'"
|
153
|
+
exit 1
|
154
|
+
fi
|
155
|
+
|
156
|
+
test_failed=0
|
157
|
+
for VARIABLE in #{get_test_name}
|
158
|
+
do
|
159
|
+
#{config[:goss_download_path]} -g ${VARIABLE} ${command_validate_opts}
|
160
|
+
if [ "$?" -ne 0 ]; then
|
161
|
+
test_failed=1
|
162
|
+
fi
|
163
|
+
done
|
164
|
+
|
165
|
+
# Check exit code
|
166
|
+
if [ "$test_failed" -ne 0 ]; then
|
167
|
+
test_failed=1
|
168
|
+
echo "<TEST EXECUTION FAILED>"
|
169
|
+
fi
|
170
|
+
exit ${test_failed}
|
171
|
+
CMD
|
172
|
+
end
|
173
|
+
|
174
|
+
def goss_filename_flags
|
175
|
+
<<-CMD
|
176
|
+
## Set the flags for GOSS command path
|
177
|
+
VERSION="#{config[:goss_version]}"
|
178
|
+
DISTRO="$(uname)"
|
179
|
+
## Need improvements
|
180
|
+
if [ "$(uname -m)" = "x86_64" ]; then
|
181
|
+
ARCH="amd64"
|
182
|
+
else
|
183
|
+
ARCH="386"
|
184
|
+
fi
|
185
|
+
CMD
|
186
|
+
end
|
187
|
+
|
188
|
+
def get_test_name
|
189
|
+
base_path = File.join(config[:test_base_path], config[:suite_name])
|
190
|
+
remote_base_path = File.join(config[:root_path], "suites")
|
191
|
+
all_tests = ""
|
192
|
+
local_suite_files.each do |test_file|
|
193
|
+
all_tests += " " + test_file.sub(base_path, remote_base_path)
|
194
|
+
end
|
195
|
+
all_tests
|
196
|
+
end
|
197
|
+
|
198
|
+
# Sleep for a period of time, if a value is set in the config.
|
199
|
+
#
|
200
|
+
# @api private
|
201
|
+
def sleep_if_set
|
202
|
+
config[:sleep].to_i.times do
|
203
|
+
print '.'
|
204
|
+
sleep 1
|
205
|
+
end
|
206
|
+
end
|
207
|
+
|
208
|
+
end
|
209
|
+
end
|
210
|
+
end
|
metadata
ADDED
@@ -0,0 +1,91 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: kitchen-goss
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Adham Helal
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-04-20 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: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rspec
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: pry
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: "== DESCRIPTION:\n\nGOSS is a tool for validating a server's configuration.
|
56
|
+
\nThis kitchen plugin adds Goss support as a validation to test-kitchen.\n\n== FEATURES:\n\n\n"
|
57
|
+
email:
|
58
|
+
- adham.helal@gmail.com
|
59
|
+
executables: []
|
60
|
+
extensions: []
|
61
|
+
extra_rdoc_files: []
|
62
|
+
files:
|
63
|
+
- README.md
|
64
|
+
- kitchen-goss.gemspec
|
65
|
+
- lib/kitchen/verifier/goss.rb
|
66
|
+
- lib/kitchen/verifier/goss_version.rb
|
67
|
+
homepage: https://github.com/ahelal/kitchen-goss
|
68
|
+
licenses:
|
69
|
+
- MIT
|
70
|
+
metadata: {}
|
71
|
+
post_install_message:
|
72
|
+
rdoc_options: []
|
73
|
+
require_paths:
|
74
|
+
- lib
|
75
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
76
|
+
requirements:
|
77
|
+
- - '>='
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
version: '0'
|
80
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
81
|
+
requirements:
|
82
|
+
- - '>='
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: '0'
|
85
|
+
requirements: []
|
86
|
+
rubyforge_project: '[none]'
|
87
|
+
rubygems_version: 2.0.14.1
|
88
|
+
signing_key:
|
89
|
+
specification_version: 4
|
90
|
+
summary: A test-kitchen verifier plugin for GOSS
|
91
|
+
test_files: []
|