puppet-check 1.5.0 → 2.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/CHANGELOG.md +39 -4
- data/README.md +35 -50
- data/lib/puppet-check.rb +63 -47
- data/lib/puppet-check/cli.rb +21 -17
- data/lib/puppet-check/data_parser.rb +55 -28
- data/lib/puppet-check/output_results.rb +5 -4
- data/lib/puppet-check/puppet_parser.rb +31 -16
- data/lib/puppet-check/rspec_puppet_support.rb +34 -11
- data/lib/puppet-check/ruby_parser.rb +6 -8
- data/lib/puppet-check/tasks.rb +17 -13
- data/spec/fixtures/manifests/eof_syntax.pp +4 -0
- data/spec/fixtures/task_metadata/task_bad.json +10 -0
- data/spec/fixtures/task_metadata/task_good.json +16 -0
- data/spec/puppet-check/cli_spec.rb +9 -43
- data/spec/puppet-check/data_parser_spec.rb +27 -11
- data/spec/puppet-check/output_results_spec.rb +9 -18
- data/spec/puppet-check/puppet_parser_spec.rb +22 -18
- data/spec/puppet-check/regression_check_spec.rb +1 -3
- data/spec/puppet-check/rspec_puppet_support_spec.rb +5 -1
- data/spec/puppet-check/ruby_parser_spec.rb +8 -4
- data/spec/puppet-check/tasks_spec.rb +13 -3
- data/spec/puppet-check_spec.rb +11 -12
- data/spec/system/system_spec.rb +8 -14
- metadata +51 -32
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: aa44aac16d4ff64057807c913172a7a064352f4fcfee70868b0d0c06dc0dffd6
|
4
|
+
data.tar.gz: 4a1fbf02e9638af8605b26377ac335594ac8d640308f38fdbc9dbae1ada78a99
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 58186b18c0aa0fe1600c158be2d20be6ccaf75389e18baae51041a47b8c314dd550f0817a329aca29e2ed1a6c96249f3220815b8f26387a2795306ce41715d9e
|
7
|
+
data.tar.gz: 616cdc41630d9b06e93cbc27015980baa3777063837ce91e1a88955a0fdbfb41cbcc79473133d4bbe1439961345cb8f745acda8f40b15c1d0bfb58b863a80be0
|
data/CHANGELOG.md
CHANGED
@@ -1,12 +1,47 @@
|
|
1
|
+
### 2.0.1
|
2
|
+
- Check for existence of executables for dependency module retrieval.
|
3
|
+
- Beta support for Puppet 7, Rubocop 1, and Reek 6.
|
4
|
+
|
5
|
+
### 2.0.0
|
6
|
+
- Bump minimum version of Puppet to 4.0.0 and remove < 4 support code.
|
7
|
+
- Official support for Puppet 6.
|
8
|
+
- Minimum Ruby version bumped to 2.2.0.
|
9
|
+
- Bumped Rubocop and Reek minimum versions and fully migrated SPDX to Rubygems.
|
10
|
+
- Add rubocop-performance extension to Rubocop.
|
11
|
+
- Update manifest validation for breaking change in 6.5 API.
|
12
|
+
- Fix check on specified dependencies in metadata.
|
13
|
+
- Enable parallel module dependency retrieval.
|
14
|
+
|
15
|
+
### 1.6.1
|
16
|
+
- Removed check for hieradata nil/undef value for Hiera >= 5.
|
17
|
+
- Add rudimentary checks for task metadata.
|
18
|
+
- Preliminary support for Puppet 6.
|
19
|
+
- RSpec Puppet fixed its default `spec_helper`. Revert to loading it instead of generating a working one.
|
20
|
+
|
21
|
+
### 1.6.0
|
22
|
+
- Minimum Ruby version increased to 2.1.
|
23
|
+
- Minimum Puppet version increased to 3.7.
|
24
|
+
- Minimum Puppet-Lint and Rubocop increased to 2.0 and 0.51.0.
|
25
|
+
- Correctly capturing new Puppet >= 5.4 parser validator output format.
|
26
|
+
- Refixing style checker error for empty hieradata.
|
27
|
+
|
28
|
+
### 1.5.1
|
29
|
+
- Slight cleanup and optimization.
|
30
|
+
- Fixed check for no spec directories during RSpec Puppet helper.
|
31
|
+
- Fixed check for semantic versioning in `metadata.json` for numbering > 9.
|
32
|
+
- Accounted for Puppet syntax validation output bugfix in 5.3.
|
33
|
+
- Fix bad symlink for module fixture during RSpec Puppet.
|
34
|
+
- Updating Beaker Rake task usage.
|
35
|
+
|
1
36
|
### 1.5.0
|
2
|
-
- Maximum Puppet version increased from
|
37
|
+
- Maximum Puppet version increased from 4 to 5.
|
3
38
|
- Added capability to check EYAML (experimental).
|
4
39
|
- Test Kitchen frontend interface.
|
5
40
|
- Updated Puppet error output for Puppet 5 differences.
|
6
41
|
- Slight optimization for smaller test sets.
|
7
|
-
- Suppress constant redefinition warnings from Octocatalog-
|
8
|
-
- Changed FileName cop to reflect change in RuboCop >= 0.
|
9
|
-
- Entire module is now symlinked into `spec/fixtures/modules` during
|
42
|
+
- Suppress constant redefinition warnings from Octocatalog-Diff's Puppet code reuse.
|
43
|
+
- Changed FileName cop to reflect change in RuboCop >= 0.50.
|
44
|
+
- Entire module is now symlinked into `spec/fixtures/modules` during RSpec Puppet testing (formerly specific components).
|
10
45
|
|
11
46
|
### 1.4.1
|
12
47
|
- Support for using SVN to download external module dependencies for RSpec Puppet.
|
data/README.md
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
# Puppet Check
|
2
2
|
[![Build Status](https://travis-ci.org/mschuchard/puppet-check.svg?branch=master)](https://travis-ci.org/mschuchard/puppet-check)
|
3
|
+
[![CircleCI](https://circleci.com/gh/mschuchard/puppet-check.svg?style=svg)](https://circleci.com/gh/mschuchard/puppet-check)
|
3
4
|
|
4
5
|
- [Description](#description)
|
5
6
|
- [Usage](#usage)
|
@@ -17,8 +18,6 @@ Puppet Check is a gem that provides a comprehensive, streamlined, and efficient
|
|
17
18
|
|
18
19
|
**IMPORTANT**: The current support for encrypted yaml validation is experimental. The code is blocked in the current release (the files will continue to be treated as unrecognized) and will be unblocked when the feature is finished in a future version.
|
19
20
|
|
20
|
-
Also, when most Ruby gems (both third party and standard) dropped support for 1.9.3, it became difficult for users to use Puppet Check with 1.9.3, and support for it was eventually dropped. This is now occurring again for 2.0.0 as few gems are supporting it anymore, and support for 2.0.0 will be discontinued in Puppet Check 1.6.0.
|
21
|
-
|
22
21
|
### Former Method for Code and Data Checks
|
23
22
|
![Old](https://raw.githubusercontent.com/mschuchard/puppet-check/master/images/puppetcheck_old.png)
|
24
23
|
|
@@ -123,33 +122,16 @@ The following files have unrecognized formats and therefore were not processed:
|
|
123
122
|
-- foobarbaz
|
124
123
|
```
|
125
124
|
|
126
|
-
###
|
127
|
-
|
128
|
-
- Puppetlabs Spec Helper performs fewer types of checks.
|
129
|
-
- Puppetlabs Spec Helper has extra layers of gems in between it and the gems executing the checks.
|
130
|
-
- Puppetlabs Spec Helper does not allow interfacing through it to the gems executing the checks.
|
131
|
-
- Puppetlabs Spec Helper has no CLI.
|
132
|
-
- Puppetlabs Spec Helper intrinsically only executes spec tests against one module at a time.
|
133
|
-
- Puppetlabs Spec Helper requires an additional config file for RSpec Puppet support.
|
134
|
-
- Puppetlabs Spec Helper does not update external module dependencies in a stateful/persistent workspace and fails gracefully instead.
|
135
|
-
- Puppetlabs Spec Helper requires extra configuration items to setup self-module RSpec testing.
|
136
|
-
- Puppetlabs Spec Helper does not frontend to Octocatalog Diff or Test-Kitchen.
|
137
|
-
|
138
|
-
It is worth nothing that there is no current development objective for Puppet Check to achieve the same advanced level of robustness for spec testing that Puppetlabs Spec Helper enables. If you are performing standard spec testing on your Puppet code and data, then Puppet Check's spec testing is a fantastic lighter and faster alternative to Puppetlabs Spec Helper. If you require advanced and intricate capabilities in your spec testing (e.g. direct interfacing to the `Puppet::Parser::Scope` API), then you will likely prefer Puppetlabs Spec Helper's spec testing in conjunction with Puppet Check's file validation.
|
125
|
+
### What About Puppet Development Kit?
|
126
|
+
The fairly recent release of the Puppet Development Kit (PDK) will hopefully eventually bring about the capability to test and validate your Puppet code and data in a streamlined, efficient, comprehensive, and accurate fashion comparable to Puppet Check. Unfortunately, the PDK has not yet achieved feature or efficiency parity with Puppet Check. The goal is for the PDK to one day replace Puppet Check and for Puppet Check to enter maintenance mode, but for now Puppet Check is still needed to lead Puppet testing.
|
139
127
|
|
140
128
|
## Usage
|
141
|
-
|
142
|
-
|
143
|
-
#### Ruby 2.0 and Reek/Rubocop
|
144
|
-
Reek dropped support for Ruby 2.0 when it went to 4.0. Since dependencies by Ruby version are allowed in Gemfiles but not gemspecs, this means that PuppetCheck installed with `bundler` will automatically pick up the correct version of Reek for your Ruby version and install it. If you are installing PuppetCheck via `gem`, then you can install reek normally with `gem` with Ruby >= 2.1, but you will need to specify `gem install reek -v 3.11` if you are using Ruby 2.0.
|
145
|
-
|
146
|
-
Similarly, RuboCop has dropped support for Ruby 2.0 at 0.51.0. Since this is a recent change, the expectation will be to automatically manage this dependency outside of Puppet Check. Only new installations on 2.0 will be affected by this.
|
129
|
+
Please see the [Gemspec](puppet-check.gemspec) for dependency information. All other dependencies should be fine with various versions. Puppet Check can be used with a CLI, Rake tasks, or API, from your system, rbenv, rvm, Docker, or Vagrant. Please note all interfaces (API by default, but can be modified) will ignore any directories named `fixtures` or specified paths with that directory during file checks and spec tests.
|
147
130
|
|
148
131
|
### CLI
|
149
132
|
```
|
150
133
|
usage: puppet-check [options] paths
|
151
134
|
--version Display the current version.
|
152
|
-
-f, --future Enable future parser
|
153
135
|
--fail-on-warnings Fail on warnings
|
154
136
|
-s, --style Enable style checks
|
155
137
|
--smoke Enable smoke testing
|
@@ -166,7 +148,7 @@ usage: puppet-check [options] paths
|
|
166
148
|
--rubocop arg_one,arg_two Arguments for Rubocop disabled cops
|
167
149
|
```
|
168
150
|
|
169
|
-
The command line interface enables the ability to select
|
151
|
+
The command line interface enables the ability to select additional style checks besides the syntax checks, and to specify PuppetLint and Rubocop checks to ignore. If you require a more robust interface to PuppetLint, Rubocop, and Reek, then please use `.puppet-lint.rc`, `.rubocop.yml` and `*.reek` config files. The `.puppet-lint.rc` can be specified with the `-c` argument. If it is not specified, then PuppetLint will automatically load one from `.puppet-lint.rc`, `~/.puppet-lint.rc`, or `/etc/puppet-lint.rc`, in that order of preference. The nearest `.rubocop.yml` and `*.reek` will be automatically respected.
|
170
152
|
|
171
153
|
Example:
|
172
154
|
```
|
@@ -185,15 +167,14 @@ rake puppetcheck:kitchen:* # Execute Test Kitchen acceptance tests
|
|
185
167
|
```
|
186
168
|
|
187
169
|
#### puppetcheck:file
|
188
|
-
You can add style, smoke, and regression checks to
|
170
|
+
You can add style, smoke, and regression checks to the `rake puppetcheck:file`, or change the output format, by adding the following after the require:
|
189
171
|
|
190
172
|
```ruby
|
191
173
|
# example of modifying Puppet Check behavior
|
192
|
-
PuppetCheck.settings[:
|
174
|
+
PuppetCheck.settings[:style] = true
|
193
175
|
PuppetCheck.settings[:fail_on_warnings] = true
|
194
|
-
PuppetCheck.settings[:
|
195
|
-
PuppetCheck.settings[:
|
196
|
-
PuppetCheck.settings[:regression_check] = true # in progress, do not use
|
176
|
+
PuppetCheck.settings[:smoke] = true
|
177
|
+
PuppetCheck.settings[:regression] = true # in progress, do not use
|
197
178
|
PuppetCheck.settings[:public] = 'public.pem'
|
198
179
|
PuppetCheck.settings[:private] = 'private.pem'
|
199
180
|
PuppetCheck.settings[:output_format] = 'yaml'
|
@@ -260,9 +241,10 @@ Example:
|
|
260
241
|
Note that `args` will be ignored during `git pull`, `svn update`, and `hg pull/hg update` when the modules are updated instead of freshly cloned.
|
261
242
|
|
262
243
|
#### puppetcheck:beaker
|
263
|
-
|
244
|
+
This task serves as a frontend to the `beaker_quickstart:run_test[hypervisor]` rake task that Beaker provides. It merely provides a convenient unified frontend for the task and automated as part of the `puppetcheck` tasks. Note that you should still provide a hypervisor argument to the rake task when executed individually (e.g. `rake puppetcheck:beaker[vagrant]`). The Vagrant hypervisor will be selected by default when executed as part of the `puppetcheck` task. Vagrant will also be selected by default if no hypervisor argument is provided to the individual task.
|
264
245
|
|
265
|
-
|
246
|
+
#### puppetcheck:kitchen
|
247
|
+
This task serves as a frontend to the `kitchen:all` rake task that Test Kitchen provides. It merely provides a convenient unified frontend for the task and automated as part of the `puppetcheck` tasks.
|
266
248
|
|
267
249
|
### API
|
268
250
|
|
@@ -272,20 +254,20 @@ If you are performing your Puppet testing from within a Ruby script or your own
|
|
272
254
|
# file checks
|
273
255
|
require 'puppet-check'
|
274
256
|
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
PuppetCheck.new.run([dirs, files])
|
257
|
+
settings = {}
|
258
|
+
settings[:fail_on_warnings] = true # default false
|
259
|
+
settings[:style] = true # default false
|
260
|
+
settings[:smoke] = true # default false
|
261
|
+
settings[:regression] = true # in progress, do not use; default false
|
262
|
+
settings[:public] = 'public.pem' # default nil
|
263
|
+
settings[:private] = 'private.pem' # default nil
|
264
|
+
settings[:output_format] = 'yaml' # also 'json'; default 'text'
|
265
|
+
settings[:octoconfig] = '$HOME/octocatalog-diff.cfg.rb' # default '.octocatalog-diff.cfg.rb'
|
266
|
+
settings[:octonodes] = %w(server.example.com) # default: %w(localhost.localdomain)
|
267
|
+
settings[:puppetlint_args] = ['--puppetlint-arg-one', '--puppetlint-arg-two'] # default []
|
268
|
+
settings[:rubocop_args] = ['--except', 'rubocop-arg-one,rubocop-arg-two'] # default []
|
269
|
+
|
270
|
+
PuppetCheck.new.run(settings, [dirs, files])
|
289
271
|
|
290
272
|
# rspec checks (as part of a RSpec::Core::RakeTask.new block with |task|)
|
291
273
|
require 'puppet-check/rspec_puppet_support'
|
@@ -300,7 +282,7 @@ You can also use Puppet Check inside of Docker for quick, portable, and disposab
|
|
300
282
|
|
301
283
|
```dockerfile
|
302
284
|
# a reliable and small container at the moment
|
303
|
-
FROM ubuntu:
|
285
|
+
FROM ubuntu:18.04
|
304
286
|
# you need ruby and any other extra dependencies that come from packages; in this example we install git to use it for downloading external module dependencies
|
305
287
|
RUN apt-get update && apt-get install ruby git -y
|
306
288
|
# you need puppet-check and any other extra dependencies that come from gems; in this example we install reek because the ruby ABI is 2.3 and then rspec-puppet and rake for extra testing
|
@@ -309,7 +291,7 @@ RUN gem install --no-document puppet-check reek rspec-puppet rake
|
|
309
291
|
ENV LANG en_US.UTF-8
|
310
292
|
# create the directory for your module, directory environment, etc. and change directory into it
|
311
293
|
WORKDIR /module_name_or_directory_environment_name
|
312
|
-
# copy the module, directory environment, etc. contents into the corresponding directory inside the container
|
294
|
+
# copy the module, directory environment, etc. contents into the corresponding directory inside the container; alternative, bind a volume mount for your module(s) into the container at runtime
|
313
295
|
COPY / .
|
314
296
|
# execute your tests; in this example we are executing the full suite of tests
|
315
297
|
ENTRYPOINT ["rake", "puppetcheck"]
|
@@ -317,6 +299,8 @@ ENTRYPOINT ["rake", "puppetcheck"]
|
|
317
299
|
|
318
300
|
You can also build your own general container for testing various Puppet situations by removing the last three lines. You can then test each module, directory environment, etc. on top of that container by merely adding and modifying the final three lines to a Dockerfile that uses the container you built from the first four lines. This is recommended usage due to being very efficient and stable.
|
319
301
|
|
302
|
+
As an alternative to copying Puppet code and data into the image for testing, it is also recommended to bind volume mount the container to the directory with your Puppet code and data.
|
303
|
+
|
320
304
|
### Vagrant
|
321
305
|
|
322
306
|
As an alternative to Docker, you can also use Vagrant for quick and disposable testing, but it is not as portable as Docker for these testing purposes. Below is an example Vagrantfile for this purpose.
|
@@ -324,7 +308,7 @@ As an alternative to Docker, you can also use Vagrant for quick and disposable t
|
|
324
308
|
```ruby
|
325
309
|
Vagrant.configure(2) do |config|
|
326
310
|
# a reliable and small box at the moment
|
327
|
-
config.vm.box = 'fedora/
|
311
|
+
config.vm.box = 'fedora/26-cloud-base'
|
328
312
|
|
329
313
|
config.vm.provision 'shell', inline: <<-SHELL
|
330
314
|
# cd to '/vagrant'
|
@@ -348,19 +332,20 @@ To overcome the lack of convenient portability, you could try spinning up the Va
|
|
348
332
|
- 1: PuppetCheck exited with an internal exception (takes preference over other non-zero exit codes) or failed spec test(s).
|
349
333
|
- 2: PuppetCheck exited with one or more errors in your code and data. Alternatively, PuppetCheck exited with one or more warnings in your code and data and you specified to fail on warnings.
|
350
334
|
|
351
|
-
### Optional
|
335
|
+
### Optional Dependencies
|
352
336
|
- **rake** (gem): install this if you want to use Puppet Check with `rake` tasks in addition to the CLI.
|
353
337
|
- **rspec** (gem): install this if you want to use Puppet Check to execute the spec tests for your Ruby files during `rake`.
|
354
338
|
- **rspec-puppet** (gem): install this if you want to use Puppet Check to execute the spec tests for your Puppet files during `rake`.
|
355
|
-
- **octocatalog-diff** (gem): install this if you want to use Puppet Check to execute smoke or regression tests for your Puppet catalog.
|
339
|
+
- **octocatalog-diff** (gem): install a version `>= 1.0` of this if you want to use Puppet Check to execute smoke or regression tests for your Puppet catalog.
|
356
340
|
- **beaker** (gem): install this if you want to use Puppet Check to execute the Beaker acceptance tests during `rake`.
|
357
341
|
- **test-kitchen** (gem): install this if you want to use Puppet Check to execute the Test Kitchen acceptance tests during `rake`.
|
358
342
|
- **git** (pkg): install this if you want to use Puppet Check to download external module dependencies with `git` commands during RSpec Puppet testing.
|
359
343
|
- **mercurial** (pkg): install this if you want to use Puppet Check to download external module dependencies with `hg` commands during RSpec Puppet testing.
|
344
|
+
- **subversion** (pkg): install this if you want to use Puppet Check to download external module dependencies with `svn` commands during RSpec Puppet testing.
|
360
345
|
|
361
346
|
## Contributing
|
362
347
|
Code should pass all spec tests. New features should involve new spec tests. Adherence to Rubocop and Reek is expected where not overly onerous or where the check is of dubious cost/benefit.
|
363
348
|
|
364
349
|
A [Dockerfile](Dockerfile) is provided for easy rake testing. A [Vagrantfile](Vagrantfile) is provided for easy gem building, installation, and post-installation testing.
|
365
350
|
|
366
|
-
Please consult the
|
351
|
+
Please consult the GitHub Project for the current development roadmap.
|
data/lib/puppet-check.rb
CHANGED
@@ -8,52 +8,30 @@ class PuppetCheck
|
|
8
8
|
# initialize settings hash
|
9
9
|
@settings = {}
|
10
10
|
|
11
|
-
# initialize future parser, fail on warning, style check, and regression check bools
|
12
|
-
@settings[:future_parser] = false
|
13
|
-
@settings[:fail_on_warning] = false
|
14
|
-
@settings[:style_check] = false
|
15
|
-
@settings[:smoke_check] = false
|
16
|
-
@settings[:regression_check] = false
|
17
|
-
|
18
|
-
# initialize ssl keys for eyaml checks
|
19
|
-
@settings[:public] = nil
|
20
|
-
@settings[:private] = nil
|
21
|
-
|
22
|
-
# initialize output format option
|
23
|
-
@settings[:output_format] = 'text'
|
24
|
-
|
25
|
-
# initialize octocatalog-diff options
|
26
|
-
@settings[:octoconfig] = '.octocatalog-diff.cfg.rb'
|
27
|
-
@settings[:octonodes] = %w[localhost.localdomain]
|
28
|
-
|
29
|
-
# initialize diagnostic output arrays
|
30
|
-
@settings[:error_files] = []
|
31
|
-
@settings[:warning_files] = []
|
32
|
-
@settings[:clean_files] = []
|
33
|
-
@settings[:ignored_files] = []
|
34
|
-
|
35
|
-
# initialize style arg arrays
|
36
|
-
@settings[:puppetlint_args] = []
|
37
|
-
@settings[:rubocop_args] = []
|
38
|
-
|
39
11
|
# allow the parser methods read user options and append to the file arrays; allow CLI and tasks write to user options
|
40
12
|
class << self
|
41
13
|
attr_accessor :settings
|
42
14
|
end
|
43
15
|
|
44
16
|
# main runner for PuppetCheck
|
45
|
-
def run(paths)
|
17
|
+
def run(settings, paths)
|
18
|
+
# establish settings
|
19
|
+
self.class.settings = settings
|
20
|
+
|
21
|
+
# settings defaults
|
22
|
+
self.class.defaults(settings)
|
23
|
+
|
46
24
|
# grab all of the files to be processed
|
47
25
|
files = self.class.parse_paths(paths)
|
48
26
|
|
49
27
|
# parse the files
|
50
|
-
execute_parsers(files,
|
28
|
+
execute_parsers(files, settings)
|
51
29
|
|
52
30
|
# output the diagnostic results
|
53
|
-
|
31
|
+
settings[:output_format] == 'text' ? OutputResults.text : OutputResults.markup(settings)
|
54
32
|
|
55
33
|
# progress to regression checks if no errors in file checks
|
56
|
-
if self.class.settings[:error_files].empty? && (!
|
34
|
+
if self.class.settings[:error_files].empty? && (!settings[:fail_on_warning] || self.class.settings[:warning_files].empty?)
|
57
35
|
begin
|
58
36
|
require_relative 'puppet-check/regression_check'
|
59
37
|
# if octocatalog-diff is not installed then return immediately
|
@@ -63,7 +41,7 @@ class PuppetCheck
|
|
63
41
|
|
64
42
|
# perform smoke checks if there were no errors and the user desires
|
65
43
|
begin
|
66
|
-
catalog = RegressionCheck.smoke(
|
44
|
+
catalog = RegressionCheck.smoke(settings[:octonodes], settings[:octoconfig]) if settings[:smoke]
|
67
45
|
# smoke check failure? output message and return 2
|
68
46
|
rescue OctocatalogDiff::Errors::CatalogError => err
|
69
47
|
puts 'There was a smoke check error:'
|
@@ -73,7 +51,7 @@ class PuppetCheck
|
|
73
51
|
end
|
74
52
|
# perform regression checks if there were no errors and the user desires
|
75
53
|
# begin
|
76
|
-
# catalog = RegressionCheck.regression(
|
54
|
+
# catalog = RegressionCheck.regression(settings[:octonodes], settings[:octoconfig]) if settings[:regression]
|
77
55
|
# rescue OctocatalogDiff::Errors::CatalogError => err
|
78
56
|
# puts 'There was a catalog compilation error during the regression check:'
|
79
57
|
# puts err
|
@@ -89,6 +67,36 @@ class PuppetCheck
|
|
89
67
|
end
|
90
68
|
end
|
91
69
|
|
70
|
+
# establish default settings
|
71
|
+
def self.defaults(settings)
|
72
|
+
# initialize fail on warning, style check, and regression check bools
|
73
|
+
settings[:fail_on_warning] ||= false
|
74
|
+
settings[:style] ||= false
|
75
|
+
settings[:smoke] ||= false
|
76
|
+
settings[:regression] ||= false
|
77
|
+
|
78
|
+
# initialize ssl keys for eyaml checks
|
79
|
+
settings[:public] ||= nil
|
80
|
+
settings[:private] ||= nil
|
81
|
+
|
82
|
+
# initialize output format option
|
83
|
+
settings[:output_format] ||= 'text'
|
84
|
+
|
85
|
+
# initialize diagnostic output arrays
|
86
|
+
@settings[:error_files] = []
|
87
|
+
@settings[:warning_files] = []
|
88
|
+
@settings[:clean_files] = []
|
89
|
+
@settings[:ignored_files] = []
|
90
|
+
|
91
|
+
# initialize octocatalog-diff options
|
92
|
+
settings[:octoconfig] ||= '.octocatalog-diff.cfg.rb'
|
93
|
+
settings[:octonodes] ||= %w[localhost.localdomain]
|
94
|
+
|
95
|
+
# initialize style arg arrays
|
96
|
+
settings[:puppetlint_args] ||= []
|
97
|
+
settings[:rubocop_args] ||= []
|
98
|
+
end
|
99
|
+
|
92
100
|
# parse the paths and return the array of files
|
93
101
|
def self.parse_paths(paths)
|
94
102
|
files = []
|
@@ -96,7 +104,7 @@ class PuppetCheck
|
|
96
104
|
# traverse the unique paths and return all files
|
97
105
|
paths.uniq.each do |path|
|
98
106
|
if File.directory?(path)
|
99
|
-
files.concat(Dir.glob("#{path}/**/*").select { |subpath| File.file?
|
107
|
+
files.concat(Dir.glob("#{path}/**/*").select { |subpath| File.file?(subpath) })
|
100
108
|
elsif File.file?(path)
|
101
109
|
files.push(path)
|
102
110
|
end
|
@@ -104,31 +112,39 @@ class PuppetCheck
|
|
104
112
|
|
105
113
|
# do not process fixtures, check that at least one file was found, and remove double slashes
|
106
114
|
files.reject! { |file| file =~ /fixtures/ }
|
107
|
-
raise "puppet-check: no files found in supplied paths #{paths.join(', ')}." if files.empty?
|
115
|
+
raise "puppet-check: no files found in supplied paths '#{paths.join(', ')}'." if files.empty?
|
108
116
|
files.map! { |file| file.gsub('//', '/') }
|
109
117
|
|
110
118
|
files.uniq
|
111
119
|
end
|
112
120
|
|
113
121
|
# categorize and pass the files out to the parsers to determine their status
|
114
|
-
def execute_parsers(files,
|
122
|
+
def execute_parsers(files, settings)
|
123
|
+
# check manifests
|
115
124
|
manifests, files = files.partition { |file| File.extname(file) == '.pp' }
|
116
|
-
PuppetParser.manifest(manifests,
|
125
|
+
PuppetParser.manifest(manifests, settings[:style], settings[:puppetlint_args]) unless manifests.empty?
|
126
|
+
# check puppet templates
|
117
127
|
templates, files = files.partition { |file| File.extname(file) == '.epp' }
|
118
|
-
PuppetParser.template(templates)
|
128
|
+
PuppetParser.template(templates) unless templates.empty?
|
129
|
+
# check ruby files
|
119
130
|
rubies, files = files.partition { |file| File.extname(file) == '.rb' }
|
120
|
-
RubyParser.ruby(rubies, style,
|
131
|
+
RubyParser.ruby(rubies, settings[:style], settings[:rubocop_args]) unless rubies.empty?
|
132
|
+
# check ruby templates
|
121
133
|
templates, files = files.partition { |file| File.extname(file) == '.erb' }
|
122
|
-
RubyParser.template(templates)
|
134
|
+
RubyParser.template(templates) unless templates.empty?
|
135
|
+
# check yaml data
|
123
136
|
yamls, files = files.partition { |file| File.extname(file) =~ /\.ya?ml$/ }
|
124
|
-
DataParser.yaml(yamls)
|
137
|
+
DataParser.yaml(yamls) unless yamls.empty?
|
138
|
+
# check json data
|
125
139
|
jsons, files = files.partition { |file| File.extname(file) == '.json' }
|
126
|
-
DataParser.json(jsons)
|
127
|
-
# block this for now
|
140
|
+
DataParser.json(jsons) unless jsons.empty?
|
141
|
+
# check eyaml data; block this for now
|
128
142
|
# eyamls, files = files.partition { |file| File.extname(file) =~ /\.eya?ml$/ }
|
129
|
-
# DataParser.eyaml(eyamls, public, private)
|
143
|
+
# DataParser.eyaml(eyamls, public, private) unless eyamls.empty?
|
144
|
+
# check misc ruby
|
130
145
|
librarians, files = files.partition { |file| File.basename(file) =~ /(?:Puppet|Module|Rake|Gem)file$/ }
|
131
|
-
RubyParser.librarian(librarians, style,
|
132
|
-
|
146
|
+
RubyParser.librarian(librarians, settings[:style], settings[:rubocop_args]) unless librarians.empty?
|
147
|
+
# ignore everything else
|
148
|
+
self.class.settings[:ignored_files].concat(files)
|
133
149
|
end
|
134
150
|
end
|
data/lib/puppet-check/cli.rb
CHANGED
@@ -6,11 +6,11 @@ class PuppetCheck::CLI
|
|
6
6
|
# run method for the cli
|
7
7
|
def self.run(args)
|
8
8
|
# gather the user arguments
|
9
|
-
parse(args)
|
9
|
+
settings = parse(args)
|
10
10
|
raise 'puppet-check: no paths specified; try using --help' if args.empty?
|
11
11
|
|
12
|
-
# run PuppetCheck
|
13
|
-
PuppetCheck.new.run(args)
|
12
|
+
# run PuppetCheck with specified paths
|
13
|
+
PuppetCheck.new.run(settings, args)
|
14
14
|
end
|
15
15
|
|
16
16
|
# parse the user arguments
|
@@ -18,44 +18,48 @@ class PuppetCheck::CLI
|
|
18
18
|
# show help message if no args specified
|
19
19
|
args = %w[-h] if args.empty?
|
20
20
|
|
21
|
+
# initialize settings hash
|
22
|
+
settings = {}
|
23
|
+
|
21
24
|
opt_parser = OptionParser.new do |opts|
|
22
25
|
# usage
|
23
26
|
opts.banner = 'usage: puppet-check [options] paths'
|
24
27
|
|
25
28
|
# base options
|
26
29
|
opts.on('--version', 'Display the current version.') do
|
27
|
-
puts 'puppet-check
|
30
|
+
puts 'puppet-check 2.0.0'
|
28
31
|
exit 0
|
29
32
|
end
|
30
33
|
|
31
34
|
# bool options
|
32
|
-
opts.on('-
|
33
|
-
opts.on('
|
34
|
-
opts.on('
|
35
|
-
opts.on('--
|
36
|
-
opts.on('-r', '--regression', 'Enable regression testing (in progress, do not use)') { PuppetCheck.settings[:regression_check] = true }
|
35
|
+
opts.on('--fail-on-warnings', 'Fail on warnings') { settings[:fail_on_warnings] = true }
|
36
|
+
opts.on('-s', '--style', 'Enable style checks') { settings[:style] = true }
|
37
|
+
opts.on('--smoke', 'Enable smoke testing') { settings[:smoke] = true }
|
38
|
+
opts.on('-r', '--regression', 'Enable regression testing (in progress, do not use)') { settings[:regression] = true }
|
37
39
|
|
38
40
|
# ssl key options for eyaml checks
|
39
|
-
opts.on('--public cert.pem', String, 'Public key for EYAML checks') { |arg|
|
40
|
-
opts.on('--private cert.pem', String, 'Private key for EYAML checks') { |arg|
|
41
|
+
opts.on('--public cert.pem', String, 'Public key for EYAML checks') { |arg| settings[:public] = arg }
|
42
|
+
opts.on('--private cert.pem', String, 'Private key for EYAML checks') { |arg| settings[:private] = arg }
|
41
43
|
|
42
44
|
# formatting options
|
43
|
-
opts.on('-o', '--output format', String, 'Format for results output (default is text): text, json, or yaml') { |arg|
|
45
|
+
opts.on('-o', '--output format', String, 'Format for results output (default is text): text, json, or yaml') { |arg| settings[:output_format] = arg }
|
44
46
|
|
45
47
|
# octocatalog-diff options
|
46
|
-
opts.on('--octoconfig config_file', String, 'Octocatalog-diff configuration file to use') { |arg|
|
47
|
-
opts.on('-n', '--octonodes node1.example.com,node2.example.com', Array, 'Octocatalog-diff nodes to test catalog on') { |arg|
|
48
|
+
opts.on('--octoconfig config_file', String, 'Octocatalog-diff configuration file to use') { |arg| settings[:octoconfig] = arg }
|
49
|
+
opts.on('-n', '--octonodes node1.example.com,node2.example.com', Array, 'Octocatalog-diff nodes to test catalog on') { |arg| settings[:octonodes] = arg }
|
48
50
|
|
49
51
|
# arguments to style checkers
|
50
52
|
opts.on('--puppet-lint arg_one,arg_two', Array, 'Arguments for PuppetLint ignored checks') do |puppetlint_args|
|
51
|
-
|
53
|
+
settings[:puppetlint_args] = puppetlint_args.map { |arg| "--#{arg}" }
|
52
54
|
end
|
53
55
|
opts.on('-c', '--config file', String, 'Load PuppetLint options from file') do |file|
|
54
|
-
|
56
|
+
settings[:puppetlint_args] = File.read(file).split("\n")
|
55
57
|
end
|
56
|
-
opts.on('--rubocop arg_one,arg_two', String, 'Arguments for Rubocop disabled cops') { |arg|
|
58
|
+
opts.on('--rubocop arg_one,arg_two', String, 'Arguments for Rubocop disabled cops') { |arg| settings[:rubocop_args] = ['--except', arg] }
|
57
59
|
end
|
58
60
|
|
61
|
+
# remove atched args and return settings
|
59
62
|
opt_parser.parse!(args)
|
63
|
+
settings
|
60
64
|
end
|
61
65
|
end
|