Class: PuppetCheck

Inherits:
Object
  • Object
show all
Defined in:
lib/puppet-check.rb

Overview

interfaces from CLI/tasks and to individual parsers

Defined Under Namespace

Classes: CLI, Tasks

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Class Attribute Details

.settingsObject

Returns the value of attribute settings.



41
42
43
# File 'lib/puppet-check.rb', line 41

def settings
  @settings
end

Class Method Details

.parse_paths(paths) ⇒ Object

parse the paths and return the array of files



93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/puppet-check.rb', line 93

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



114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
# File 'lib/puppet-check.rb', line 114

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(paths) ⇒ Object

main runner for PuppetCheck



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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/puppet-check.rb', line 45

def run(paths)
  # grab all of the files to be processed
  files = self.class.parse_paths(paths)

  # parse the files
  execute_parsers(files, self.class.settings[:future_parser], self.class.settings[:style_check], self.class.settings[:public], self.class.settings[:private], self.class.settings[:puppetlint_args], self.class.settings[:rubocop_args])

  # output the diagnostic results
  PuppetCheck.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(self.class.octonodes, self.class.octoconfig) if PuppetCheck.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.error_message unless catalog.valid?
      2
    end
    # perform regression checks if there were no errors and the user desires
    # begin
    #   catalog = RegressionCheck.regression(self.class.octonodes, self.class.octoconfig) if PuppetCheck.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