puppetbox 0.3.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +0 -1
- data/lib/puppetbox/driver/vagrant.rb +40 -29
- data/lib/puppetbox/puppetbox.rb +21 -29
- data/lib/puppetbox/report.rb +12 -12
- data/lib/puppetbox/result.rb +0 -1
- data/lib/puppetbox/result_set.rb +3 -2
- data/lib/puppetbox/version.rb +1 -1
- data/puppetbox.gemspec +2 -1
- metadata +18 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 466cebb037b7d3d05647c4c6edb2276cdc27cf20
|
4
|
+
data.tar.gz: d2b111a894e2acff93367e270e5b7291550d2c62
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: be79a33ae71e23acb18c040028923f4057e30dadfba4aac33d64b9bc06a84e5cb29cd96efee3ebca5b3c75aa622ea980c1308cdd0a1892126994687f97086c21
|
7
|
+
data.tar.gz: dc4054fe17680fd977ac4f872491a73773780c45177bd5133ca54878376b045ad62688cb0ff2477f5ddb46065a9af3bed4353eaeaa52667614bf4403df654424
|
data/Gemfile
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
source 'https://rubygems.org'
|
2
2
|
|
3
3
|
# Specify your gem's dependencies in puppetbox.gemspec
|
4
|
-
gem 'derelict', :git => 'https://github.com/GeoffWilliams/derelict', :ref => 'preserve_real_status'
|
5
4
|
#gem 'vagrantomatic', :path => '/home/geoff/github/vagrantomatic'
|
6
5
|
|
7
6
|
gemspec
|
@@ -6,48 +6,53 @@ require "puppetbox/logger"
|
|
6
6
|
module PuppetBox
|
7
7
|
module Driver
|
8
8
|
class Vagrant
|
9
|
-
|
10
|
-
# DEFAULT_VAGRANT_BOX = "puppetlabs/centos-7.2-64-puppet"
|
9
|
+
WORKING_DIR_VAGRANT = "vagrant"
|
11
10
|
PUPPET_CODE_MOUNT = "/etc/puppetlabs/code/environments/production"
|
12
11
|
|
13
12
|
def node_name
|
14
13
|
@name
|
15
14
|
end
|
16
15
|
|
17
|
-
# def initialize(name, codedir, keep_vm:true, working_dir:nil, config:{'box'=> DEFAULT_VAGRANT_BOX}, logger: nil)
|
18
16
|
def initialize(name, codedir, config, keep_vm:false, working_dir:nil, logger: nil)
|
19
17
|
|
20
18
|
@name = name
|
21
19
|
@keep_vm = keep_vm
|
22
|
-
@working_dir = working_dir ||
|
20
|
+
@working_dir = File.join((working_dir || PuppetBox::WORKING_DIR), WORKING_DIR_VAGRANT)
|
23
21
|
@config = config
|
24
22
|
@result = Result.new
|
25
23
|
@logger = Logger.new(logger).logger
|
26
24
|
|
27
|
-
|
28
|
-
|
29
|
-
|
25
|
+
# setup the instance
|
26
|
+
@vom = Vagrantomatic::Vagrantomatic.new(vagrant_vm_dir:@working_dir, logger:@logger)
|
27
|
+
@logger.debug("creating instance metadata for #{@name}")
|
28
|
+
@vm = @vom.instance(@name, config:@config)
|
29
|
+
@vm.add_shared_folder("#{codedir}:#{PUPPET_CODE_MOUNT}")
|
30
|
+
|
31
|
+
|
32
|
+
# if ! @config.has_key?("box")
|
33
|
+
# raise "Node #{node_name} must specify box"
|
34
|
+
# end
|
30
35
|
|
31
36
|
# Add the code dir to the config has so that it will automatically become
|
32
37
|
# a shared folder when the VM boots
|
33
38
|
|
34
39
|
# can't use dig() might not be ruby 2.3
|
35
|
-
if @config.has_key?("folders")
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
else
|
48
|
-
|
49
|
-
end
|
50
|
-
@config["folders"] << "#{codedir}:#{PUPPET_CODE_MOUNT}"
|
40
|
+
# if @config.has_key?("folders")
|
41
|
+
# @config["folders"] = Array(@config["folders"])
|
42
|
+
#
|
43
|
+
# # all paths must be fully qualified. If we were asked to do a relative path, change
|
44
|
+
# # it to the current directory since that's probably what the user wanted. Not right?
|
45
|
+
# # user supply correct path!
|
46
|
+
# @config["folders"] = @config["folders"].map { |folder|
|
47
|
+
# if ! folder.start_with? '/'
|
48
|
+
# folder = "#{Dir.pwd}/#{folder}"
|
49
|
+
# end
|
50
|
+
# folder
|
51
|
+
# }
|
52
|
+
# else
|
53
|
+
# @config["folders"] = []
|
54
|
+
# end
|
55
|
+
# @config["folders"] << "#{codedir}:#{PUPPET_CODE_MOUNT}"
|
51
56
|
@logger.debug "instance #{name} initialised"
|
52
57
|
end
|
53
58
|
|
@@ -77,15 +82,17 @@ module PuppetBox
|
|
77
82
|
# make sure working dir exists...
|
78
83
|
FileUtils.mkdir_p(@working_dir)
|
79
84
|
|
80
|
-
vom = Vagrantomatic::Vagrantomatic.new(vagrant_vm_dir
|
85
|
+
# vom = Vagrantomatic::Vagrantomatic.new(vagrant_vm_dir:@working_dir, logger:@logger)
|
81
86
|
|
82
|
-
@logger.debug("
|
83
|
-
@vm = vom.instance(@name)
|
87
|
+
# @logger.debug("creating instance metadata for #{@name}")
|
88
|
+
# @vm = vom.instance(@name, config:@config)
|
84
89
|
|
85
|
-
|
86
|
-
|
87
|
-
|
90
|
+
# obtain 'fixed' metadata from instance
|
91
|
+
# @config = @vm.config
|
92
|
+
# add in our mandatory shared folder
|
93
|
+
# @vm.add_shared_folder("#{codedir}:#{PUPPET_CODE_MOUNT}")
|
88
94
|
@vm.save
|
95
|
+
|
89
96
|
@logger.debug("Instance saved and ready for starting")
|
90
97
|
started = @vm.start
|
91
98
|
end
|
@@ -103,6 +110,10 @@ module PuppetBox
|
|
103
110
|
@vm.reset
|
104
111
|
end
|
105
112
|
|
113
|
+
def validate_config
|
114
|
+
@vm.validate_config
|
115
|
+
end
|
116
|
+
|
106
117
|
# Test that a VM is operational and able to run puppet
|
107
118
|
def self_test()
|
108
119
|
status_code, messages = @vm.run("sudo -i puppet --version")
|
data/lib/puppetbox/puppetbox.rb
CHANGED
@@ -2,11 +2,14 @@ require "puppetbox/result_set"
|
|
2
2
|
require "puppetbox/logger"
|
3
3
|
require "puppetbox/nodeset"
|
4
4
|
require "puppetbox/driver/vagrant"
|
5
|
+
require "puppetbox/report"
|
5
6
|
|
6
7
|
module PuppetBox
|
7
8
|
class PuppetBox
|
8
9
|
|
9
|
-
|
10
|
+
WORKING_DIR = File.join(Dir.home, '.puppetbox')
|
11
|
+
|
12
|
+
def initialize(logger:nil, nodeset_file: nil, working_dir: nil)
|
10
13
|
# The results of all tests on all driver instances
|
11
14
|
@result_set = ResultSet.new
|
12
15
|
|
@@ -20,6 +23,8 @@ module PuppetBox
|
|
20
23
|
# talk to use about nodes of particular name and puppetbox will sort out
|
21
24
|
# the how and why of what this exactly should involve
|
22
25
|
@nodeset = NodeSet.new(nodeset_file)
|
26
|
+
|
27
|
+
@working_dir = working_dir || WORKING_DIR
|
23
28
|
end
|
24
29
|
|
25
30
|
|
@@ -70,8 +75,11 @@ module PuppetBox
|
|
70
75
|
config,
|
71
76
|
# "#{repo.tempdir}/etc/puppetlabs/code/environments/production",
|
72
77
|
logger: @logger,
|
73
|
-
|
78
|
+
working_dir: @working_dir,
|
74
79
|
)
|
80
|
+
|
81
|
+
# immediately validate the configuration to allow us to fail-fast
|
82
|
+
di.validate_config
|
75
83
|
else
|
76
84
|
raise "PuppetBox only supports driver: 'vagrant' at the moment (requested: #{driver})"
|
77
85
|
end
|
@@ -123,29 +131,16 @@ module PuppetBox
|
|
123
131
|
|
124
132
|
# Print all results to STDOUT
|
125
133
|
def print_results
|
126
|
-
|
127
|
-
indent = " "
|
128
|
-
puts "\n\n\nSummary\n======="
|
129
|
-
summary.each { |node, class_results|
|
130
|
-
puts node
|
131
|
-
if class_results.class == String
|
132
|
-
puts "#{indent}#{class_results}"
|
133
|
-
else
|
134
|
-
class_results.each { |puppet_class, passed|
|
135
|
-
line = "#{indent}#{puppet_class}: #{passed ? "OK": "FAILED"}"
|
136
|
-
if passed
|
137
|
-
puts line.green
|
138
|
-
else
|
139
|
-
puts line.red
|
140
|
-
end
|
141
|
-
}
|
142
|
-
end
|
143
|
-
}
|
144
|
-
|
145
|
-
puts "Overall acceptance testing result #{overall}"
|
134
|
+
Report::print(@result_set)
|
146
135
|
end
|
147
136
|
|
137
|
+
def result_set
|
138
|
+
@result_set
|
139
|
+
end
|
148
140
|
|
141
|
+
def passed?
|
142
|
+
@result_set.passed?
|
143
|
+
end
|
149
144
|
|
150
145
|
# Run puppet using `driver_instance` to execute
|
151
146
|
def run_puppet(driver_instance, puppet_classes, logger:nil, reset_after_run:true)
|
@@ -153,32 +148,29 @@ module PuppetBox
|
|
153
148
|
logger = logger || @logger
|
154
149
|
logger.debug("#{driver_instance.node_name} running test for #{puppet_classes}")
|
155
150
|
puppet_classes = Array(puppet_classes)
|
156
|
-
|
151
|
+
|
157
152
|
if driver_instance.open
|
158
153
|
logger.debug("#{driver_instance.node_name} started")
|
159
154
|
if driver_instance.self_test
|
160
155
|
logger.debug("#{driver_instance.node_name} self_test OK, running puppet")
|
161
156
|
puppet_classes.each{ |puppet_class|
|
162
|
-
if
|
157
|
+
if @result_set.class_size(driver_instance.node_name) > 0 and reset_after_run
|
163
158
|
# purge and reboot the vm - this will save approximately 1 second
|
164
159
|
# per class on the self-test which we now know will succeed
|
165
160
|
driver_instance.reset
|
166
161
|
end
|
167
162
|
driver_instance.run_puppet_x2(puppet_class)
|
168
|
-
|
163
|
+
@result_set.save(driver_instance.node_name, puppet_class, driver_instance.result)
|
169
164
|
}
|
170
165
|
logger.debug("#{driver_instance.node_name} test completed, closing instance")
|
171
|
-
driver_instance.close
|
172
166
|
else
|
173
|
-
driver_instance.close
|
174
167
|
raise "#{driver_instance.node_name} self test failed, unable to continue"
|
175
168
|
end
|
176
169
|
else
|
177
|
-
driver_instance.close
|
178
170
|
raise "#{driver_instance.node_name} failed to start, unable to continue"
|
179
171
|
end
|
180
172
|
|
181
|
-
|
173
|
+
driver_instance.close
|
182
174
|
end
|
183
175
|
|
184
176
|
end
|
data/lib/puppetbox/report.rb
CHANGED
@@ -1,27 +1,27 @@
|
|
1
|
+
require 'colorize'
|
1
2
|
module PuppetBox
|
2
3
|
module Report
|
3
|
-
def self.
|
4
|
+
def self.pretty_status(passed)
|
5
|
+
passed ? 'OK'.green: 'FAILED'.red
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.print(result_set, stream=$stdout)
|
4
9
|
# print the report summary
|
5
10
|
indent = " "
|
6
11
|
stream.puts "\n\n\nSummary\n======="
|
7
|
-
|
8
|
-
puts node
|
12
|
+
result_set.results.each { |node, class_results|
|
13
|
+
stream.puts node
|
9
14
|
if class_results.class == String
|
10
15
|
stream.puts "#{indent}#{class_results}"
|
11
16
|
else
|
12
|
-
class_results.each { |puppet_class,
|
13
|
-
|
14
|
-
if passed
|
15
|
-
stream.puts line.green
|
16
|
-
else
|
17
|
-
stream.puts line.red
|
18
|
-
end
|
17
|
+
class_results.each { |puppet_class, result|
|
18
|
+
stream.puts "#{indent}#{puppet_class}: #{pretty_status(result.passed?)}"
|
19
19
|
}
|
20
20
|
end
|
21
21
|
}
|
22
22
|
|
23
|
-
stream.puts "
|
24
|
-
overall
|
23
|
+
stream.puts "\n\nOVERALL STATUS: #{pretty_status(result_set.passed?)}"
|
25
24
|
end
|
25
|
+
|
26
26
|
end
|
27
27
|
end
|
data/lib/puppetbox/result.rb
CHANGED
data/lib/puppetbox/result_set.rb
CHANGED
@@ -27,6 +27,7 @@ module PuppetBox
|
|
27
27
|
end
|
28
28
|
|
29
29
|
def passed?
|
30
|
+
! @results.empty? and
|
30
31
|
@results.map { |node_name, class_results_hash|
|
31
32
|
class_results_hash.map { |class_name, class_results|
|
32
33
|
class_results.passed?
|
@@ -34,7 +35,7 @@ module PuppetBox
|
|
34
35
|
}.all?
|
35
36
|
end
|
36
37
|
|
37
|
-
def
|
38
|
+
def results
|
38
39
|
@results
|
39
40
|
end
|
40
41
|
|
@@ -59,7 +60,7 @@ module PuppetBox
|
|
59
60
|
def test_size
|
60
61
|
@results.map {|node_name, classes|
|
61
62
|
classes.size
|
62
|
-
}.reduce(:+)
|
63
|
+
}.reduce(:+) || 0
|
63
64
|
end
|
64
65
|
|
65
66
|
|
data/lib/puppetbox/version.rb
CHANGED
data/puppetbox.gemspec
CHANGED
@@ -23,5 +23,6 @@ Gem::Specification.new do |spec|
|
|
23
23
|
spec.add_development_dependency "rake", "~> 10.0"
|
24
24
|
spec.add_development_dependency "rspec", "~> 3.0"
|
25
25
|
|
26
|
-
spec.add_dependency "vagrantomatic", "0.2
|
26
|
+
spec.add_dependency "vagrantomatic", "0.3.2"
|
27
|
+
spec.add_dependency "colorize"
|
27
28
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: puppetbox
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Geoff Williams
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-04-
|
11
|
+
date: 2017-04-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -58,14 +58,28 @@ dependencies:
|
|
58
58
|
requirements:
|
59
59
|
- - '='
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: 0.2
|
61
|
+
version: 0.3.2
|
62
62
|
type: :runtime
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - '='
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: 0.2
|
68
|
+
version: 0.3.2
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: colorize
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
69
83
|
description:
|
70
84
|
email:
|
71
85
|
- geoff@geoffwilliams.me.uk
|