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
-
.settings ⇒ Object
Returns the value of attribute settings.
Class Method Summary collapse
-
.defaults ⇒ Object
establish default settings.
-
.parse_paths(paths) ⇒ Object
parse the paths and return the array of files.
Instance Method Summary collapse
-
#execute_parsers(files, future, style, public, private, pl_args, rc_args) ⇒ Object
categorize and pass the files out to the parsers to determine their status.
-
#run(settings, paths) ⇒ Object
main runner for PuppetCheck.
Class Attribute Details
.settings ⇒ Object
Returns the value of attribute settings.
13 14 15 |
# File 'lib/puppet-check.rb', line 13 def settings @settings end |
Class Method Details
.defaults ⇒ Object
establish default settings
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/puppet-check.rb', line 71 def self.defaults # initialize future parser, fail on warning, style check, and regression check bools @settings[:future_parser] ||= false @settings[:fail_on_warning] ||= false @settings[:style_check] ||= false @settings[:smoke_check] ||= false @settings[:regression_check] ||= false # initialize ssl keys for eyaml checks @settings[:public] ||= nil @settings[:private] ||= nil # initialize output format option @settings[:output_format] ||= 'text' # initialize diagnostic output arrays @settings[:error_files] = [] @settings[:warning_files] = [] @settings[:clean_files] = [] @settings[:ignored_files] = [] # initialize octocatalog-diff options @settings[:octoconfig] ||= '.octocatalog-diff.cfg.rb' @settings[:octonodes] ||= %w[localhost.localdomain] # initialize style arg arrays @settings[:puppetlint_args] ||= [] @settings[:rubocop_args] ||= [] end |
.parse_paths(paths) ⇒ Object
parse the paths and return the array of files
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/puppet-check.rb', line 102 def self.parse_paths(paths) files = [] # traverse the unique paths and return all files paths.uniq.each do |path| if File.directory?(path) files.concat(Dir.glob("#{path}/**/*").select { |subpath| File.file?(subpath) }) elsif File.file?(path) files.push(path) end end # do not process fixtures, check that at least one file was found, and remove double slashes files.reject! { |file| file =~ /fixtures/ } raise "puppet-check: no files found in supplied paths #{paths.join(', ')}." if files.empty? files.map! { |file| file.gsub('//', '/') } files.uniq end |
Instance Method Details
#execute_parsers(files, future, style, public, private, pl_args, rc_args) ⇒ Object
categorize and pass the files out to the parsers to determine their status
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 |
# File 'lib/puppet-check.rb', line 123 def execute_parsers(files, future, style, public, private, pl_args, rc_args) # check manifests manifests, files = files.partition { |file| File.extname(file) == '.pp' } PuppetParser.manifest(manifests, future, style, pl_args) unless manifests.empty? # check puppet templates templates, files = files.partition { |file| File.extname(file) == '.epp' } PuppetParser.template(templates) unless templates.empty? # check ruby files rubies, files = files.partition { |file| File.extname(file) == '.rb' } RubyParser.ruby(rubies, style, rc_args) unless rubies.empty? # check ruby templates templates, files = files.partition { |file| File.extname(file) == '.erb' } RubyParser.template(templates) unless templates.empty? # check yaml data yamls, files = files.partition { |file| File.extname(file) =~ /\.ya?ml$/ } DataParser.yaml(yamls) unless yamls.empty? # check json data jsons, files = files.partition { |file| File.extname(file) == '.json' } DataParser.json(jsons) unless jsons.empty? # check eyaml data; block this for now # eyamls, files = files.partition { |file| File.extname(file) =~ /\.eya?ml$/ } # DataParser.eyaml(eyamls, public, private) unless eyamls.empty? # check misc ruby librarians, files = files.partition { |file| File.basename(file) =~ /(?:Puppet|Module|Rake|Gem)file$/ } RubyParser.librarian(librarians, style, rc_args) unless librarians.empty? # ignore everything else self.class.settings[:ignored_files].concat(files) end |
#run(settings, paths) ⇒ Object
main runner for PuppetCheck
17 18 19 20 21 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 |
# File 'lib/puppet-check.rb', line 17 def run(settings, paths) # establish settings self.class.settings = settings # settings defaults self.class.defaults # grab all of the files to be processed files = self.class.parse_paths(paths) # parse the files execute_parsers(files, settings[:future_parser], settings[:style_check], settings[:public], settings[:private], settings[:puppetlint_args], settings[:rubocop_args]) # output the diagnostic results settings[:output_format] == 'text' ? OutputResults.text : OutputResults.markup # progress to regression checks if no errors in file checks if self.class.settings[:error_files].empty? && (!self.class.settings[:fail_on_warning] || self.class.settings[:warning_files].empty?) begin require_relative 'puppet-check/regression_check' # if octocatalog-diff is not installed then return immediately rescue LoadError return 0 end # perform smoke checks if there were no errors and the user desires begin catalog = RegressionCheck.smoke(settings[:octonodes], settings[:octoconfig]) if settings[:smoke_check] # 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_check] # 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 |