Skip to content

Commit

Permalink
(#7316) Append module plugin directories to $LOAD_PATH
Browse files Browse the repository at this point in the history
Previously, face applications delivered as a module could not be loaded.
This is because FaceCollection has problems loading code. For one, it
require's faces and actions within, but load's actions that reside in
different files. So it conceivable that a reloaded face application
could run with older faces, but newer actions.

Second, if we load the face, it will call Puppet::Interface.define,
which will check if the face has already been loaded by calling
FaceCollection[name, version]. But that will attempt to load the face
that we're currently loading, getting into an infinite loop.

Third, the help face application gets a list of available application
names from Application. This list includes applications from gem and
module paths. However, the help face application fails to load faces
which reside in the modulepath, since it's using require and not going
through the Autoloader.

While faces could be modified to use an Autoloader, the longer term plan
is to stop pretending we can reload code in ruby, i.e. always require
based on the current $LOAD_PATH.

This commit adds a `each_plugin_directory` method that yields each
module plugin directories based on the current environment. It also
modifies the CommandLine to append those directories,  unless we are
loading the master or agent applications.

In the case of an agent, the libdir is always in the $LOAD_PATH, and it
will load pluginsync'ed files from there. This aspect of #4248 has been
fixed for sometime.

In the case of master, we compile catalogs in the context of the
client's environment, not necessarily the environment the master itself
is configured to use. As such, we only want to autoload custom functions
from those modules, not require them. In other words, we don't want those
modules in the $LOAD_PATH to start with. This aspect of #4248 (the
ability to load utility module code from a custom function) is not
fixed, and can't really be fixed until we move to one process per
environment compilation.

In the case of apply, we compile catalogs, but always in its current
environment, so we can safely append to the $LOAD_PATH. And same for
face applications. As a result, the help face can load other faces from
modules.
  • Loading branch information
joshcooper committed Dec 8, 2012
1 parent 38571f5 commit 4f99f25
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
11 changes: 11 additions & 0 deletions lib/puppet/node/environment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,17 @@ def known_resource_types
}
end

# Yields each modules' plugin directory.
#
# @yield [String] Yields the plugin directory from each module to the block.
# @api public
def each_plugin_directory(&block)
modules.map(&:plugin_directory).each do |lib|
lib = Puppet::Util::Autoload.cleanpath(lib)
yield lib if File.directory?(lib)
end
end

def module(name)
modules.find {|mod| mod.name == name}
end
Expand Down
13 changes: 13 additions & 0 deletions lib/puppet/util/command_line.rb
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,19 @@ def initialize(subcommand_name, command_line)
end

def run
# For most applications, we want to be able to load code from the modulepath,
# such as apply, describe, resource, and faces.
# For agent, we only want to load pluginsync'ed code from libdir.
# For master, we shouldn't ever be loading per-enviroment code into the master's
# ruby process, but that requires fixing (#17210, #12173, #8750). So for now
# we try to restrict to only code that can be autoloaded from the node's
# environment.
if @subcommand_name != 'master' and @subcommand_name != 'agent'
Puppet::Node::Environment.new.each_plugin_directory do |dir|
$LOAD_PATH << dir unless $LOAD_PATH.include?(dir)
end
end

app = Puppet::Application.find(@subcommand_name).new(@command_line)
Puppet::Plugins.on_application_initialization(:application_object => @command_line)

Expand Down

0 comments on commit 4f99f25

Please sign in to comment.