Class: PuppetCheck
- Inherits:
-
Object
- Object
- PuppetCheck
- Defined in:
- lib/puppet_check.rb
Overview
interfaces from CLI/tasks and to individual parsers
Defined Under Namespace
Class Attribute Summary collapse
-
.files ⇒ Object
Returns the value of attribute files.
Class Method Summary collapse
-
.defaults(settings = {}) ⇒ Object
establish default settings.
-
.parse_paths(paths = []) ⇒ Object
parse the paths and return the array of files.
Instance Method Summary collapse
-
#run(settings = {}, paths = []) ⇒ Object
main runner for PuppetCheck.
Class Attribute Details
.files ⇒ Object
Returns the value of attribute files.
18 19 20 |
# File 'lib/puppet_check.rb', line 18 def files @files end |
Class Method Details
.defaults(settings = {}) ⇒ Object
establish default settings
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/puppet_check.rb', line 72 def self.defaults(settings = {}) private_class_method :method # return settings with defaults where unspecified { # initialize fail on warning, style check, and regression check bools fail_on_warning: false, style: false, smoke: false, regression: false, # initialize ssl keys for eyaml checks public: nil, private: nil, # initialize output format option output_format: 'text', # initialize octocatalog-diff options octoconfig: '.octocatalog-diff.cfg.rb', octonodes: %w[localhost.localdomain], # initialize style arg arrays puppetlint_args: [], rubocop_args: [] }.merge(settings) end |
.parse_paths(paths = []) ⇒ Object
parse the paths and return the array of files
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/puppet_check.rb', line 97 def self.parse_paths(paths = []) private_class_method :method files = [] # traverse the unique paths and return all files not explicitly in fixtures paths.uniq.each do |path| if File.directory?(path) # glob all files in directory and concat them files.concat(Dir.glob("#{path}/**/*").select { |subpath| File.file?(subpath) && !subpath.include?('fixtures') }) elsif File.file?(path) && !path.include?('fixtures') files.push(path) else warn "puppet-check: #{path} is not a directory, file, or symlink, and will not be considered during parsing" end end # check that at least one file was found, and remove double slashes from returned array raise "puppet-check: no files found in supplied paths '#{paths.join(', ')}'." if files.empty? files.map { |file| file.gsub('//', '/') }.uniq end |
Instance Method Details
#run(settings = {}, paths = []) ⇒ Object
main runner for PuppetCheck
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/puppet_check.rb', line 22 def run(settings = {}, paths = []) # settings defaults settings = self.class.defaults(settings) # grab all of the files to be processed files = self.class.parse_paths(paths) # parse the files parsed_files = execute_parsers(files, settings[:style], settings[:puppetlint_args], settings[:rubocop_args], settings[:public], settings[:private]) # output the diagnostic results OutputResults.run(parsed_files.clone, settings[:output_format]) # progress to regression checks if no errors in file checks if parsed_files[:errors].empty? && (!settings[:fail_on_warning] || parsed_files[:warnings].empty?) begin require_relative 'puppet-check/regression_check' # perform smoke checks if there were no errors and the user desires catalog = RegressionCheck.smoke(settings[:octonodes], settings[:octoconfig]) if settings[:smoke] # if octocatalog-diff is not installed then continue immediately rescue NameError puts 'puppet-check: immediately continuing to results' # smoke check failure? output message and return 2 rescue OctocatalogDiff::Errors::CatalogError => err puts 'There was a smoke check error:' puts err puts catalog. unless catalog.valid? 2 end # perform regression checks if there were no errors and the user desires # begin # catalog = RegressionCheck.regression(settings[:octonodes], settings[:octoconfig]) if settings[:regression] # rescue OctocatalogDiff::Errors::CatalogError => err # puts 'There was a catalog compilation error during the regression check:' # puts err # puts catalog.error_message unless catalog.valid? # 2 # end # code to output differences in catalog? # everything passed? return 0 0 else # error files? return 2 2 end end |