puppetbox 0.3.1 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/puppetbox/driver/vagrant.rb +8 -37
- data/lib/puppetbox/driver.rb +1 -15
- data/lib/puppetbox/nodeset.rb +0 -22
- data/lib/puppetbox/puppetbox.rb +12 -45
- data/lib/puppetbox/report.rb +20 -0
- data/lib/puppetbox/result.rb +6 -0
- data/lib/puppetbox/version.rb +1 -1
- data/lib/puppetbox.rb +0 -2
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 393f46fa2e8abcca2e2fd278c4c4732af09ba444
|
4
|
+
data.tar.gz: 7dc52e48c12005dff1122fa6f900064f86b8bf16
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cb725f0228784ae8560c4f0de5a7bad886a1fa7a205c8c9185f9431240e8ffe3f98b5335d01c6bb3064b56d7200feddab0683bdfb7683ea673504a2a889e6938
|
7
|
+
data.tar.gz: 45bae316cd000af9dc4f5b4a7936bdd10c58d56037181b80305148e0afec2387aa8e53d262710a550d37ac7ce61ce0fc3eb4d3c717316207e2cf835446095ebd
|
@@ -6,8 +6,9 @@ require "puppetbox/logger"
|
|
6
6
|
module PuppetBox
|
7
7
|
module Driver
|
8
8
|
class Vagrant
|
9
|
-
WORKING_DIR_VAGRANT
|
10
|
-
PUPPET_CODE_MOUNT
|
9
|
+
WORKING_DIR_VAGRANT = "vagrant"
|
10
|
+
PUPPET_CODE_MOUNT = "/etc/puppetlabs/code/environments/production"
|
11
|
+
SPEC_ACCEPTANCE_MOUNT = "spec/acceptance:/acceptance"
|
11
12
|
|
12
13
|
def node_name
|
13
14
|
@name
|
@@ -26,33 +27,13 @@ module PuppetBox
|
|
26
27
|
@vom = Vagrantomatic::Vagrantomatic.new(vagrant_vm_dir:@working_dir, logger:@logger)
|
27
28
|
@logger.debug("creating instance metadata for #{@name}")
|
28
29
|
@vm = @vom.instance(@name, config:@config)
|
30
|
+
|
31
|
+
# the code under test
|
29
32
|
@vm.add_shared_folder("#{codedir}:#{PUPPET_CODE_MOUNT}")
|
30
33
|
|
34
|
+
# ./spec/acceptance directory
|
35
|
+
@vm.add_shared_folder(SPEC_ACCEPTANCE_MOUNT)
|
31
36
|
|
32
|
-
# if ! @config.has_key?("box")
|
33
|
-
# raise "Node #{node_name} must specify box"
|
34
|
-
# end
|
35
|
-
|
36
|
-
# Add the code dir to the config has so that it will automatically become
|
37
|
-
# a shared folder when the VM boots
|
38
|
-
|
39
|
-
# can't use dig() might not be ruby 2.3
|
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}"
|
56
37
|
@logger.debug "instance #{name} initialised"
|
57
38
|
end
|
58
39
|
|
@@ -81,16 +62,6 @@ module PuppetBox
|
|
81
62
|
def open()
|
82
63
|
# make sure working dir exists...
|
83
64
|
FileUtils.mkdir_p(@working_dir)
|
84
|
-
|
85
|
-
# vom = Vagrantomatic::Vagrantomatic.new(vagrant_vm_dir:@working_dir, logger:@logger)
|
86
|
-
|
87
|
-
# @logger.debug("creating instance metadata for #{@name}")
|
88
|
-
# @vm = vom.instance(@name, config:@config)
|
89
|
-
|
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}")
|
94
65
|
@vm.save
|
95
66
|
|
96
67
|
@logger.debug("Instance saved and ready for starting")
|
@@ -101,7 +72,7 @@ module PuppetBox
|
|
101
72
|
# anything on SSH...)
|
102
73
|
def close()
|
103
74
|
if ! @keep_vm
|
104
|
-
@logger.info("Closing #{@
|
75
|
+
@logger.info("Closing #{@name}")
|
105
76
|
@vm.purge
|
106
77
|
end
|
107
78
|
end
|
data/lib/puppetbox/driver.rb
CHANGED
@@ -1,20 +1,6 @@
|
|
1
1
|
module PuppetBox
|
2
|
-
# New drivers must implement the methods in this class (via ductyping)
|
3
2
|
class Driver
|
4
|
-
|
5
|
-
# end
|
6
|
-
#
|
7
|
-
# def self.open()
|
8
|
-
# end
|
9
|
-
#
|
10
|
-
# def self.close()
|
11
|
-
# end
|
12
|
-
#
|
13
|
-
# def self.selftest()
|
14
|
-
# end
|
15
|
-
#
|
16
|
-
# def self.puppet_apply_x2(puppet_class)
|
17
|
-
# end
|
3
|
+
|
18
4
|
end
|
19
5
|
|
20
6
|
end
|
data/lib/puppetbox/nodeset.rb
CHANGED
@@ -55,27 +55,5 @@ module PuppetBox
|
|
55
55
|
end
|
56
56
|
end
|
57
57
|
|
58
|
-
#
|
59
|
-
#
|
60
|
-
# if nodeset["hosts"][node.name].has_key?('config') and nodeset_yaml["HOSTS"][node.name].has_key?('driver')
|
61
|
-
# test.classes.each { |puppet_class|
|
62
|
-
# logger.info "Acceptance testing #{node.name} #{puppet_class.name}"
|
63
|
-
# summary[node.name][puppet_class.name] = pb.provision_and_test(
|
64
|
-
# nodeset_yaml["HOSTS"][node.name]["driver"],
|
65
|
-
# node.name,
|
66
|
-
# puppet_class.name,
|
67
|
-
# nodeset_yaml["HOSTS"][node.name]['config'],
|
68
|
-
# @repo,
|
69
|
-
# )
|
70
|
-
#
|
71
|
-
# overall &= ! summary[node.name][puppet_class.name]
|
72
|
-
# }
|
73
|
-
# else
|
74
|
-
# message = "onceover-nodes.yaml missing `config` or `driver` element for #{node.name} (tests skipped)"
|
75
|
-
# summary[node.name] = message
|
76
|
-
# overall = false
|
77
|
-
# end
|
78
|
-
# end
|
79
|
-
|
80
58
|
end
|
81
59
|
end
|
data/lib/puppetbox/puppetbox.rb
CHANGED
@@ -32,11 +32,7 @@ module PuppetBox
|
|
32
32
|
def enqueue_test(node_name, run_from, puppet_class)
|
33
33
|
instantiate_driver(node_name, run_from)
|
34
34
|
@testsuite[node_name]["classes"] << puppet_class
|
35
|
-
|
36
|
-
# node_name
|
37
|
-
# puppet_class.name,
|
38
|
-
# nodeset_yaml["HOSTS"][node.name]['config'],
|
39
|
-
# @repo,
|
35
|
+
|
40
36
|
end
|
41
37
|
|
42
38
|
def run_testsuite
|
@@ -89,47 +85,10 @@ module PuppetBox
|
|
89
85
|
"classes" => [],
|
90
86
|
}
|
91
87
|
end
|
92
|
-
|
93
|
-
# di
|
94
|
-
# result = ::PuppetBox.run_puppet(di, puppet_class)
|
95
|
-
|
96
|
-
# indent = " "
|
97
|
-
# if result.passed
|
98
|
-
# logger.info("#{indent}#{host}:#{puppet_class} --> PASSED")
|
99
|
-
# else
|
100
|
-
# logger.error("#{indent}#{host}:#{puppet_class} --> FAILED")
|
101
|
-
# # since we stop running on failure, the error messages will be in the
|
102
|
-
# # last element of the result.messages array (tada!)
|
103
|
-
# messages = result.messages
|
104
|
-
# messages[-1].each { |line|
|
105
|
-
# # puts "XXXXXXX #{line}"
|
106
|
-
# logger.error "#{indent}#{host} - #{line}"
|
107
|
-
# }
|
108
|
-
# # puts "size of result messages #{result.messages.size}"
|
109
|
-
# # puts "size of result messages #{result.messages[0].size}"
|
110
|
-
# # run.each { |message_arr|
|
111
|
-
# # puts message_arr
|
112
|
-
# # #message_arr.each { |line|
|
113
|
-
# # # puts line
|
114
|
-
# # # }
|
115
|
-
# # # require 'pry'
|
116
|
-
# # # binding.pry
|
117
|
-
# # #puts "messages size"
|
118
|
-
# # #puts messages.size
|
119
|
-
# # # messages.each { |message|
|
120
|
-
# # # messages from the puppet run are avaiable in a nested array of run
|
121
|
-
# # # and then lines so lets print each one out indended from the host so
|
122
|
-
# # # we can see what's what
|
123
|
-
# # # logger.error("#{host} #{message}")
|
124
|
-
# # # }
|
125
|
-
# # }
|
126
|
-
# # }
|
127
|
-
# end
|
128
|
-
# result.passed
|
129
88
|
end
|
130
89
|
|
131
|
-
|
132
|
-
#
|
90
|
+
# Print a summary of *all* results to STDOUT. Does not include the error(s)
|
91
|
+
# if any - these would have been printed after each individual test ran
|
133
92
|
def print_results
|
134
93
|
Report::print(@result_set)
|
135
94
|
end
|
@@ -153,14 +112,22 @@ module PuppetBox
|
|
153
112
|
logger.debug("#{driver_instance.node_name} started")
|
154
113
|
if driver_instance.self_test
|
155
114
|
logger.debug("#{driver_instance.node_name} self_test OK, running puppet")
|
156
|
-
puppet_classes.each{ |puppet_class|
|
115
|
+
puppet_classes.each { |puppet_class|
|
157
116
|
if @result_set.class_size(driver_instance.node_name) > 0 and reset_after_run
|
158
117
|
# purge and reboot the vm - this will save approximately 1 second
|
159
118
|
# per class on the self-test which we now know will succeed
|
160
119
|
driver_instance.reset
|
161
120
|
end
|
121
|
+
logger.info("running test #{driver_instance.node_name} - #{puppet_class}")
|
162
122
|
driver_instance.run_puppet_x2(puppet_class)
|
163
123
|
@result_set.save(driver_instance.node_name, puppet_class, driver_instance.result)
|
124
|
+
|
125
|
+
Report::log_test_result_or_errors(
|
126
|
+
@logger,
|
127
|
+
driver_instance.node_name,
|
128
|
+
puppet_class,
|
129
|
+
driver_instance.result,
|
130
|
+
)
|
164
131
|
}
|
165
132
|
logger.debug("#{driver_instance.node_name} test completed, closing instance")
|
166
133
|
else
|
data/lib/puppetbox/report.rb
CHANGED
@@ -23,5 +23,25 @@ module PuppetBox
|
|
23
23
|
stream.puts "\n\nOVERALL STATUS: #{pretty_status(result_set.passed?)}"
|
24
24
|
end
|
25
25
|
|
26
|
+
|
27
|
+
# Print an individual test's result or if it failed, it's errors.
|
28
|
+
def self.log_test_result_or_errors(logger, node_name, puppet_class, result)
|
29
|
+
indent = " "
|
30
|
+
tag = "#{indent}#{node_name} - #{puppet_class}"
|
31
|
+
logger.info("#{tag}: #{pretty_status(result.passed?)}")
|
32
|
+
if ! result.passed?
|
33
|
+
# since we stop running on failure, the error messages will be in the
|
34
|
+
# last element of the result.messages array (tada!)
|
35
|
+
messages = result.messages
|
36
|
+
if messages.empty?
|
37
|
+
logger.error "#{tag} - no output available"
|
38
|
+
else
|
39
|
+
messages[-1].each { |line|
|
40
|
+
logger.error "#{tag} - #{line}"
|
41
|
+
}
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
26
46
|
end
|
27
47
|
end
|
data/lib/puppetbox/result.rb
CHANGED
@@ -18,12 +18,18 @@ module PuppetBox
|
|
18
18
|
@report = []
|
19
19
|
end
|
20
20
|
|
21
|
+
# Puppet exit codes:
|
21
22
|
# 0: The run succeeded with no changes or failures; the system was already in the desired state.
|
22
23
|
# 1: The run failed, or wasn't attempted due to another run already in progress.
|
23
24
|
# 2: The run succeeded, and some resources were changed.
|
24
25
|
# 4: The run succeeded, and some resources failed.
|
25
26
|
# 6: The run succeeded, and included both changes and failures.
|
26
27
|
def save(status_code, messages)
|
28
|
+
|
29
|
+
# messages will usually be an array of output - one per line, but it might
|
30
|
+
# not be and everthing expects to be so just turn it into one if it isn't
|
31
|
+
# already...
|
32
|
+
messages = Array(messages)
|
27
33
|
status = PS_ERROR
|
28
34
|
if @report.empty?
|
29
35
|
# first run
|
data/lib/puppetbox/version.rb
CHANGED
data/lib/puppetbox.rb
CHANGED