Skip to content
Permalink
Browse files

(PUP-9035) Load files saved via pluginsync

  • Loading branch information
tvpartytonight committed Aug 1, 2018
1 parent c9d21e0 commit 7404ee14745c78bd4a3173c79cac198809faea74
@@ -334,7 +334,7 @@ def run_internal(options)
end
Puppet.push_context({
:current_environment => local_node_environment,
:loaders => Puppet::Pops::Loaders.new(local_node_environment)
:loaders => Puppet::Pops::Loaders.new(local_node_environment, true)
}, "Local node environment for configurer transaction")

query_options = get_facts(options) unless query_options
@@ -73,15 +73,19 @@ def context_overrides()
# Create a script compiler for the given environment where errors are logged as coming
# from the given node_name
#
def initialize(environment, node_name)
def initialize(environment, node_name, for_agent=false)
@environment = environment
@node_name = node_name

# Create the initial scope, it is needed early
@topscope = Puppet::Parser::Scope.new(self)

# Initialize loaders and Pcore
@loaders = Puppet::Pops::Loaders.new(environment)
if for_agent
@loaders = Puppet::Pops::Loaders.new(environment, true)
else
@loaders = Puppet::Pops::Loaders.new(environment)
end

# Need to compute overrides here, and remember them, because we are about to
# Expensive entries in the context are bound lazily.
@@ -20,7 +20,7 @@ class DeferredResolver
# @return [nil] does not return anything - the catalog is modified as a side effect
#
def self.resolve_and_replace(node, facts, catalog)
compiler = Puppet::Parser::ScriptCompiler.new(node.environment, node.name)
compiler = Puppet::Parser::ScriptCompiler.new(node.environment, node.name, true)
resolver = new(compiler)
resolver.set_facts_variable(facts)
# TODO:
@@ -19,6 +19,18 @@ module Loader
# @api private
#
module ModuleLoaders
# This is exactly the same as the #system_loader_from method, but the argument for path is changed to
# location where pluginsync stores functions.
def self.cached_loader_from(parent_loader, loaders)
LibRootedFileBased.new(parent_loader,
loaders,
nil,
Puppet[:libdir],
'cached_puppet_lib',
[:func_4x, :datatype]
)
end

def self.system_loader_from(parent_loader, loaders)
# Puppet system may be installed in a fixed location via RPM, installed as a Gem, via source etc.
# The only way to find this across the different ways puppet can be installed is
@@ -13,6 +13,7 @@ class LoaderError < Puppet::Error; end

attr_reader :static_loader
attr_reader :puppet_system_loader
attr_reader :puppet_cache_loader
attr_reader :public_environment_loader
attr_reader :private_environment_loader
attr_reader :environment
@@ -43,20 +44,21 @@ def initialize(environment, for_agent)
#
@puppet_system_loader = create_puppet_system_loader()

# 2. Environment loader - i.e. what is bound across the environment, may change for each setup
# 2. Cache loader(optional) - i.e. what puppet stores on disk via pluginsync; gate behind the for_agent flag.
# 3. Environment loader - i.e. what is bound across the environment, may change for each setup
# TODO: loaders need to work when also running in an agent doing catalog application. There is no
# concept of environment the same way as when running as a master (except when doing apply).
# The creation mechanisms should probably differ between the two.
#
@private_environment_loader = if for_agent
add_loader_by_name(Loader::SimpleEnvironmentLoader.new(@puppet_system_loader, 'agent environment'))
@puppet_cache_loader = create_puppet_cache_loader()
create_environment_loader(environment, @puppet_cache_loader)
else
create_environment_loader(environment)
create_environment_loader(environment, @puppet_system_loader)
end

Pcore.init_env(@private_environment_loader)

# 3. module loaders are set up from the create_environment_loader, they register themselves
# 4. module loaders are set up from the create_environment_loader, they register themselves
end

# Called after loader has been added to Puppet Context as :loaders so that dynamic types can
@@ -354,7 +356,11 @@ def create_puppet_system_loader()
Loader::ModuleLoaders.system_loader_from(static_loader, self)
end

def create_environment_loader(environment)
def create_puppet_cache_loader()
Loader::ModuleLoaders.cached_loader_from(puppet_system_loader, self)
end

def create_environment_loader(environment, parent_loader)
# This defines where to start parsing/evaluating - the "initial import" (to use 3x terminology)
# Is either a reference to a single .pp file, or a directory of manifests. If the environment becomes
# a module and can hold functions, types etc. then these are available across all other modules without
@@ -375,11 +381,11 @@ def create_environment_loader(environment)
env_path = env_conf.nil? || !env_conf.is_a?(Puppet::Settings::EnvironmentConf) ? nil : env_conf.path_to_env

if Puppet[:tasks]
loader = Loader::ModuleLoaders.environment_loader_from(puppet_system_loader, self, env_path)
loader = Loader::ModuleLoaders.environment_loader_from(parent_loader, self, env_path)
else
# Create the 3.x resource type loader
static_loader.runtime_3_init
@runtime3_type_loader = add_loader_by_name(Loader::Runtime3TypeLoader.new(puppet_system_loader, self, environment, env_conf.nil? ? nil : env_path))
@runtime3_type_loader = add_loader_by_name(Loader::Runtime3TypeLoader.new(parent_loader, self, environment, env_conf.nil? ? nil : env_path))

if env_path.nil?
# Not a real directory environment, cannot work as a module TODO: Drop when legacy env are dropped?

0 comments on commit 7404ee1

Please sign in to comment.
You can’t perform that action at this time.