serverspec_launcher 0.4.2 → 0.4.5
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/.gitignore +2 -1
- data/Rakefile +20 -2
- data/lib/serverspec_launcher.rb +8 -3
- data/lib/serverspec_launcher/generators/example_spec_generator.rb +21 -0
- data/lib/serverspec_launcher/rake_tasks.rb +8 -1
- data/lib/serverspec_launcher/spec_helper.rb +26 -1
- data/lib/serverspec_launcher/version.rb +1 -1
- data/properties.yml +41 -5
- data/serverspec_launcher.gemspec +1 -0
- data/templates/example_spec.rb.erb +30 -0
- data/templates/properties-light.yaml.erb +1 -1
- metadata +18 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d6a8011a886a38e0290fcbe0e8abb9de940d1e86a3485fb74c3d2febfca0bde0
|
4
|
+
data.tar.gz: 86f96b435403dfc3e423f043ff7bb5301a08d4d1b92995e21006c13586151632
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 74ddda61add4e88370222706ce5d772ee1d035fb8470851d7ea3e85c1959c7bd50a7ec8b2bff77b326fcce4a5409b3df1c71726ffefcc0a3a102416ad831b392
|
7
|
+
data.tar.gz: 1985d69f979d083e99561b11348ad8c504a5cb42ac3264aa9c268b9a0a2180499d45264ec67d36dd1e6a44b9f2b6f79210c75bbe35d103b7bcbec9d22f78c765
|
data/.gitignore
CHANGED
data/Rakefile
CHANGED
@@ -1,11 +1,17 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
|
3
|
+
|
4
|
+
|
2
5
|
require 'bundler/gem_tasks'
|
3
6
|
require 'rspec/core/rake_task'
|
4
7
|
require 'conventional_changelog'
|
5
8
|
require 'docker-api'
|
9
|
+
require_relative 'spec/helpers/container_helper'
|
6
10
|
|
7
11
|
require 'serverspec_launcher/rake_tasks'
|
8
12
|
|
13
|
+
include ContainerHelper
|
14
|
+
|
9
15
|
RSpec::Core::RakeTask.new(:spec) do |t|
|
10
16
|
t.exclude_pattern = 'spec/integration/**/*_spec.rb'
|
11
17
|
end
|
@@ -18,7 +24,19 @@ task :changelog do
|
|
18
24
|
end
|
19
25
|
|
20
26
|
|
21
|
-
task :
|
27
|
+
task :stop_ssh_container do
|
28
|
+
stop_ssh_container
|
29
|
+
end
|
30
|
+
|
31
|
+
task :start_ssh_container do
|
32
|
+
ENV['TARGET_HOST'] = '172.18.0.22'
|
33
|
+
start_ssh_container
|
34
|
+
end
|
35
|
+
|
36
|
+
task :post_task_cleanup do
|
37
|
+
at_exit { stop_ssh_container }
|
38
|
+
end
|
22
39
|
|
23
40
|
|
24
|
-
|
41
|
+
Rake::Task['serverspec:inspec-agent-example:all'].enhance ['post_task_cleanup', 'start_ssh_container']
|
42
|
+
Rake::Task['serverspec:inspec-password-example:all'].enhance ['post_task_cleanup', 'start_ssh_container']
|
data/lib/serverspec_launcher.rb
CHANGED
@@ -18,6 +18,12 @@ module ServerspecLauncher
|
|
18
18
|
properties.generate
|
19
19
|
end
|
20
20
|
|
21
|
+
|
22
|
+
def self.generate_examplespec
|
23
|
+
properties = ExampleSpecGenerator.new
|
24
|
+
properties.generate
|
25
|
+
end
|
26
|
+
|
21
27
|
def self.generate_spec_helper
|
22
28
|
properties = SpecHelperGenerator.new
|
23
29
|
properties.generate
|
@@ -69,12 +75,11 @@ module ServerspecLauncher
|
|
69
75
|
def self.init
|
70
76
|
generate_properties
|
71
77
|
generate_rolespec
|
72
|
-
|
78
|
+
generate_examplespec
|
79
|
+
generate_spec_helper
|
73
80
|
generate_rakefile
|
74
81
|
generate_rolespec
|
75
82
|
generate_gemspec create_repo
|
76
|
-
|
77
|
-
|
78
83
|
end
|
79
84
|
|
80
85
|
def self.process_command(args)
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'erb'
|
3
|
+
|
4
|
+
# Generates the propetires.yml to be used in tests
|
5
|
+
class ExampleSpecGenerator
|
6
|
+
def initialize(root_path = nil)
|
7
|
+
@path = root_path ? "#{root_path}/" : ''
|
8
|
+
@template_path = File.expand_path('../../../../templates', __FILE__)
|
9
|
+
@spec_file = "#{@path}spec/example_spec.rb"
|
10
|
+
end
|
11
|
+
|
12
|
+
def template
|
13
|
+
File.read "#{@template_path}/example_spec.rb.erb"
|
14
|
+
end
|
15
|
+
|
16
|
+
def generate
|
17
|
+
renderer = ERB.new template
|
18
|
+
Dir.mkdir "#{@path}spec" unless Dir.exists? "#{@path}spec"
|
19
|
+
File.open(@spec_file, 'w') { |file| file.write renderer.result } unless File.exists? @spec_file
|
20
|
+
end
|
21
|
+
end
|
@@ -235,6 +235,11 @@ class ServerspecLauncherRakeTasks
|
|
235
235
|
)
|
236
236
|
begin
|
237
237
|
puts "inspec #{command.join(' ')}"
|
238
|
+
networks = target[:attach_to] || []
|
239
|
+
networks.each do |nw|
|
240
|
+
network = Docker::Network.get(nw)
|
241
|
+
network.connect(container.id)
|
242
|
+
end
|
238
243
|
container.start
|
239
244
|
container.wait
|
240
245
|
rescue Docker::Error::TimeoutError => ex
|
@@ -304,6 +309,8 @@ class ServerspecLauncherRakeTasks
|
|
304
309
|
command << keyfile
|
305
310
|
end
|
306
311
|
command << "--user=#{target_info[:user]}" if target_info[:user]
|
312
|
+
command << "--port=#{target_info[:ssh_port]}" if target_info[:ssh_port]
|
313
|
+
command << "--password=#{target_info[:password]}" if target_info[:password]
|
307
314
|
command << "--bastion-host=#{target_info[:bastion_host]}" if target_info[:bastion_host]
|
308
315
|
command << "--bastion-port=#{target_info[:bastion_port]}" if target_info[:bastion_port]
|
309
316
|
command << "--bastion-user=#{target_info[:bastion_user]}" if target_info[:bastion_user]
|
@@ -313,7 +320,7 @@ class ServerspecLauncherRakeTasks
|
|
313
320
|
|
314
321
|
def set_inspec_reporters(key, host, options)
|
315
322
|
reporters = []
|
316
|
-
report_path = options[:environment] ? "/share/reports/#{options[:environment]}/#{key}" : "/share/#{
|
323
|
+
report_path = options[:environment] ? "/share/reports/#{options[:environment]}/#{key}" : "/share/reports/#{key}"
|
317
324
|
reporters << "junit:#{report_path}.xml" if options[:formatters].include?('junit') || options[:formatters].include?('xml')
|
318
325
|
reporters << "documentation:#{report_path}.docs" if options[:formatters].include?('docs') || options[:formatters].include?('documentation') || options[:formatters].include?('docs_file')
|
319
326
|
reporters << 'documentation' if options[:formatters].include?('docs_screen')
|
@@ -74,6 +74,8 @@ class SpecHelper
|
|
74
74
|
|
75
75
|
sudo_checks
|
76
76
|
|
77
|
+
|
78
|
+
|
77
79
|
ssh_user = @target_properties[:user] || Etc.getlogin
|
78
80
|
|
79
81
|
options = if @backend == 'vagrant'
|
@@ -81,13 +83,17 @@ class SpecHelper
|
|
81
83
|
else
|
82
84
|
Net::SSH::Config.for(@host)
|
83
85
|
end
|
84
|
-
|
86
|
+
password_checks(options)
|
85
87
|
options[:user] ||= ssh_user
|
86
88
|
options[:keys] = [@target_properties[:identity_file]] if @target_properties[:identity_file]
|
89
|
+
options[:port] = @target_properties[:ssh_port] if @target_properties[:ssh_port]
|
90
|
+
host_key_checking(options)
|
91
|
+
|
87
92
|
|
88
93
|
set :host, options[:host_name] || @host
|
89
94
|
set :ssh_options, options
|
90
95
|
|
96
|
+
|
91
97
|
# Disable sudo
|
92
98
|
# set :disable_sudo, true
|
93
99
|
|
@@ -114,6 +120,19 @@ class SpecHelper
|
|
114
120
|
end
|
115
121
|
end
|
116
122
|
|
123
|
+
def password_checks(options)
|
124
|
+
if ENV['ASK_LOGIN_PASSWORD']
|
125
|
+
begin
|
126
|
+
require 'highline/import'
|
127
|
+
rescue LoadError
|
128
|
+
raise 'highline is not available. Try installing it.'
|
129
|
+
end
|
130
|
+
options[:password] = ask('Enter login password: ') { |q| q.echo = false }
|
131
|
+
else
|
132
|
+
options[:password] = ENV['LOGIN_PASSWORD']
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
117
136
|
def vagrant_backend
|
118
137
|
@host = @target_properties[:vagrant_host] || 'default'
|
119
138
|
vagrant_dir = @target_properties[:vagrant_dir]
|
@@ -165,6 +184,12 @@ class SpecHelper
|
|
165
184
|
helper.setup_backend
|
166
185
|
helper
|
167
186
|
end
|
187
|
+
|
188
|
+
private
|
189
|
+
|
190
|
+
def host_key_checking(options)
|
191
|
+
options[:verify_host_key] = @target_properties[:verify_host_key].to_sym if @target_properties[:verify_host_key]
|
192
|
+
end
|
168
193
|
end
|
169
194
|
|
170
195
|
SpecHelper.load unless $dont_load_spec_helper
|
data/properties.yml
CHANGED
@@ -3,15 +3,51 @@ options:
|
|
3
3
|
fail_on_err: true
|
4
4
|
formatters:
|
5
5
|
- tick
|
6
|
-
color:
|
6
|
+
color: true
|
7
7
|
|
8
8
|
targets:
|
9
|
-
|
9
|
+
exec-example:
|
10
|
+
backend: exec
|
11
|
+
spec_type: integration/example
|
12
|
+
|
13
|
+
docker-example:
|
14
|
+
backend: docker
|
15
|
+
docker_image: alpine:latest
|
16
|
+
spec_type: integration/docker
|
17
|
+
|
18
|
+
ssh-example:
|
10
19
|
backend: ssh
|
11
20
|
hosts:
|
12
|
-
-
|
13
|
-
-
|
14
|
-
|
21
|
+
- 172.18.0.22
|
22
|
+
- 172.18.0.23
|
23
|
+
user: root
|
24
|
+
spec_type: integration/ssh
|
25
|
+
identity_file: spec/resources/ssh.rsa
|
26
|
+
verify_host_key: never
|
27
|
+
|
28
|
+
inspec-agent-example:
|
29
|
+
backend: inspec
|
30
|
+
control: spec/integration/inspec_spec.rb
|
31
|
+
ssh_port: 22
|
32
|
+
user: root
|
33
|
+
hosts:
|
34
|
+
- 172.18.0.22
|
35
|
+
auth_method: agent
|
36
|
+
attach_to:
|
37
|
+
- test_network
|
38
|
+
|
39
|
+
inspec-password-example:
|
40
|
+
backend: inspec
|
41
|
+
control: spec/integration/inspec_spec.rb
|
42
|
+
user: root
|
43
|
+
password: root
|
44
|
+
hosts:
|
45
|
+
- 172.18.0.22
|
46
|
+
auth_method: password
|
47
|
+
attach_to:
|
48
|
+
- test_network
|
49
|
+
formatters:
|
50
|
+
- json
|
15
51
|
|
16
52
|
|
17
53
|
environments:
|
data/serverspec_launcher.gemspec
CHANGED
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
context ENV['TARGET_HOST'] do
|
4
|
+
describe package('httpd'), :if => os[:family] == 'redhat' do
|
5
|
+
it { should be_installed }
|
6
|
+
end
|
7
|
+
|
8
|
+
describe package('apache2'), :if => os[:family] == 'ubuntu' do
|
9
|
+
it { should be_installed }
|
10
|
+
end
|
11
|
+
|
12
|
+
describe service('httpd'), :if => os[:family] == 'redhat' do
|
13
|
+
it { should be_enabled }
|
14
|
+
it { should be_running }
|
15
|
+
end
|
16
|
+
|
17
|
+
describe service('apache2'), :if => os[:family] == 'ubuntu' do
|
18
|
+
it { should be_enabled }
|
19
|
+
it { should be_running }
|
20
|
+
end
|
21
|
+
|
22
|
+
describe service('org.apache.httpd'), :if => os[:family] == 'darwin' do
|
23
|
+
it { should be_enabled }
|
24
|
+
it { should be_running }
|
25
|
+
end
|
26
|
+
|
27
|
+
describe port(80) do
|
28
|
+
it { should be_listening }
|
29
|
+
end
|
30
|
+
end
|
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.4.
|
4
|
+
version: 0.4.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Wardrobe
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-05-
|
11
|
+
date: 2019-05-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -192,6 +192,20 @@ dependencies:
|
|
192
192
|
- - ">="
|
193
193
|
- !ruby/object:Gem::Version
|
194
194
|
version: '0'
|
195
|
+
- !ruby/object:Gem::Dependency
|
196
|
+
name: docker-swarm-sdk
|
197
|
+
requirement: !ruby/object:Gem::Requirement
|
198
|
+
requirements:
|
199
|
+
- - ">="
|
200
|
+
- !ruby/object:Gem::Version
|
201
|
+
version: '0'
|
202
|
+
type: :runtime
|
203
|
+
prerelease: false
|
204
|
+
version_requirements: !ruby/object:Gem::Requirement
|
205
|
+
requirements:
|
206
|
+
- - ">="
|
207
|
+
- !ruby/object:Gem::Version
|
208
|
+
version: '0'
|
195
209
|
description: A utility to manage serverspec scripts
|
196
210
|
email:
|
197
211
|
- andrew.g.wardrobe@googlemail.com
|
@@ -214,6 +228,7 @@ files:
|
|
214
228
|
- exe/serverspec_launcher
|
215
229
|
- lib/launcher_json_formatter.rb
|
216
230
|
- lib/serverspec_launcher.rb
|
231
|
+
- lib/serverspec_launcher/generators/example_spec_generator.rb
|
217
232
|
- lib/serverspec_launcher/generators/gemspec_generator.rb
|
218
233
|
- lib/serverspec_launcher/generators/properties_generator.rb
|
219
234
|
- lib/serverspec_launcher/generators/rakefile_generator.rb
|
@@ -228,6 +243,7 @@ files:
|
|
228
243
|
- properties.yml
|
229
244
|
- serverspec_launcher.gemspec
|
230
245
|
- templates/Rakefile.erb
|
246
|
+
- templates/example_spec.rb.erb
|
231
247
|
- templates/gemspec.rb.erb
|
232
248
|
- templates/properties-light.yaml.erb
|
233
249
|
- templates/properties.yaml.erb
|