puppet-syntax 2.5.0 → 3.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -1
- data/.travis.yml +17 -5
- data/CHANGELOG.md +63 -0
- data/Gemfile +3 -5
- data/README.md +67 -47
- data/lib/puppet-syntax.rb +9 -9
- data/lib/puppet-syntax/hiera.rb +1 -1
- data/lib/puppet-syntax/manifests.rb +4 -7
- data/lib/puppet-syntax/tasks/puppet-syntax.rb +12 -33
- data/lib/puppet-syntax/templates.rb +41 -19
- data/lib/puppet-syntax/version.rb +1 -1
- data/puppet-syntax.gemspec +3 -0
- data/spec/fixtures/test_module/manifests/schedule_notice.pp +5 -0
- data/spec/puppet-syntax/manifests_spec.rb +23 -180
- data/spec/puppet-syntax/tasks/puppet-syntax_spec.rb +1 -1
- data/spec/puppet-syntax/templates_spec.rb +58 -67
- data/spec/puppet-syntax_spec.rb +8 -15
- metadata +20 -5
- data/jenkins.sh +0 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5d56b393f1a0a60742b7c0600dd39568eb232cee2bae2400b169fee499cb12a6
|
4
|
+
data.tar.gz: 3b641f2e4ad9f5ab9fa8f91853bfc557b6573e871caeae2228b17f2446d96270
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e4cf5aff0b7abe2e3dc4f07f6a3fec2704c637c063f076e08d9c4812f8fdb8b68fc4d65277982d12008914dca799cf45e8bf6ec5120827b3485abc569755b6c3
|
7
|
+
data.tar.gz: 63e40dd6206c72b2dfddbc85dd0efff6c4fffcd748277e15cacf1aaa54c79a1d62b67da751842ee190856b01e333c391197e22393372d54851306b67639b12bf
|
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
@@ -1,20 +1,25 @@
|
|
1
1
|
---
|
2
|
+
os: linux
|
3
|
+
dist: bionic
|
2
4
|
language: ruby
|
3
5
|
# Workaround https://github.com/bundler/bundler/issues/3558
|
4
6
|
before_install: gem install bundler
|
5
|
-
install: bundle install --jobs 4 --retry 2 --without development
|
7
|
+
install: bundle install --jobs 4 --retry 2 --without development release
|
6
8
|
script: bundle exec rake
|
7
9
|
rvm:
|
8
10
|
- 2.4.4
|
9
11
|
- 2.5.1
|
12
|
+
- 2.6.5
|
13
|
+
- 2.7
|
10
14
|
env:
|
11
15
|
- PUPPET_VERSION="~> 5.5.10"
|
12
|
-
- PUPPET_VERSION="~> 6.
|
13
|
-
- PUPPET_VERSION="~> 6.2.0"
|
14
|
-
- PUPPET_VERSION="~> 6.5.0"
|
16
|
+
- PUPPET_VERSION="~> 6.5"
|
15
17
|
- PUPPET_VERSION=">= 0"
|
16
18
|
- PUPPET_VERSION="git://github.com/puppetlabs/puppet.git#master"
|
17
|
-
|
19
|
+
jobs:
|
20
|
+
exclude:
|
21
|
+
- rvm: 2.7
|
22
|
+
env: PUPPET_VERSION="~> 5.5.10"
|
18
23
|
allow_failures:
|
19
24
|
- env: PUPPET_VERSION=">= 0"
|
20
25
|
- env: PUPPET_VERSION="git://github.com/puppetlabs/puppet.git#master"
|
@@ -29,3 +34,10 @@ deploy:
|
|
29
34
|
tags: true
|
30
35
|
all_branches: true
|
31
36
|
repo: voxpupuli/puppet-syntax
|
37
|
+
notifications:
|
38
|
+
email: false
|
39
|
+
irc:
|
40
|
+
on_success: always
|
41
|
+
on_failure: always
|
42
|
+
channels:
|
43
|
+
- "chat.freenode.org#voxpupuli-notifications"
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,69 @@
|
|
2
2
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
4
4
|
|
5
|
+
## [v3.1.0](https://github.com/voxpupuli/puppet-syntax/tree/v3.1.0) (2020-06-24)
|
6
|
+
|
7
|
+
[Full Changelog](https://github.com/voxpupuli/puppet-syntax/compare/v3.0.1...v3.1.0)
|
8
|
+
|
9
|
+
**Implemented enhancements:**
|
10
|
+
|
11
|
+
- print actual template errors on $stderr [\#125](https://github.com/voxpupuli/puppet-syntax/pull/125) ([foxxx0](https://github.com/foxxx0))
|
12
|
+
|
13
|
+
**Merged pull requests:**
|
14
|
+
|
15
|
+
- Add ruby2.7 testing, replacing multiple obsolete puppet6 versions [\#124](https://github.com/voxpupuli/puppet-syntax/pull/124) ([DavidS](https://github.com/DavidS))
|
16
|
+
|
17
|
+
## [v3.0.1](https://github.com/voxpupuli/puppet-syntax/tree/v3.0.1) (2020-05-27)
|
18
|
+
|
19
|
+
[Full Changelog](https://github.com/voxpupuli/puppet-syntax/compare/v3.0.0...v3.0.1)
|
20
|
+
|
21
|
+
**Merged pull requests:**
|
22
|
+
|
23
|
+
- Avoid failure on schedule metaparameter warning [\#122](https://github.com/voxpupuli/puppet-syntax/pull/122) ([ffapitalle](https://github.com/ffapitalle))
|
24
|
+
|
25
|
+
## [v3.0.0](https://github.com/voxpupuli/puppet-syntax/tree/v3.0.0) (2020-05-09)
|
26
|
+
|
27
|
+
[Full Changelog](https://github.com/voxpupuli/puppet-syntax/compare/v2.6.1...v3.0.0)
|
28
|
+
|
29
|
+
**Breaking changes:**
|
30
|
+
|
31
|
+
- Drop legacy code to support Puppet \< 5 and Ruby \< 2.4 [\#120](https://github.com/voxpupuli/puppet-syntax/pull/120) ([ekohl](https://github.com/ekohl))
|
32
|
+
|
33
|
+
**Implemented enhancements:**
|
34
|
+
|
35
|
+
- Migrate Changelog to GCG [\#93](https://github.com/voxpupuli/puppet-syntax/issues/93)
|
36
|
+
|
37
|
+
**Merged pull requests:**
|
38
|
+
|
39
|
+
- cleanup README.md / fix markdown linter warnings [\#119](https://github.com/voxpupuli/puppet-syntax/pull/119) ([bastelfreak](https://github.com/bastelfreak))
|
40
|
+
|
41
|
+
## [v2.6.1](https://github.com/voxpupuli/puppet-syntax/tree/v2.6.1) (2020-01-11)
|
42
|
+
|
43
|
+
[Full Changelog](https://github.com/voxpupuli/puppet-syntax/compare/v2.6.0...v2.6.1)
|
44
|
+
|
45
|
+
**Fixed bugs:**
|
46
|
+
|
47
|
+
- Add `puppet` gem as runtime dependency [\#116](https://github.com/voxpupuli/puppet-syntax/pull/116) ([bastelfreak](https://github.com/bastelfreak))
|
48
|
+
|
49
|
+
**Merged pull requests:**
|
50
|
+
|
51
|
+
- traivs: run tests on Ubuntu 18.04 [\#117](https://github.com/voxpupuli/puppet-syntax/pull/117) ([bastelfreak](https://github.com/bastelfreak))
|
52
|
+
- travis: enable irc / disable email notifications [\#114](https://github.com/voxpupuli/puppet-syntax/pull/114) ([bastelfreak](https://github.com/bastelfreak))
|
53
|
+
|
54
|
+
## [v2.6.0](https://github.com/voxpupuli/puppet-syntax/tree/v2.6.0) (2019-10-05)
|
55
|
+
|
56
|
+
[Full Changelog](https://github.com/voxpupuli/puppet-syntax/compare/v2.5.0...v2.6.0)
|
57
|
+
|
58
|
+
**Implemented enhancements:**
|
59
|
+
|
60
|
+
- add support for validating puppet plans \(fixes \#95, fixes \#96\) [\#97](https://github.com/voxpupuli/puppet-syntax/pull/97) ([slauger](https://github.com/slauger))
|
61
|
+
- Allow specifying file paths for manifests and templates too [\#87](https://github.com/voxpupuli/puppet-syntax/pull/87) ([lavagetto](https://github.com/lavagetto))
|
62
|
+
|
63
|
+
**Merged pull requests:**
|
64
|
+
|
65
|
+
- Test on ruby 2.6 [\#111](https://github.com/voxpupuli/puppet-syntax/pull/111) ([alexjfisher](https://github.com/alexjfisher))
|
66
|
+
- Adding KMS tags to allowed EYAML methods [\#105](https://github.com/voxpupuli/puppet-syntax/pull/105) ([craigwatson](https://github.com/craigwatson))
|
67
|
+
|
5
68
|
## [v2.5.0](https://github.com/voxpupuli/puppet-syntax/tree/v2.5.0) (2019-07-07)
|
6
69
|
|
7
70
|
[Full Changelog](https://github.com/voxpupuli/puppet-syntax/compare/v2.4.3...v2.5.0)
|
data/Gemfile
CHANGED
@@ -18,15 +18,13 @@ end
|
|
18
18
|
gemspec
|
19
19
|
|
20
20
|
# Override gemspec for CI matrix builds.
|
21
|
-
|
22
|
-
|
23
|
-
# older version required for ruby 1.9 compat, as it is pulled in as dependency of puppet, this has to be carried by the module
|
24
|
-
gem 'json_pure', '<= 2.0.1'
|
21
|
+
# But only if the environment variable is set
|
22
|
+
gem 'puppet', *location_for(ENV['PUPPET_VERSION'] || '>= 5') if ENV['PUPPET_VERSION']
|
25
23
|
|
26
24
|
group :test do
|
27
25
|
gem 'rspec'
|
28
26
|
end
|
29
27
|
|
30
28
|
group :release do
|
31
|
-
gem 'github_changelog_generator', :require => false, :git => 'https://github.com/github-changelog-generator/github-changelog-generator'
|
29
|
+
gem 'github_changelog_generator', :require => false, :git => 'https://github.com/github-changelog-generator/github-changelog-generator'
|
32
30
|
end
|
data/README.md
CHANGED
@@ -4,36 +4,40 @@
|
|
4
4
|
|
5
5
|
# Puppet::Syntax
|
6
6
|
|
7
|
-
Puppet::Syntax checks for correct syntax in Puppet manifests, templates, and
|
7
|
+
Puppet::Syntax checks for correct syntax in Puppet manifests, templates, and
|
8
|
+
Hiera YAML.
|
8
9
|
|
9
10
|
## Version support
|
10
11
|
|
11
12
|
Puppet::Syntax is supported with:
|
12
13
|
|
13
|
-
- Puppet >=
|
14
|
-
- Ruby >=
|
14
|
+
- Puppet >= 5.0 that provides the `validate` face.
|
15
|
+
- Ruby >= 2.4
|
15
16
|
|
16
17
|
For the specific versions that we test against, see the [TravisCI config](.travis.yml).
|
17
18
|
|
18
|
-
If you're using `puppetlabs_spec_helper/rake_tasks` and getting unexpected non-zero exit codes, upgrade to [puppetlabs_spec_helper][psh] version 0.8.0 or greater. Versions of `puppetlabs_spec_helper` prior to 0.8.0 conflicted with Puppet::Syntax.
|
19
|
-
|
20
|
-
[psh]: https://github.com/puppetlabs/puppetlabs_spec_helper
|
21
|
-
|
22
19
|
## Installation
|
23
20
|
|
24
|
-
To install Puppet::Syntax, either add it to your module's Gemfile or install
|
21
|
+
To install Puppet::Syntax, either add it to your module's Gemfile or install
|
22
|
+
the gem manually.
|
25
23
|
|
26
24
|
* To install with the Gemfile, add:
|
27
25
|
|
28
|
-
|
26
|
+
```ruby
|
27
|
+
gem 'puppet-syntax'
|
28
|
+
```
|
29
29
|
|
30
30
|
And then execute:
|
31
31
|
|
32
|
-
|
32
|
+
```sh
|
33
|
+
bundle install
|
34
|
+
```
|
33
35
|
|
34
36
|
* To install the gem yourself, run:
|
35
37
|
|
36
|
-
|
38
|
+
```sh
|
39
|
+
gem install puppet-syntax
|
40
|
+
```
|
37
41
|
|
38
42
|
## Configuration
|
39
43
|
|
@@ -41,70 +45,85 @@ To configure Puppet::Syntax, add any of the following settings to your `Rakefile
|
|
41
45
|
|
42
46
|
* To exclude certain paths from the syntax checks, set:
|
43
47
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
PuppetSyntax.future_parser = true
|
48
|
+
```ruby
|
49
|
+
PuppetSyntax.exclude_paths = ["vendor/**/*"]
|
50
|
+
```
|
49
51
|
|
50
52
|
* To configure specific paths for the Hiera syntax check, specify `hieradata_paths`. This is useful if you use Hiera data inside your module.
|
51
53
|
|
52
|
-
|
53
|
-
|
54
|
-
|
54
|
+
```ruby
|
55
|
+
PuppetSyntax.hieradata_paths = ["**/data/**/*.yaml", "hieradata/**/*.yaml", "hiera*.yaml"]
|
56
|
+
```
|
55
57
|
|
56
|
-
|
58
|
+
* To configure specific paths for the Puppet syntax checks or for the templates checks, specify `manifests_paths` or `templates_paths` respectively. This is useful if you want to check specific paths only.
|
57
59
|
|
58
|
-
|
60
|
+
```ruby
|
61
|
+
PuppetSyntax.manifests_paths = ["**/environments/future/*.pp"]
|
62
|
+
PuppetSyntax.templates_paths = ["**/modules/**/templates/*.erb"]
|
63
|
+
```
|
59
64
|
|
60
65
|
* To ignore deprecation warnings, disable `fail_on_deprecation_notices`. By default, `puppet-syntax` fails if it encounters Puppet deprecation notices. If you are working with a legacy code base and want to ignore such non-fatal warnings, you might want to override the default behavior.
|
61
66
|
|
62
|
-
|
67
|
+
```ruby
|
68
|
+
PuppetSyntax.fail_on_deprecation_notices = false
|
69
|
+
```
|
63
70
|
|
64
71
|
* To enable a syntax check on Hiera keys, set:
|
65
72
|
|
66
|
-
|
73
|
+
```ruby
|
74
|
+
PuppetSyntax.check_hiera_keys = true
|
75
|
+
```
|
67
76
|
|
68
|
-
|
77
|
+
This reports common mistakes in key names in Hiera files, such as:
|
69
78
|
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
79
|
+
* Leading `::` in keys, such as: `::notsotypical::warning2: true`.
|
80
|
+
* Single colon scope separators, such as: `:picky::warning5: true`.
|
81
|
+
* Invalid camel casing, such as: `noCamelCase::warning3: true`.
|
82
|
+
* Use of hyphens, such as: `no-hyphens::warning4: true`.
|
74
83
|
|
75
84
|
## Usage
|
76
85
|
|
77
86
|
* To enable Puppet::Syntax, include the following in your module's `Rakefile`:
|
78
87
|
|
79
|
-
|
88
|
+
```ruby
|
89
|
+
require 'puppet-syntax/tasks/puppet-syntax'
|
90
|
+
```
|
80
91
|
|
81
|
-
|
92
|
+
For Continuous Integration, use Puppet::Syntax in conjunction with `puppet-lint`
|
93
|
+
and spec tests. Add the following to your module's `Rakefile`:
|
82
94
|
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
95
|
+
```ruby
|
96
|
+
task :test => [
|
97
|
+
:syntax,
|
98
|
+
:lint,
|
99
|
+
:spec,
|
100
|
+
]
|
101
|
+
```
|
88
102
|
|
89
103
|
* To test all manifests and templates, relative to the location of the `Rakefile`, run:
|
90
104
|
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
105
|
+
```
|
106
|
+
$ bundle exec rake syntax
|
107
|
+
---> syntax:manifests
|
108
|
+
---> syntax:templates
|
109
|
+
---> syntax:hiera:yaml
|
110
|
+
```
|
95
111
|
|
96
112
|
* To return a non-zero exit code and an error message on any failures, run:
|
97
113
|
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
114
|
+
```
|
115
|
+
$ bundle exec rake syntax
|
116
|
+
---> syntax:manifests
|
117
|
+
rake aborted!
|
118
|
+
Could not parse for environment production: Syntax error at end of file at demo.pp:2
|
119
|
+
Tasks: TOP => syntax => syntax:manifests
|
120
|
+
(See full trace by running task with --trace)
|
121
|
+
```
|
104
122
|
|
105
123
|
## Checks
|
106
124
|
|
107
|
-
Puppet::Syntax makes the following checks in the directories and subdirectories
|
125
|
+
Puppet::Syntax makes the following checks in the directories and subdirectories
|
126
|
+
of the module, relative to the location of the `Rakefile`.
|
108
127
|
|
109
128
|
### Hiera
|
110
129
|
|
@@ -130,7 +149,8 @@ Checks `.erb` files in the module for syntax errors.
|
|
130
149
|
|
131
150
|
Checks `.epp` files in the module for syntax errors.
|
132
151
|
|
133
|
-
EPP checks are supported in Puppet 4 or greater, or in Puppet 3 with the future
|
152
|
+
EPP checks are supported in Puppet 4 or greater, or in Puppet 3 with the future
|
153
|
+
parser enabled.
|
134
154
|
|
135
155
|
## Contributing
|
136
156
|
|
data/lib/puppet-syntax.rb
CHANGED
@@ -6,28 +6,28 @@ require "puppet/version"
|
|
6
6
|
|
7
7
|
module PuppetSyntax
|
8
8
|
@exclude_paths = []
|
9
|
-
@future_parser = false
|
10
9
|
@hieradata_paths = [
|
11
10
|
"**/data/**/*.*{yaml,yml}",
|
12
11
|
"hieradata/**/*.*{yaml,yml}",
|
13
12
|
"hiera*.*{yaml,yml}"
|
14
13
|
]
|
14
|
+
@manifests_paths = [
|
15
|
+
'**/*.pp'
|
16
|
+
]
|
17
|
+
@templates_paths = [
|
18
|
+
'**/templates/**/*.erb',
|
19
|
+
'**/templates/**/*.epp'
|
20
|
+
]
|
15
21
|
@fail_on_deprecation_notices = true
|
16
|
-
@app_management = Puppet.version.to_i >= 5 ? true : false
|
17
22
|
@check_hiera_keys = false
|
18
23
|
|
19
24
|
class << self
|
20
25
|
attr_accessor :exclude_paths,
|
21
|
-
:future_parser,
|
22
26
|
:hieradata_paths,
|
27
|
+
:manifests_paths,
|
28
|
+
:templates_paths,
|
23
29
|
:fail_on_deprecation_notices,
|
24
30
|
:epp_only,
|
25
31
|
:check_hiera_keys
|
26
|
-
attr_reader :app_management
|
27
|
-
|
28
|
-
def app_management=(app_management)
|
29
|
-
raise 'app_management cannot be disabled on Puppet 5 or higher' if Puppet.version.to_i >= 5 && !app_management
|
30
|
-
@app_management = app_management
|
31
|
-
end
|
32
32
|
end
|
33
33
|
end
|
data/lib/puppet-syntax/hiera.rb
CHANGED
@@ -56,7 +56,7 @@ module PuppetSyntax
|
|
56
56
|
method = 'PKCS7'
|
57
57
|
end
|
58
58
|
|
59
|
-
return "has unknown eyaml method #{method}" unless ['PKCS7','GPG'].include? method
|
59
|
+
return "has unknown eyaml method #{method}" unless ['PKCS7','GPG','GKMS','KMS'].include? method
|
60
60
|
return "has unpadded or truncated base64 data" unless base64.length % 4 == 0
|
61
61
|
|
62
62
|
# Base64#decode64 will silently ignore characters outside the alphabet,
|
@@ -8,9 +8,7 @@ module PuppetSyntax
|
|
8
8
|
|
9
9
|
output = []
|
10
10
|
|
11
|
-
|
12
|
-
Puppet::Test::TestHelper.initialize
|
13
|
-
end
|
11
|
+
Puppet::Test::TestHelper.initialize
|
14
12
|
Puppet::Test::TestHelper.before_all_tests
|
15
13
|
called_before_all_tests = true
|
16
14
|
|
@@ -43,9 +41,9 @@ module PuppetSyntax
|
|
43
41
|
e =~ /^You cannot collect( exported resources)? without storeconfigs being set/
|
44
42
|
}
|
45
43
|
|
46
|
-
# tag
|
44
|
+
# tag and schedule parameters in class raise warnings notice in output that prevent from succeed
|
47
45
|
output.reject! { |e|
|
48
|
-
e =~ /^tag is a metaparam; this value will inherit to all contained resources in the /
|
46
|
+
e =~ /^(tag|schedule) is a metaparam; this value will inherit to all contained resources in the /
|
49
47
|
}
|
50
48
|
|
51
49
|
deprecations = output.select { |e|
|
@@ -62,8 +60,7 @@ module PuppetSyntax
|
|
62
60
|
|
63
61
|
private
|
64
62
|
def validate_manifest(file)
|
65
|
-
Puppet[:
|
66
|
-
Puppet[:app_management] = true if PuppetSyntax.app_management && (Puppet::Util::Package.versioncmp(Puppet.version, '4.3.0') >= 0 && Puppet.version.to_i < 5)
|
63
|
+
Puppet[:tasks] = true if Puppet::Util::Package.versioncmp(Puppet.version, '5.4.0') >= 0 and file.match(/.*plans\/.*\.pp$/)
|
67
64
|
Puppet::Face[:parser, :current].validate(file)
|
68
65
|
end
|
69
66
|
end
|
@@ -13,11 +13,11 @@ module PuppetSyntax
|
|
13
13
|
end
|
14
14
|
|
15
15
|
def filelist_manifests
|
16
|
-
filelist(
|
16
|
+
filelist(PuppetSyntax.manifests_paths)
|
17
17
|
end
|
18
18
|
|
19
19
|
def filelist_templates
|
20
|
-
filelist(
|
20
|
+
filelist(PuppetSyntax.templates_paths)
|
21
21
|
end
|
22
22
|
|
23
23
|
def filelist_hiera_yaml
|
@@ -27,42 +27,14 @@ module PuppetSyntax
|
|
27
27
|
def initialize(*args)
|
28
28
|
desc 'Syntax check Puppet manifests and templates'
|
29
29
|
task :syntax => [
|
30
|
-
'syntax:check_puppetlabs_spec_helper',
|
31
30
|
'syntax:manifests',
|
32
31
|
'syntax:templates',
|
33
32
|
'syntax:hiera',
|
34
33
|
]
|
35
34
|
|
36
35
|
namespace :syntax do
|
37
|
-
task :check_puppetlabs_spec_helper do
|
38
|
-
psh_present = task(:syntax).actions.any? { |a|
|
39
|
-
a.inspect.match(/puppetlabs_spec_helper\/rake_tasks\.rb:\d+/)
|
40
|
-
}
|
41
|
-
|
42
|
-
if psh_present
|
43
|
-
$stderr.puts <<-EOS
|
44
|
-
[WARNING] A conflicting :syntax rake task has been defined by
|
45
|
-
puppetlabs_spec_helper/rake_tasks. You should either disable this or upgrade
|
46
|
-
to puppetlabs_spec_helper >= 0.8.0 which now uses puppet-syntax.
|
47
|
-
EOS
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
36
|
desc 'Syntax check Puppet manifests'
|
52
37
|
task :manifests do |t|
|
53
|
-
if Puppet.version.to_i >= 4 and PuppetSyntax.future_parser
|
54
|
-
$stderr.puts <<-EOS
|
55
|
-
[INFO] Puppet 4 has been detected and `future_parser` has been set to
|
56
|
-
'true'. The `future_parser setting will be ignored.
|
57
|
-
EOS
|
58
|
-
end
|
59
|
-
if Puppet::Util::Package.versioncmp(Puppet.version, '4.3.0') < 0 and PuppetSyntax.app_management
|
60
|
-
$stderr.puts <<-EOS
|
61
|
-
[WARNING] Puppet `app_management` has been detected but the Puppet
|
62
|
-
version is less then 4.3. The `app_management` setting will be ignored.
|
63
|
-
EOS
|
64
|
-
end
|
65
|
-
|
66
38
|
$stderr.puts "---> #{t.name}"
|
67
39
|
|
68
40
|
c = PuppetSyntax::Manifests.new
|
@@ -76,9 +48,16 @@ version is less then 4.3. The `app_management` setting will be ignored.
|
|
76
48
|
$stderr.puts "---> #{t.name}"
|
77
49
|
|
78
50
|
c = PuppetSyntax::Templates.new
|
79
|
-
|
80
|
-
|
81
|
-
|
51
|
+
result = c.check(filelist_templates)
|
52
|
+
unless result[:warnings].empty?
|
53
|
+
$stdout.puts "WARNINGS:"
|
54
|
+
$stdout.puts result[:warnings].join("\n")
|
55
|
+
end
|
56
|
+
unless result[:errors].empty?
|
57
|
+
$stderr.puts "ERRORS:"
|
58
|
+
$stderr.puts result[:errors].join("\n")
|
59
|
+
exit 1
|
60
|
+
end
|
82
61
|
end
|
83
62
|
|
84
63
|
desc 'Syntax check Hiera config files'
|
@@ -9,42 +9,64 @@ module PuppetSyntax
|
|
9
9
|
|
10
10
|
# We now have to redirect STDERR in order to capture warnings.
|
11
11
|
$stderr = warnings = StringIO.new()
|
12
|
-
|
12
|
+
result = { warnings: [], errors: [] }
|
13
13
|
|
14
14
|
filelist.each do |file|
|
15
15
|
if File.extname(file) == '.epp' or PuppetSyntax.epp_only
|
16
|
-
|
16
|
+
tmp = validate_epp(file)
|
17
17
|
elsif File.extname(file) == '.erb'
|
18
|
-
|
18
|
+
tmp = validate_erb(file)
|
19
19
|
end
|
20
|
+
result.merge!(tmp) { |k, a, b| a.concat(b) } unless tmp.nil?
|
20
21
|
end
|
21
22
|
|
22
23
|
$stderr = STDERR
|
23
|
-
|
24
|
-
errors.map! { |e| e.to_s }
|
24
|
+
result[:warnings] << warnings.string unless warnings.string.empty?
|
25
25
|
|
26
|
-
errors
|
26
|
+
result[:errors].map! { |e| e.to_s }
|
27
|
+
result[:warnings].map! { |w| w.to_s }
|
28
|
+
|
29
|
+
result
|
27
30
|
end
|
28
31
|
|
29
32
|
def validate_epp(filename)
|
30
|
-
if Puppet.version.to_f < 3.7
|
31
|
-
raise "Cannot validate EPP without Puppet 4 or future parser (3.7+)"
|
32
|
-
end
|
33
|
-
|
34
33
|
require 'puppet/pops'
|
35
|
-
|
34
|
+
result = { warnings: [], errors: [] }
|
35
|
+
formatter = Puppet::Pops::Validation::DiagnosticFormatterPuppetStyle.new
|
36
|
+
evaluating_parser = Puppet::Pops::Parser::EvaluatingParser::EvaluatingEppParser.new()
|
37
|
+
parser = evaluating_parser.parser()
|
36
38
|
begin
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
39
|
+
parse_result = parser.parse_file(filename)
|
40
|
+
validation_result = evaluating_parser.validate(parse_result.model)
|
41
|
+
|
42
|
+
# print out any warnings
|
43
|
+
validation_result.warnings.each do |warn|
|
44
|
+
message = formatter.format_message(warn)
|
45
|
+
file = warn.file
|
46
|
+
line = warn.source_pos.line
|
47
|
+
column = warn.source_pos.pos
|
48
|
+
result[:warnings] << "#{file}:#{line}:#{column}: #{message}"
|
49
|
+
end
|
50
|
+
|
51
|
+
# collect errors and return them in order to indicate validation failure
|
52
|
+
validation_result.errors.each do |err|
|
53
|
+
message = formatter.format_message(err)
|
54
|
+
file = err.file
|
55
|
+
line = err.source_pos.line
|
56
|
+
column = err.source_pos.pos
|
57
|
+
result[:errors] << "#{file}:#{line}:#{column}: #{message}"
|
58
|
+
end
|
59
|
+
rescue Puppet::ParseError, SyntaxError => exc
|
60
|
+
result[:errors] << exc
|
61
|
+
rescue => exc
|
62
|
+
result[:errors] << exc
|
41
63
|
end
|
42
64
|
|
43
|
-
|
65
|
+
result
|
44
66
|
end
|
45
67
|
|
46
68
|
def validate_erb(filename)
|
47
|
-
|
69
|
+
result = { warnings: [], errors: [] }
|
48
70
|
|
49
71
|
begin
|
50
72
|
erb = ERB.new(File.read(filename), nil, '-')
|
@@ -57,10 +79,10 @@ module PuppetSyntax
|
|
57
79
|
# This is normal because we don't have the variables that would
|
58
80
|
# ordinarily be bound by the parent Puppet manifest.
|
59
81
|
rescue SyntaxError => error
|
60
|
-
errors << error
|
82
|
+
result[:errors] << error
|
61
83
|
end
|
62
84
|
|
63
|
-
|
85
|
+
result
|
64
86
|
end
|
65
87
|
end
|
66
88
|
end
|
data/puppet-syntax.gemspec
CHANGED
@@ -18,7 +18,10 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
21
|
+
spec.required_ruby_version = ">= 2.4"
|
22
|
+
|
21
23
|
spec.add_dependency "rake"
|
24
|
+
spec.add_dependency "puppet", ">= 5"
|
22
25
|
|
23
26
|
spec.add_development_dependency "pry"
|
24
27
|
spec.add_development_dependency "rb-readline"
|
@@ -24,19 +24,21 @@ describe PuppetSyntax::Manifests do
|
|
24
24
|
expect(has_errors).to eq(false)
|
25
25
|
end
|
26
26
|
|
27
|
+
it 'should return nothing from a valid file with a class using schedule parameter' do
|
28
|
+
files = fixture_manifests('schedule_notice.pp')
|
29
|
+
output, has_errors = subject.check(files)
|
30
|
+
|
31
|
+
expect(output).to eq([])
|
32
|
+
expect(has_errors).to eq(false)
|
33
|
+
end
|
34
|
+
|
27
35
|
it 'should return an error from an invalid file' do
|
28
36
|
files = fixture_manifests('fail_error.pp')
|
29
37
|
output, has_errors = subject.check(files)
|
30
38
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
expect(has_errors).to eq(true)
|
35
|
-
else
|
36
|
-
expect(output.size).to eq(1)
|
37
|
-
expect(output[0]).to match(/Syntax error at .*:3$/)
|
38
|
-
expect(has_errors).to eq(true)
|
39
|
-
end
|
39
|
+
expect(output.size).to eq(3)
|
40
|
+
expect(output[2]).to match(/2 errors. Giving up/)
|
41
|
+
expect(has_errors).to eq(true)
|
40
42
|
end
|
41
43
|
|
42
44
|
it 'should return a warning from an invalid file' do
|
@@ -72,181 +74,22 @@ describe PuppetSyntax::Manifests do
|
|
72
74
|
output, has_errors = subject.check(files)
|
73
75
|
|
74
76
|
expect(has_errors).to eq(true)
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
expect(output[4]).to match(/Unrecogni(s|z)ed escape sequence '\\\]'/)
|
82
|
-
else
|
83
|
-
expect(output.size).to eq(3)
|
84
|
-
expect(output[0]).to match(/Syntax error at '\}' .*:3$/)
|
85
|
-
expect(output[1]).to match(/Unrecogni(s|z)ed escape sequence '\\\['/)
|
86
|
-
expect(output[2]).to match(/Unrecogni(s|z)ed escape sequence '\\\]'/)
|
87
|
-
end
|
77
|
+
expect(output.size).to eq(5)
|
78
|
+
expect(output[0]).to match(/This Name has no effect. A Host Class Definition can not end with a value-producing expression without other effect \(file: \S*\/fail_error.pp, line: 2, column: 32\)$/)
|
79
|
+
expect(output[1]).to match(/This Name has no effect. A value was produced and then forgotten \(one or more preceding expressions may have the wrong form\) \(file: \S*\/fail_error.pp, line: 2, column: 3\)$/)
|
80
|
+
expect(output[2]).to match('2 errors. Giving up')
|
81
|
+
expect(output[3]).to match(/Unrecogni(s|z)ed escape sequence '\\\['/)
|
82
|
+
expect(output[4]).to match(/Unrecogni(s|z)ed escape sequence '\\\]'/)
|
88
83
|
end
|
89
84
|
|
90
85
|
describe 'deprecation notices' do
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
it 'should instead be failures' do
|
95
|
-
files = fixture_manifests('deprecation_notice.pp')
|
96
|
-
output, has_errors = subject.check(files)
|
97
|
-
|
98
|
-
expect(has_errors).to eq(true)
|
99
|
-
expect(output.size).to eq(1)
|
100
|
-
expect(output[0]).to match (/Node inheritance is not supported in Puppet >= 4.0.0/)
|
101
|
-
end
|
102
|
-
end
|
103
|
-
when 3.7, 3.8
|
104
|
-
context 'on puppet 3.7 and 3.8' do
|
105
|
-
it 'should return deprecation notices as warnings' do
|
106
|
-
files = fixture_manifests('deprecation_notice.pp')
|
107
|
-
output, has_errors = subject.check(files)
|
108
|
-
|
109
|
-
expect(has_errors).to eq(false)
|
110
|
-
expect(output.size).to eq(2)
|
111
|
-
expect(output[0]).to match(/The use of 'import' is deprecated/)
|
112
|
-
expect(output[1]).to match(/Deprecation notice:/)
|
113
|
-
end
|
114
|
-
end
|
115
|
-
when 3.5, 3.6
|
116
|
-
context 'on puppet 3.5 and 3.6' do
|
117
|
-
it 'should return deprecation notices as warnings' do
|
118
|
-
files = fixture_manifests('deprecation_notice.pp')
|
119
|
-
output, has_errors = subject.check(files)
|
120
|
-
|
121
|
-
expect(has_errors).to eq(false)
|
122
|
-
expect(output.size).to eq(1)
|
123
|
-
expect(output[0]).to match(/The use of 'import' is deprecated/)
|
124
|
-
end
|
125
|
-
end
|
126
|
-
when 3.0..3.4
|
127
|
-
context 'on puppet 3.0 to 3.4' do
|
128
|
-
it 'should not print deprecation notices' do
|
129
|
-
files = fixture_manifests('deprecation_notice.pp')
|
130
|
-
output, has_errors = subject.check(files)
|
131
|
-
|
132
|
-
expect(output).to eq([])
|
133
|
-
expect(has_errors).to eq(false)
|
134
|
-
end
|
135
|
-
end
|
136
|
-
end
|
137
|
-
end
|
138
|
-
|
139
|
-
describe 'app_management' do
|
140
|
-
after do
|
141
|
-
PuppetSyntax.app_management = false if Puppet.version.to_i < 5
|
142
|
-
end
|
86
|
+
it 'should instead be failures' do
|
87
|
+
files = fixture_manifests('deprecation_notice.pp')
|
88
|
+
output, has_errors = subject.check(files)
|
143
89
|
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
files = fixture_manifests(['test_app.pp'])
|
148
|
-
output,has_errors = subject.check(files)
|
149
|
-
|
150
|
-
expect(has_errors).to eq(true)
|
151
|
-
expect(output).to include(/error/)
|
152
|
-
end
|
153
|
-
end
|
154
|
-
context 'app_management = true' do
|
155
|
-
before(:each) {
|
156
|
-
PuppetSyntax.app_management = true
|
157
|
-
}
|
158
|
-
if Puppet::Util::Package.versioncmp(Puppet.version, '4.3.0') >= 0
|
159
|
-
it 'should successfully parse an application manifest on Puppet >= 4.3.0' do
|
160
|
-
expect(PuppetSyntax.app_management).to eq(true)
|
161
|
-
|
162
|
-
files = fixture_manifests(['test_app.pp'])
|
163
|
-
output,has_errors = subject.check(files)
|
164
|
-
|
165
|
-
expect(output.size).to eq(0)
|
166
|
-
expect(has_errors).to eq(false)
|
167
|
-
end
|
168
|
-
else
|
169
|
-
it 'should fail to parse an application manifest on Puppet < 4.3.0' do
|
170
|
-
expect(PuppetSyntax.app_management).to eq(true)
|
171
|
-
|
172
|
-
files = fixture_manifests(['test_app.pp'])
|
173
|
-
output,has_errors = subject.check(files)
|
174
|
-
|
175
|
-
expect(output).to include(/error/)
|
176
|
-
expect(has_errors).to eq(true)
|
177
|
-
end
|
178
|
-
end
|
179
|
-
end
|
180
|
-
end
|
181
|
-
|
182
|
-
|
183
|
-
describe 'future_parser' do
|
184
|
-
context 'future_parser = false (default)' do
|
185
|
-
if Puppet::Util::Package.versioncmp(Puppet.version, '4.0') < 0
|
186
|
-
it 'should fail without setting future option to true on future manifest on Puppet < 4.0.0' do
|
187
|
-
expect(PuppetSyntax.future_parser).to eq(false)
|
188
|
-
|
189
|
-
files = fixture_manifests(['future_syntax.pp'])
|
190
|
-
output, has_errors = subject.check(files)
|
191
|
-
|
192
|
-
expect(output.size).to eq(1)
|
193
|
-
expect(output[0]).to match(/Syntax error at '='; expected '\}' .*:2$/)
|
194
|
-
expect(has_errors).to eq(true)
|
195
|
-
end
|
196
|
-
else
|
197
|
-
it 'should succeed on Puppet >= 4.0.0' do
|
198
|
-
expect(PuppetSyntax.future_parser).to eq(false)
|
199
|
-
|
200
|
-
files = fixture_manifests(['future_syntax.pp'])
|
201
|
-
output, has_errors = subject.check(files)
|
202
|
-
|
203
|
-
expect(output.size).to eq(0)
|
204
|
-
expect(has_errors).to eq(false)
|
205
|
-
end
|
206
|
-
end
|
207
|
-
end
|
208
|
-
|
209
|
-
context 'future_parser = true' do
|
210
|
-
before(:each) {
|
211
|
-
PuppetSyntax.future_parser = true
|
212
|
-
}
|
213
|
-
|
214
|
-
if Puppet::Util::Package.versioncmp(Puppet.version, '3.2') >= 0 and Puppet.version.to_i < 4
|
215
|
-
context 'Puppet >= 3.2 < 4' do
|
216
|
-
it 'should pass with future option set to true on future manifest' do
|
217
|
-
files = fixture_manifests(['future_syntax.pp'])
|
218
|
-
output, has_errors = subject.check(files)
|
219
|
-
|
220
|
-
expect(output).to eq([])
|
221
|
-
expect(has_errors).to eq(false)
|
222
|
-
end
|
223
|
-
end
|
224
|
-
context 'Puppet >= 3.7 < 4' do
|
225
|
-
# Certain elements of the future parser weren't added until 3.7
|
226
|
-
if Puppet::Util::Package.versioncmp(Puppet.version, '3.7') >= 0
|
227
|
-
it 'should fail on what were deprecation notices in the non-future parser' do
|
228
|
-
files = fixture_manifests('deprecation_notice.pp')
|
229
|
-
output, has_errors = subject.check(files)
|
230
|
-
|
231
|
-
expect(output.size).to eq(1)
|
232
|
-
expect(output[0]).to match(/Node inheritance is not supported/)
|
233
|
-
expect(has_errors).to eq(true)
|
234
|
-
end
|
235
|
-
end
|
236
|
-
end
|
237
|
-
elsif Puppet::Util::Package.versioncmp(Puppet.version, '3.2') < 0
|
238
|
-
context 'Puppet < 3.2' do
|
239
|
-
it 'should return an error that the parser option is not supported' do
|
240
|
-
files = fixture_manifests(['future_syntax.pp'])
|
241
|
-
output, has_errors = subject.check(files)
|
242
|
-
|
243
|
-
expect(output.size).to eq(1)
|
244
|
-
expect(output[0]).to match("Attempt to assign a value to unknown configuration parameter :parser")
|
245
|
-
expect(has_errors).to eq(true)
|
246
|
-
end
|
247
|
-
end
|
248
|
-
end
|
90
|
+
expect(has_errors).to eq(true)
|
91
|
+
expect(output.size).to eq(1)
|
92
|
+
expect(output[0]).to match (/Node inheritance is not supported in Puppet >= 4.0.0/)
|
249
93
|
end
|
250
94
|
end
|
251
|
-
|
252
95
|
end
|
@@ -18,7 +18,7 @@ describe 'PuppetSyntax rake tasks' do
|
|
18
18
|
it 'should generate FileList of manifests relative to Rakefile' do
|
19
19
|
list = PuppetSyntax::RakeTask.new.filelist_manifests
|
20
20
|
expect(list).to include(known_pp)
|
21
|
-
expect(list.count).to eq
|
21
|
+
expect(list.count).to eq 9
|
22
22
|
end
|
23
23
|
|
24
24
|
it 'should generate FileList of templates relative to Rakefile' do
|
@@ -2,6 +2,13 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe PuppetSyntax::Templates do
|
4
4
|
let(:subject) { PuppetSyntax::Templates.new }
|
5
|
+
let(:conditional_warning_regex) do
|
6
|
+
if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('2.6.0')
|
7
|
+
%r{2: warning: found `= literal' in conditional}
|
8
|
+
else
|
9
|
+
%r{2: warning: found = in conditional}
|
10
|
+
end
|
11
|
+
end
|
5
12
|
|
6
13
|
it 'should expect an array of files' do
|
7
14
|
expect { subject.check(nil) }.to raise_error(/Expected an array of files/)
|
@@ -11,127 +18,111 @@ describe PuppetSyntax::Templates do
|
|
11
18
|
files = fixture_templates('pass.erb')
|
12
19
|
res = subject.check(files)
|
13
20
|
|
14
|
-
expect(res).to match([])
|
21
|
+
expect(res[:warnings]).to match([])
|
22
|
+
expect(res[:errors]).to match([])
|
15
23
|
end
|
16
24
|
|
17
25
|
it 'should ignore NameErrors from unbound variables' do
|
18
26
|
files = fixture_templates('pass_unbound_var.erb')
|
19
27
|
res = subject.check(files)
|
20
28
|
|
21
|
-
expect(res).to match([])
|
29
|
+
expect(res[:warnings]).to match([])
|
30
|
+
expect(res[:errors]).to match([])
|
22
31
|
end
|
23
32
|
|
24
33
|
it 'should catch SyntaxError' do
|
25
34
|
files = fixture_templates('fail_error.erb')
|
26
35
|
res = subject.check(files)
|
27
36
|
|
28
|
-
expect(res.size).to eq(1)
|
29
|
-
expect(res[0]).to match(/2: syntax error, unexpected/)
|
37
|
+
expect(res[:errors].size).to eq(1)
|
38
|
+
expect(res[:errors][0]).to match(/2: syntax error, unexpected/)
|
30
39
|
end
|
31
40
|
|
32
41
|
it 'should catch Ruby warnings' do
|
33
42
|
files = fixture_templates('fail_warning.erb')
|
34
43
|
res = subject.check(files)
|
35
44
|
|
36
|
-
expect(res.size).to eq(1)
|
37
|
-
expect(res[0]).to match(
|
45
|
+
expect(res[:warnings].size).to eq(1)
|
46
|
+
expect(res[:warnings][0]).to match(conditional_warning_regex)
|
38
47
|
end
|
39
48
|
|
40
49
|
it 'should read more than one valid file' do
|
41
50
|
files = fixture_templates(['pass.erb', 'pass_unbound_var.erb'])
|
42
51
|
res = subject.check(files)
|
43
52
|
|
44
|
-
expect(res).to match([])
|
53
|
+
expect(res[:warnings]).to match([])
|
54
|
+
expect(res[:errors]).to match([])
|
45
55
|
end
|
46
56
|
|
47
57
|
it 'should continue after finding an error in the first file' do
|
48
58
|
files = fixture_templates(['fail_error.erb', 'fail_warning.erb'])
|
49
59
|
res = subject.check(files)
|
50
60
|
|
51
|
-
expect(res.size).to eq(
|
52
|
-
expect(res[
|
53
|
-
expect(res[
|
61
|
+
expect(res[:warnings].size).to eq(1)
|
62
|
+
expect(res[:errors].size).to eq(1)
|
63
|
+
expect(res[:errors][0]).to match(/2: syntax error, unexpected/)
|
64
|
+
expect(res[:warnings][0]).to match(conditional_warning_regex)
|
54
65
|
end
|
55
66
|
|
56
67
|
it 'should ignore a TypeError' do
|
57
68
|
files = fixture_templates('typeerror_shouldwin.erb')
|
58
69
|
res = subject.check(files)
|
59
70
|
|
60
|
-
expect(res).to match([])
|
71
|
+
expect(res[:warnings]).to match([])
|
72
|
+
expect(res[:errors]).to match([])
|
61
73
|
end
|
62
74
|
|
63
75
|
it 'should ignore files without .erb extension' do
|
64
76
|
files = fixture_templates('ignore.tpl')
|
65
77
|
res = subject.check(files)
|
66
78
|
|
67
|
-
expect(res).to match([])
|
68
|
-
|
69
|
-
|
70
|
-
if Puppet.version.to_f < 3.7
|
71
|
-
context 'on Puppet < 3.7' do
|
72
|
-
it 'should throw an exception when parsing EPP files' do
|
73
|
-
file = fixture_templates('pass.epp')
|
74
|
-
expect{ subject.check(file) }.to raise_error(/Cannot validate EPP without Puppet 4/)
|
75
|
-
end
|
76
|
-
|
77
|
-
context "when the 'epp_only' options is set" do
|
78
|
-
before(:each) {
|
79
|
-
PuppetSyntax.epp_only = true
|
80
|
-
}
|
81
|
-
|
82
|
-
it 'should throw an exception for any file' do
|
83
|
-
file = fixture_templates('pass.erb')
|
84
|
-
expect{ subject.check(file) }.to raise_error(/Cannot validate EPP without Puppet 4/)
|
85
|
-
end
|
86
|
-
end
|
87
|
-
end
|
79
|
+
expect(res[:warnings]).to match([])
|
80
|
+
expect(res[:errors]).to match([])
|
88
81
|
end
|
89
82
|
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
files = fixture_templates('pass.epp')
|
94
|
-
res = subject.check(files)
|
83
|
+
it 'should return nothing from a valid file' do
|
84
|
+
files = fixture_templates('pass.epp')
|
85
|
+
res = subject.check(files)
|
95
86
|
|
96
|
-
|
97
|
-
|
87
|
+
expect(res[:warnings]).to match([])
|
88
|
+
expect(res[:errors]).to match([])
|
89
|
+
end
|
98
90
|
|
99
|
-
|
100
|
-
|
101
|
-
|
91
|
+
it 'should catch SyntaxError' do
|
92
|
+
files = fixture_templates('fail_error.epp')
|
93
|
+
res = subject.check(files)
|
102
94
|
|
103
|
-
|
104
|
-
|
105
|
-
|
95
|
+
expect(res[:errors].size).to eq(1)
|
96
|
+
expect(res[:errors][0]).to match(/This Type-Name has no effect/)
|
97
|
+
end
|
106
98
|
|
107
|
-
|
108
|
-
|
109
|
-
|
99
|
+
it 'should read more than one valid file' do
|
100
|
+
files = fixture_templates(['pass.epp', 'pass_also.epp'])
|
101
|
+
res = subject.check(files)
|
110
102
|
|
111
|
-
|
112
|
-
|
103
|
+
expect(res[:warnings]).to match([])
|
104
|
+
expect(res[:errors]).to match([])
|
105
|
+
end
|
113
106
|
|
114
|
-
|
115
|
-
|
116
|
-
|
107
|
+
it 'should continue after finding an error in the first file' do
|
108
|
+
files = fixture_templates(['fail_error.epp', 'fail_error_also.epp'])
|
109
|
+
res = subject.check(files)
|
117
110
|
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
111
|
+
expect(res[:errors].size).to eq(2)
|
112
|
+
expect(res[:errors][0]).to match(/This Type-Name has no effect/)
|
113
|
+
expect(res[:errors][1]).to match(/Syntax error at '}' \(file: \S*\/fail_error_also.epp, line: 2, column: 4\)/)
|
114
|
+
end
|
122
115
|
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
116
|
+
context "when the 'epp_only' options is set" do
|
117
|
+
before(:each) {
|
118
|
+
PuppetSyntax.epp_only = true
|
119
|
+
}
|
127
120
|
|
128
|
-
|
129
|
-
|
130
|
-
|
121
|
+
it 'should process an ERB as EPP and find an error' do
|
122
|
+
files = fixture_templates('pass.erb')
|
123
|
+
res = subject.check(files)
|
131
124
|
|
132
|
-
|
133
|
-
end
|
134
|
-
end
|
125
|
+
expect(res[:errors].size).to eq(1)
|
135
126
|
end
|
136
127
|
end
|
137
128
|
end
|
data/spec/puppet-syntax_spec.rb
CHANGED
@@ -3,7 +3,6 @@ require 'spec_helper'
|
|
3
3
|
describe PuppetSyntax do
|
4
4
|
after do
|
5
5
|
PuppetSyntax.exclude_paths = []
|
6
|
-
PuppetSyntax.app_management = false if Puppet.version.to_i < 5
|
7
6
|
end
|
8
7
|
|
9
8
|
it 'should default exclude_paths to include the pkg directory' do
|
@@ -20,20 +19,6 @@ describe PuppetSyntax do
|
|
20
19
|
expect(PuppetSyntax.exclude_paths).to eq(["foo"])
|
21
20
|
end
|
22
21
|
|
23
|
-
it 'should support future parser setting' do
|
24
|
-
PuppetSyntax.future_parser = true
|
25
|
-
expect(PuppetSyntax.future_parser).to eq(true)
|
26
|
-
end
|
27
|
-
|
28
|
-
it 'should support app_management setting setting' do
|
29
|
-
PuppetSyntax.app_management = true
|
30
|
-
expect(PuppetSyntax.app_management).to eq(true)
|
31
|
-
end
|
32
|
-
|
33
|
-
it 'should raise error when app_management is disabled on 5.x', :if => (Puppet.version.to_i >= 5) do
|
34
|
-
expect { PuppetSyntax.app_management = false }.to raise_error(/app_management cannot be disabled on Puppet 5 or higher/)
|
35
|
-
end
|
36
|
-
|
37
22
|
it 'should support a fail_on_deprecation_notices setting' do
|
38
23
|
PuppetSyntax.fail_on_deprecation_notices = false
|
39
24
|
expect(PuppetSyntax.fail_on_deprecation_notices).to eq(false)
|
@@ -44,4 +29,12 @@ describe PuppetSyntax do
|
|
44
29
|
expect(PuppetSyntax.epp_only).to eq(true)
|
45
30
|
end
|
46
31
|
|
32
|
+
it 'should support setting paths for manifests, templates and hiera' do
|
33
|
+
PuppetSyntax.hieradata_paths = []
|
34
|
+
expect(PuppetSyntax.hieradata_paths).to eq([])
|
35
|
+
PuppetSyntax.manifests_paths = ["**/environments/production/**/*.pp"]
|
36
|
+
expect(PuppetSyntax.manifests_paths).to eq(["**/environments/production/**/*.pp"])
|
37
|
+
PuppetSyntax.templates_paths = []
|
38
|
+
expect(PuppetSyntax.templates_paths).to eq([])
|
39
|
+
end
|
47
40
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: puppet-syntax
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 3.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Vox Pupuli
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-06-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -24,6 +24,20 @@ dependencies:
|
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: puppet
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '5'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '5'
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: pry
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -81,7 +95,6 @@ files:
|
|
81
95
|
- LICENSE.txt
|
82
96
|
- README.md
|
83
97
|
- Rakefile
|
84
|
-
- jenkins.sh
|
85
98
|
- lib/puppet-syntax.rb
|
86
99
|
- lib/puppet-syntax/hiera.rb
|
87
100
|
- lib/puppet-syntax/manifests.rb
|
@@ -105,6 +118,7 @@ files:
|
|
105
118
|
- spec/fixtures/test_module/manifests/future_syntax.pp
|
106
119
|
- spec/fixtures/test_module/manifests/pass.pp
|
107
120
|
- spec/fixtures/test_module/manifests/pass_storeconfigs.pp
|
121
|
+
- spec/fixtures/test_module/manifests/schedule_notice.pp
|
108
122
|
- spec/fixtures/test_module/manifests/tag_notice.pp
|
109
123
|
- spec/fixtures/test_module/manifests/test_app.pp
|
110
124
|
- spec/fixtures/test_module/templates/fail_error.epp
|
@@ -135,14 +149,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
135
149
|
requirements:
|
136
150
|
- - ">="
|
137
151
|
- !ruby/object:Gem::Version
|
138
|
-
version: '
|
152
|
+
version: '2.4'
|
139
153
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
140
154
|
requirements:
|
141
155
|
- - ">="
|
142
156
|
- !ruby/object:Gem::Version
|
143
157
|
version: '0'
|
144
158
|
requirements: []
|
145
|
-
rubygems_version: 3.0.
|
159
|
+
rubygems_version: 3.0.6
|
146
160
|
signing_key:
|
147
161
|
specification_version: 4
|
148
162
|
summary: Syntax checks for Puppet manifests, templates, and Hiera YAML
|
@@ -163,6 +177,7 @@ test_files:
|
|
163
177
|
- spec/fixtures/test_module/manifests/future_syntax.pp
|
164
178
|
- spec/fixtures/test_module/manifests/pass.pp
|
165
179
|
- spec/fixtures/test_module/manifests/pass_storeconfigs.pp
|
180
|
+
- spec/fixtures/test_module/manifests/schedule_notice.pp
|
166
181
|
- spec/fixtures/test_module/manifests/tag_notice.pp
|
167
182
|
- spec/fixtures/test_module/manifests/test_app.pp
|
168
183
|
- spec/fixtures/test_module/templates/fail_error.epp
|
data/jenkins.sh
DELETED