File: catalog_compiler.rb

package info (click to toggle)
puppet-agent 7.23.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 19,092 kB
  • sloc: ruby: 245,074; sh: 456; makefile: 38; xml: 33
file content (56 lines) | stat: -rw-r--r-- 1,653 bytes parent folder | download
1
2
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
require_relative '../../puppet/loaders'
require_relative '../../puppet/pops'

# A Catalog "compiler" that is like the regular compiler but with an API
# that is harmonized with the ScriptCompiler
#
# The Script compiler is "one shot" - it does not support rechecking if underlying source has changed or
# deal with possible errors in a cached environment.
#
class Puppet::Parser::CatalogCompiler < Puppet::Parser::Compiler

  # Evaluates the configured setup for a script + code in an environment with modules
  #
  def compile
    Puppet[:strict_variables] = true
    Puppet[:strict] = :error

    Puppet.override(rich_data: true) do
      super
    end

  rescue Puppet::ParseErrorWithIssue => detail
    detail.node = node.name
    Puppet.log_exception(detail)
    raise
  rescue => detail
    message = "#{detail} on node #{node.name}"
    Puppet.log_exception(detail, message)
    raise Puppet::Error, message, detail.backtrace
  end

  # Evaluates all added constructs, and validates the resulting catalog.
  # This can be called whenever a series of evaluation of puppet code strings
  # have reached a stable state (essentially that there are no relationships to
  # non-existing resources).
  #
  # Raises an error if validation fails.
  #
  def compile_additions
    evaluate_additions
    validate
  end

  # Evaluates added constructs that are lazily evaluated until all of them have been evaluated.
  # 
  def evaluate_additions
    evaluate_generators
    finish
  end

  # Validates the current state of the catalog.
  # Does not cause evaluation of lazy constructs.
  def validate
    validate_catalog(CatalogValidator::FINAL)
  end
end