Skip to content

Commit 3693ffc

Browse files
committed
(PUP-9318) fix $LOAD_PATH handling in device
Previous to this commit, `puppet device` would use the proxy agent's `:libdir` to load all code, since we changed the `:vardir` setting, but not the `:libdir`. While `Puppet::Settings` has hooks to change the `$LOAD_PATH` when `:libdir` changes, those do not trigger when the change is effected through a interpolation, like in this case. By setting the `:libdir` explicitely the hook is triggered, and the `$LOAD_PATH` gets updated. This commit also removes the `device` subcommand from the CLI's default `$LOAD_PATH` processing.
1 parent 5c300d6 commit 3693ffc

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

lib/puppet/application/device.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
require 'puppet/application'
2+
require 'puppet/configurer'
23
require 'puppet/util/network_device'
34

45
class Puppet::Application::Device < Puppet::Application
@@ -222,6 +223,7 @@ def main
222223
raise _("missing argument: --target is required when using --apply") if options[:target].nil?
223224
raise _("%{file} does not exist, cannot apply") % { file: options[:apply] } unless File.file?(options[:apply])
224225
end
226+
libdir = Puppet[:libdir]
225227
vardir = Puppet[:vardir]
226228
confdir = Puppet[:confdir]
227229
certname = Puppet[:certname]
@@ -251,9 +253,11 @@ def main
251253

252254
# override local $vardir and $certname
253255
Puppet[:confdir] = ::File.join(Puppet[:devicedir], device.name)
256+
Puppet[:libdir] = ::File.join(Puppet[:devicedir], device.name, 'lib')
254257
Puppet[:vardir] = ::File.join(Puppet[:devicedir], device.name)
255258
Puppet[:certname] = device.name
256259

260+
Puppet::Configurer::PluginHandler.new.download_plugins(env)
257261
# this init the device singleton, so that the facts terminus
258262
# and the various network_device provider can use it
259263
Puppet::Util::NetworkDevice.init(device)
@@ -316,6 +320,7 @@ def main
316320
# If we rescued an error, then we return 1 as the exit code
317321
1
318322
ensure
323+
Puppet[:libdir] = libdir
319324
Puppet[:vardir] = vardir
320325
Puppet[:confdir] = confdir
321326
Puppet[:certname] = certname

lib/puppet/util/command_line.rb

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ def initialize(subcommand_name, command_line)
106106
def run
107107
# For most applications, we want to be able to load code from the modulepath,
108108
# such as apply, describe, resource, and faces.
109-
# For agent, we only want to load pluginsync'ed code from libdir.
109+
# For agent and device, we only want to load pluginsync'ed code from libdir.
110110
# For master, we shouldn't ever be loading per-environment code into the master's
111111
# ruby process, but that requires fixing (#17210, #12173, #8750). So for now
112112
# we try to restrict to only code that can be autoloaded from the node's
@@ -116,8 +116,7 @@ def run
116116
# have an appropriate application-wide current_environment set.
117117
# If we cannot find the configured environment, which may not exist,
118118
# we do not attempt to add plugin directories to the load path.
119-
#
120-
if @subcommand_name != 'master' and @subcommand_name != 'agent'
119+
unless ['master', 'agent', 'device'].include? @subcommand_name
121120
if configured_environment = Puppet.lookup(:environments).get(Puppet[:environment])
122121
configured_environment.each_plugin_directory do |dir|
123122
$LOAD_PATH << dir unless $LOAD_PATH.include?(dir)

0 commit comments

Comments
 (0)