puppet-syntax 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +4 -0
- data/README.md +19 -1
- data/lib/puppet-syntax.rb +1 -0
- data/lib/puppet-syntax/hiera.rb +23 -0
- data/lib/puppet-syntax/tasks/puppet-syntax.rb +19 -0
- data/lib/puppet-syntax/version.rb +1 -1
- data/spec/fixtures/hiera/hiera_bad.yaml +1 -0
- data/spec/fixtures/hiera/hiera_bad_18.yaml +3 -0
- data/spec/fixtures/hiera/hiera_good.yaml +7 -0
- data/spec/puppet-syntax/hiera_spec.rb +29 -0
- data/spec/spec_helper.rb +7 -3
- metadata +13 -4
data/CHANGELOG
CHANGED
data/README.md
CHANGED
@@ -1,6 +1,16 @@
|
|
1
1
|
# Puppet::Syntax
|
2
2
|
|
3
|
-
Syntax checks for Puppet manifests and templates
|
3
|
+
Syntax checks for Puppet manifests and templates.
|
4
|
+
|
5
|
+
## Version support
|
6
|
+
|
7
|
+
This should work on any version of:
|
8
|
+
|
9
|
+
- Puppet >= 2.7 that provides the `validate` face.
|
10
|
+
- Ruby >= 1.8 with `erb` from stdlib.
|
11
|
+
|
12
|
+
You can see the matrix of specific versions that we currently test against
|
13
|
+
in the [TravisCI config](.travis.yml).
|
4
14
|
|
5
15
|
## Usage
|
6
16
|
|
@@ -23,6 +33,14 @@ A non-zero exit code and error message will be returned for any failures:
|
|
23
33
|
Tasks: TOP => syntax => syntax:manifests
|
24
34
|
(See full trace by running task with --trace)
|
25
35
|
|
36
|
+
Use in conjunction with lint and spec tests for Continuous Integration:
|
37
|
+
|
38
|
+
task :test => [
|
39
|
+
:syntax,
|
40
|
+
:lint,
|
41
|
+
:spec,
|
42
|
+
]
|
43
|
+
|
26
44
|
## Configuration
|
27
45
|
|
28
46
|
Paths can be excluded with:
|
data/lib/puppet-syntax.rb
CHANGED
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
|
3
|
+
module PuppetSyntax
|
4
|
+
class Hiera
|
5
|
+
def check(filelist)
|
6
|
+
raise "Expected an array of files" unless filelist.is_a?(Array)
|
7
|
+
|
8
|
+
errors = []
|
9
|
+
|
10
|
+
filelist.each do |hiera_file|
|
11
|
+
begin
|
12
|
+
YAML.load_file(hiera_file)
|
13
|
+
rescue Exception => error
|
14
|
+
errors << error
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
errors.map! { |e| e.to_s }
|
19
|
+
|
20
|
+
errors
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -9,6 +9,7 @@ module PuppetSyntax
|
|
9
9
|
task :syntax => [
|
10
10
|
'syntax:manifests',
|
11
11
|
'syntax:templates',
|
12
|
+
'syntax:hiera',
|
12
13
|
]
|
13
14
|
|
14
15
|
namespace :syntax do
|
@@ -35,6 +36,24 @@ module PuppetSyntax
|
|
35
36
|
errors = c.check(files)
|
36
37
|
fail errors.join("\n") unless errors.empty?
|
37
38
|
end
|
39
|
+
|
40
|
+
desc 'Syntax check Hiera config files'
|
41
|
+
task :hiera => [
|
42
|
+
'syntax:hiera:yaml',
|
43
|
+
]
|
44
|
+
|
45
|
+
namespace :hiera do
|
46
|
+
task :yaml do |t|
|
47
|
+
$stderr.puts "---> #{t.name}"
|
48
|
+
files = FileList["hieradata/**/*.yaml", "hiera*.yaml"]
|
49
|
+
files.reject! { |f| File.directory?(f) }
|
50
|
+
files = files.exclude(*PuppetSyntax.exclude_paths)
|
51
|
+
|
52
|
+
c = PuppetSyntax::Hiera.new
|
53
|
+
errors = c.check(files)
|
54
|
+
fail errors.join("\n") unless errors.empty?
|
55
|
+
end
|
56
|
+
end
|
38
57
|
end
|
39
58
|
end
|
40
59
|
end
|
@@ -0,0 +1 @@
|
|
1
|
+
%YAMLBAD
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe PuppetSyntax::Hiera do
|
4
|
+
let(:subject) { PuppetSyntax::Hiera.new }
|
5
|
+
|
6
|
+
it 'should expect an array of files' do
|
7
|
+
expect { subject.check(nil) }.to raise_error(/Expected an array of files/)
|
8
|
+
end
|
9
|
+
|
10
|
+
it "should return nothing from valid YAML" do
|
11
|
+
files = fixture_hiera('hiera_good.yaml')
|
12
|
+
res = subject.check(files)
|
13
|
+
expect(res).to be == []
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should return an error from invalid YAML" do
|
17
|
+
case RUBY_VERSION
|
18
|
+
when /1.8/
|
19
|
+
files = fixture_hiera('hiera_bad_18.yaml')
|
20
|
+
expected = /syntax error on line 3, col -1: `'/
|
21
|
+
else
|
22
|
+
files = fixture_hiera('hiera_bad.yaml')
|
23
|
+
expected = /scanning a directive at line 1 column 1/
|
24
|
+
end
|
25
|
+
res = subject.check(files)
|
26
|
+
expect(res.size).to be == 1
|
27
|
+
expect(res.first).to match(expected)
|
28
|
+
end
|
29
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,17 +1,21 @@
|
|
1
1
|
require 'rspec'
|
2
2
|
require 'puppet-syntax'
|
3
3
|
|
4
|
+
def fixture_hiera(list)
|
5
|
+
fixture_files(list, 'hiera')
|
6
|
+
end
|
7
|
+
|
4
8
|
def fixture_templates(list)
|
5
|
-
fixture_files(list, 'templates')
|
9
|
+
fixture_files(list, 'test_module/templates')
|
6
10
|
end
|
7
11
|
|
8
12
|
def fixture_manifests(list)
|
9
|
-
fixture_files(list, 'manifests')
|
13
|
+
fixture_files(list, 'test_module/manifests')
|
10
14
|
end
|
11
15
|
|
12
16
|
def fixture_files(list, path)
|
13
17
|
list = [list].flatten
|
14
|
-
list.map { |f| File.expand_path("../fixtures
|
18
|
+
list.map { |f| File.expand_path("../fixtures/#{path}/#{f}", __FILE__) }
|
15
19
|
end
|
16
20
|
|
17
21
|
RSpec.configure do |config|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: puppet-syntax
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.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-09-06 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|
@@ -106,11 +106,15 @@ files:
|
|
106
106
|
- README.md
|
107
107
|
- Rakefile
|
108
108
|
- lib/puppet-syntax.rb
|
109
|
+
- lib/puppet-syntax/hiera.rb
|
109
110
|
- lib/puppet-syntax/manifests.rb
|
110
111
|
- lib/puppet-syntax/tasks/puppet-syntax.rb
|
111
112
|
- lib/puppet-syntax/templates.rb
|
112
113
|
- lib/puppet-syntax/version.rb
|
113
114
|
- puppet-syntax.gemspec
|
115
|
+
- spec/fixtures/hiera/hiera_bad.yaml
|
116
|
+
- spec/fixtures/hiera/hiera_bad_18.yaml
|
117
|
+
- spec/fixtures/hiera/hiera_good.yaml
|
114
118
|
- spec/fixtures/test_module/manifests/fail_error.pp
|
115
119
|
- spec/fixtures/test_module/manifests/fail_warning.pp
|
116
120
|
- spec/fixtures/test_module/manifests/pass.pp
|
@@ -119,6 +123,7 @@ files:
|
|
119
123
|
- spec/fixtures/test_module/templates/fail_warning.erb
|
120
124
|
- spec/fixtures/test_module/templates/pass.erb
|
121
125
|
- spec/fixtures/test_module/templates/pass_unbound_var.erb
|
126
|
+
- spec/puppet-syntax/hiera_spec.rb
|
122
127
|
- spec/puppet-syntax/manifests_spec.rb
|
123
128
|
- spec/puppet-syntax/tasks/puppet-syntax_spec.rb
|
124
129
|
- spec/puppet-syntax/templates_spec.rb
|
@@ -139,7 +144,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
139
144
|
version: '0'
|
140
145
|
segments:
|
141
146
|
- 0
|
142
|
-
hash:
|
147
|
+
hash: 4527904498098256296
|
143
148
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
144
149
|
none: false
|
145
150
|
requirements:
|
@@ -148,7 +153,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
148
153
|
version: '0'
|
149
154
|
segments:
|
150
155
|
- 0
|
151
|
-
hash:
|
156
|
+
hash: 4527904498098256296
|
152
157
|
requirements: []
|
153
158
|
rubyforge_project:
|
154
159
|
rubygems_version: 1.8.23
|
@@ -156,6 +161,9 @@ signing_key:
|
|
156
161
|
specification_version: 3
|
157
162
|
summary: ''
|
158
163
|
test_files:
|
164
|
+
- spec/fixtures/hiera/hiera_bad.yaml
|
165
|
+
- spec/fixtures/hiera/hiera_bad_18.yaml
|
166
|
+
- spec/fixtures/hiera/hiera_good.yaml
|
159
167
|
- spec/fixtures/test_module/manifests/fail_error.pp
|
160
168
|
- spec/fixtures/test_module/manifests/fail_warning.pp
|
161
169
|
- spec/fixtures/test_module/manifests/pass.pp
|
@@ -164,6 +172,7 @@ test_files:
|
|
164
172
|
- spec/fixtures/test_module/templates/fail_warning.erb
|
165
173
|
- spec/fixtures/test_module/templates/pass.erb
|
166
174
|
- spec/fixtures/test_module/templates/pass_unbound_var.erb
|
175
|
+
- spec/puppet-syntax/hiera_spec.rb
|
167
176
|
- spec/puppet-syntax/manifests_spec.rb
|
168
177
|
- spec/puppet-syntax/tasks/puppet-syntax_spec.rb
|
169
178
|
- spec/puppet-syntax/templates_spec.rb
|