puppet-catalog-test 0.1.0 → 0.2.0
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.
- data/README.md +16 -7
- data/bin/puppet-catalog-test +19 -8
- data/lib/puppet-catalog-test.rb +2 -1
- data/lib/puppet-catalog-test/filter.rb +10 -0
- data/lib/puppet-catalog-test/rake_task.rb +13 -4
- data/lib/puppet-catalog-test/test_runner.rb +30 -4
- data/puppet-catalog-test.gemspec +3 -3
- metadata +6 -4
data/README.md
CHANGED
@@ -1,16 +1,22 @@
|
|
1
|
-
# Test all your puppet catalogs for compiler errors
|
1
|
+
# Test all your puppet catalogs for compiler warnings and errors
|
2
|
+
|
3
|
+
puppet-catalog-test is a tool for capturing and testing warnings and errors the puppet-compiler is emitting during the compilation process.
|
4
|
+
|
5
|
+
For a more detailed insight into the puppet-compiler, you can take a look at <http://www.masterzen.fr/2012/03/17/puppet-internals-the-compiler/>.
|
2
6
|
|
3
7
|
## Installation
|
4
8
|
|
5
|
-
gem install puppet-catalog-
|
9
|
+
gem install puppet-catalog-test
|
6
10
|
|
7
11
|
## Usage
|
8
12
|
```bash
|
9
13
|
$ puppet-catalog-test -h
|
14
|
+
|
10
15
|
USAGE: puppet-catalog-test [options]
|
11
16
|
-m, --module-paths PATHS Location of puppet modules, separated by collon
|
12
17
|
-M, --manifest-path PATH Location of the puppet manifests (site.pp)
|
13
|
-
-
|
18
|
+
-i, --include-pattern PATTERN Include only test cases that match pattern
|
19
|
+
-e, --exclude-pattern PATTERN Exclude test cases that match pattern
|
14
20
|
-s, --scenario FILE Scenario definition to use
|
15
21
|
-h, --help Show this message
|
16
22
|
```
|
@@ -61,7 +67,8 @@ namespace :catalog do
|
|
61
67
|
t.module_paths = ["modules"]
|
62
68
|
t.manifest_path = File.join("scripts", "site.pp")
|
63
69
|
|
64
|
-
t.
|
70
|
+
t.include_pattern = ENV["include"]
|
71
|
+
t.exclude_pattern = ENV["exclude"]
|
65
72
|
end
|
66
73
|
end
|
67
74
|
```
|
@@ -96,7 +103,8 @@ namespace :catalog do
|
|
96
103
|
"operatingsystem" => "RedHat"
|
97
104
|
}
|
98
105
|
|
99
|
-
t.
|
106
|
+
t.include_pattern = ENV["include"]
|
107
|
+
t.exclude_pattern = ENV["exclude"]
|
100
108
|
end
|
101
109
|
end
|
102
110
|
```
|
@@ -115,7 +123,8 @@ namespace :catalog do
|
|
115
123
|
|
116
124
|
t.scenario_yaml = "scenarios.yml"
|
117
125
|
|
118
|
-
t.
|
126
|
+
t.include_pattern = ENV["include"]
|
127
|
+
t.exclude_pattern = ENV["exclude"]
|
119
128
|
end
|
120
129
|
end
|
121
130
|
```
|
@@ -153,7 +162,7 @@ REDHAT_db-dev:
|
|
153
162
|
|
154
163
|
## Reporters (output plugins)
|
155
164
|
|
156
|
-
Per default puppet-catalog-test
|
165
|
+
Per default puppet-catalog-test uses the StdoutReporter which prints the result like in the examples above. Besides this you can use in your own Reporter.
|
157
166
|
|
158
167
|
Puppet-Catalog-Test also ships a JunitXmlReporter which creates a junit compatible xml report.
|
159
168
|
|
data/bin/puppet-catalog-test
CHANGED
@@ -1,11 +1,12 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
+
# allow loading library from workspace
|
4
|
+
$:.unshift(File.join(File.dirname(__FILE__), "..", "lib"))
|
5
|
+
|
3
6
|
require "puppet-catalog-test"
|
4
7
|
require "optparse"
|
5
8
|
|
6
|
-
options = {
|
7
|
-
:filter => PuppetCatalogTest::DEFAULT_FILTER
|
8
|
-
}
|
9
|
+
options = {}
|
9
10
|
|
10
11
|
opt_parser = OptionParser.new do |opts|
|
11
12
|
opts.banner = "USAGE: #{File.basename($0)} [options]"
|
@@ -18,8 +19,12 @@ opt_parser = OptionParser.new do |opts|
|
|
18
19
|
options[:manifest_path] = arg
|
19
20
|
end
|
20
21
|
|
21
|
-
opts.on("-
|
22
|
-
options[:
|
22
|
+
opts.on("-i", "--include-pattern PATTERN", "Include only test cases that match pattern") do |arg|
|
23
|
+
options[:include_pattern] = arg
|
24
|
+
end
|
25
|
+
|
26
|
+
opts.on("-e", "--exclude-pattern PATTERN", "Exclude test cases that match pattern") do |arg|
|
27
|
+
options[:exclude_pattern] = arg
|
23
28
|
end
|
24
29
|
|
25
30
|
opts.on("-s", "--scenario FILE", "Scenario definition to use") do |arg|
|
@@ -39,12 +44,18 @@ if options.empty?
|
|
39
44
|
exit
|
40
45
|
end
|
41
46
|
|
42
|
-
pct = PuppetCatalogTest::TestRunner.new(
|
47
|
+
pct = PuppetCatalogTest::TestRunner.new(
|
48
|
+
:manifest_path => options[:manifest_path],
|
49
|
+
:module_paths => options[:module_paths])
|
50
|
+
|
51
|
+
filter = PuppetCatalogTest::Filter.new
|
52
|
+
filter.include_pattern = options[:include_pattern] if options.has_key?(:include_pattern)
|
53
|
+
filter.exclude_pattern = options[:exclude_pattern] if options.has_key?(:exclude_pattern)
|
43
54
|
|
44
55
|
if options[:scenario]
|
45
|
-
pct.load_scenario_yaml(options[:scenario],
|
56
|
+
pct.load_scenario_yaml(options[:scenario], filter)
|
46
57
|
else
|
47
|
-
pct.load_all(
|
58
|
+
pct.load_all(filter)
|
48
59
|
end
|
49
60
|
|
50
61
|
pct.run_tests!
|
data/lib/puppet-catalog-test.rb
CHANGED
@@ -8,15 +8,14 @@ module PuppetCatalogTest
|
|
8
8
|
attr_accessor :module_paths
|
9
9
|
attr_accessor :manifest_path
|
10
10
|
attr_accessor :scenario_yaml
|
11
|
-
attr_accessor :
|
11
|
+
attr_accessor :include_pattern
|
12
|
+
attr_accessor :exclude_pattern
|
12
13
|
attr_accessor :facts
|
13
14
|
attr_accessor :reporter
|
14
15
|
|
15
16
|
def initialize(name, &task_block)
|
16
17
|
desc "Compile all puppet catalogs" unless ::Rake.application.last_comment
|
17
18
|
|
18
|
-
@filter = PuppetCatalogTest::DEFAULT_FILTER
|
19
|
-
|
20
19
|
task name do
|
21
20
|
task_block.call(self) if task_block
|
22
21
|
setup
|
@@ -24,7 +23,17 @@ module PuppetCatalogTest
|
|
24
23
|
end
|
25
24
|
|
26
25
|
def setup
|
27
|
-
|
26
|
+
puppet_config = {
|
27
|
+
:manifest_path => @manifest_path,
|
28
|
+
:module_paths => @module_paths
|
29
|
+
}
|
30
|
+
|
31
|
+
pct = TestRunner.new(puppet_config)
|
32
|
+
|
33
|
+
@filter = Filter.new
|
34
|
+
|
35
|
+
@filter.include_pattern = @include_pattern if @include_pattern
|
36
|
+
@filter.exclude_pattern = @exclude_pattern if @exclude_pattern
|
28
37
|
|
29
38
|
if @scenario_yaml
|
30
39
|
pct.load_scenario_yaml(@scenario_yaml, @filter)
|
@@ -12,7 +12,11 @@ module PuppetCatalogTest
|
|
12
12
|
attr_reader :test_cases
|
13
13
|
attr_reader :total_duration
|
14
14
|
|
15
|
-
def initialize(
|
15
|
+
def initialize(puppet_config, stdout_target = $stdout)
|
16
|
+
if !puppet_config
|
17
|
+
raise ArgumentError, "No puppet_config hash supplied"
|
18
|
+
end
|
19
|
+
|
16
20
|
@test_cases = []
|
17
21
|
@exit_on_fail = true
|
18
22
|
@out = stdout_target
|
@@ -21,6 +25,10 @@ module PuppetCatalogTest
|
|
21
25
|
|
22
26
|
@total_duration = nil
|
23
27
|
|
28
|
+
manifest_path = puppet_config[:manifest_path]
|
29
|
+
module_paths = puppet_config[:module_paths]
|
30
|
+
config_dir = puppet_config[:config_dir]
|
31
|
+
|
24
32
|
raise ArgumentError, "[ERROR] manifest_path must be specified" if !manifest_path
|
25
33
|
raise ArgumentError, "[ERROR] manifest_path (#{manifest_path}) does not exist" if !FileTest.exist?(manifest_path)
|
26
34
|
|
@@ -29,6 +37,10 @@ module PuppetCatalogTest
|
|
29
37
|
raise ArgumentError, "[ERROR] module_path (#{mp}) does not exist" if !FileTest.directory?(mp)
|
30
38
|
end
|
31
39
|
|
40
|
+
if config_dir
|
41
|
+
Puppet.settings.handlearg("--confdir", config_dir)
|
42
|
+
end
|
43
|
+
|
32
44
|
Puppet.settings.handlearg("--config", ".")
|
33
45
|
Puppet.settings.handlearg("--manifest", manifest_path)
|
34
46
|
|
@@ -44,13 +56,17 @@ module PuppetCatalogTest
|
|
44
56
|
|
45
57
|
scenarios.each do |tc_name, facts|
|
46
58
|
next if tc_name =~ /^__/
|
47
|
-
|
59
|
+
|
60
|
+
if filter
|
61
|
+
next if filter.exclude_pattern && tc_name.match(filter.exclude_pattern)
|
62
|
+
next if filter.include_pattern && !tc_name.match(filter.include_pattern)
|
63
|
+
end
|
48
64
|
|
49
65
|
add_test_case(tc_name, facts)
|
50
66
|
end
|
51
67
|
end
|
52
68
|
|
53
|
-
def load_all(filter =
|
69
|
+
def load_all(filter = Filter.new, facts = {})
|
54
70
|
nodes = collect_puppet_nodes(filter)
|
55
71
|
|
56
72
|
nodes.each do |n|
|
@@ -85,7 +101,16 @@ module PuppetCatalogTest
|
|
85
101
|
def collect_puppet_nodes(filter)
|
86
102
|
parser = Puppet::Parser::Parser.new("environment")
|
87
103
|
nodes = parser.environment.known_resource_types.nodes.keys
|
88
|
-
|
104
|
+
|
105
|
+
if filter.exclude_pattern
|
106
|
+
nodes.delete_if { |node| node.match(filter.exclude_pattern) }
|
107
|
+
end
|
108
|
+
|
109
|
+
if filter.include_pattern
|
110
|
+
nodes.delete_if { |node| !node.match(filter.include_pattern) }
|
111
|
+
end
|
112
|
+
|
113
|
+
nodes
|
89
114
|
end
|
90
115
|
|
91
116
|
def run_tests!
|
@@ -108,6 +133,7 @@ module PuppetCatalogTest
|
|
108
133
|
@reporter.report_passed_test_case(tc)
|
109
134
|
end
|
110
135
|
rescue => error
|
136
|
+
p error if $DEBUG
|
111
137
|
tc.duration = Time.now - tc_start_time
|
112
138
|
tc.error = error.message
|
113
139
|
tc.passed = false
|
data/puppet-catalog-test.gemspec
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = 'puppet-catalog-test'
|
3
|
-
s.version = '0.
|
3
|
+
s.version = '0.2.0'
|
4
4
|
s.homepage = 'https://github.com/invadersmustdie/puppet-catalog-test/'
|
5
|
-
s.summary = '
|
6
|
-
s.description = '
|
5
|
+
s.summary = 'Test all your puppet catalogs for compiler warnings and errors'
|
6
|
+
s.description = 'Test all your puppet catalogs for compiler warnings and errors.'
|
7
7
|
|
8
8
|
s.executables = ['puppet-catalog-test']
|
9
9
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: puppet-catalog-test
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-03-24 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: puppet
|
@@ -27,7 +27,7 @@ dependencies:
|
|
27
27
|
- - ! '>='
|
28
28
|
- !ruby/object:Gem::Version
|
29
29
|
version: '0'
|
30
|
-
description:
|
30
|
+
description: Test all your puppet catalogs for compiler warnings and errors.
|
31
31
|
email: rene.lengwinat@googlemail.com
|
32
32
|
executables:
|
33
33
|
- puppet-catalog-test
|
@@ -39,6 +39,7 @@ files:
|
|
39
39
|
- Rakefile
|
40
40
|
- README.md
|
41
41
|
- puppet-catalog-test.gemspec
|
42
|
+
- lib/puppet-catalog-test/filter.rb
|
42
43
|
- lib/puppet-catalog-test/junit_xml_reporter.rb
|
43
44
|
- lib/puppet-catalog-test/rake_task.rb
|
44
45
|
- lib/puppet-catalog-test/stdout_reporter.rb
|
@@ -68,5 +69,6 @@ rubyforge_project:
|
|
68
69
|
rubygems_version: 1.8.24
|
69
70
|
signing_key:
|
70
71
|
specification_version: 3
|
71
|
-
summary:
|
72
|
+
summary: Test all your puppet catalogs for compiler warnings and errors
|
72
73
|
test_files: []
|
74
|
+
has_rdoc:
|