Class: PuppetSyntax::Manifests

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

Instance Method Summary collapse

Instance Method Details

#check(filelist) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
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
# File 'lib/puppet-syntax/manifests.rb', line 3

def check(filelist)
  raise "Expected an array of files" unless filelist.is_a?(Array)
  require 'puppet'
  require 'puppet/face'
  require 'puppet/test/test_helper'

  output = []

  if Puppet::Test::TestHelper.respond_to?(:initialize) # 3.1+
    Puppet::Test::TestHelper.initialize
  end
  Puppet::Test::TestHelper.before_all_tests
  called_before_all_tests = true

  # Catch syntax warnings.
  Puppet::Util::Log.newdestination(Puppet::Test::LogCollector.new(output))
  Puppet::Util::Log.level = :warning

  filelist.each do |puppet_file|
    Puppet::Test::TestHelper.before_each_test
    begin
      validate_manifest(puppet_file)
    rescue SystemExit
      # Disregard exit(1) from face.
    rescue => error
      output << error
    ensure
      Puppet::Test::TestHelper.after_each_test
    end
  end

  Puppet::Util::Log.close_all
  output.map! { |e| e.to_s }

  # Exported resources will raise warnings when outside a puppetmaster.
  output.reject! { |e|
    e =~ /^You cannot collect( exported resources)? without storeconfigs being set/
  }

  # tag parameter in class raise warnings notice in output that prevent from succeed
  output.reject! { |e|
    e =~ /^tag is a metaparam; this value will inherit to all contained resources in the /
  }

  deprecations = output.select { |e|
    e =~ /^Deprecation notice:|is deprecated/
  }

  # Errors exist if there is any output that isn't a deprecation notice.
  has_errors = (output != deprecations)

  return output, has_errors
ensure
  Puppet::Test::TestHelper.after_all_tests if called_before_all_tests
end