Fixing #621 -- plugins are now downloaded directly into the $libdir, and autoload looks for them there. You can now easily download any reloadable file to your clients.

git-svn-id: https://reductivelabs.com/svn/puppet/trunk@2669 980ebf18-57e1-0310-9a29-db15c13687c0
This commit is contained in:
luke 2007-07-10 04:17:07 +00:00
Родитель 7befe1bc5a
Коммит e662c869bf
4 изменённых файлов: 31 добавлений и 45 удалений

Просмотреть файл

@ -1,3 +1,10 @@
The configuration client now pulls libraries down to $libdir,
and all autoloading is done from there with full support
for any reloadable file, such as types and providers. (#621)
Note that this is not backward compatible -- if you're using
pluginsync right now, you'll need to disable it on your clients
until you can upgrade them.
The Rails log level can now be set via (shockingly!) the
'rails_loglevel' parameter (#710). Note that this isn't
exactly the feature asked for, but I could not find a

Просмотреть файл

@ -436,8 +436,10 @@ module Puppet
self.setdefaults(:main,
:pluginpath => ["$vardir/plugins",
"Where Puppet should look for plugins. Multiple directories should
be colon-separated, like normal PATH variables."],
:plugindest => ["$vardir/plugins",
be colon-separated, like normal PATH variables. As of 0.23.1, this
option is deprecated; download your custom libraries to the $libdir
instead."],
:plugindest => ["$libdir",
"Where Puppet should store plugins that it pulls down from the central
server."],
:pluginsource => ["puppet://$server/plugins",

Просмотреть файл

@ -454,18 +454,20 @@ class Puppet::Network::Client::Master < Puppet::Network::Client
# Retrieve the plugins from the central server. We only have to load the
# changed plugins, because Puppet::Type loads plugins on demand.
def self.getplugins
path = Puppet[:pluginpath].split(":")
download(:dest => Puppet[:plugindest], :source => Puppet[:pluginsource],
:ignore => Puppet[:pluginsignore], :name => "plugin") do |object|
next unless path.include?(::File.dirname(object[:path]))
next if FileTest.directory?(object[:path])
path = object[:path].sub(Puppet[:plugindest], '').sub(/^\/+/, '')
unless Puppet::Util::Autoload.loaded?(path)
next
end
begin
Puppet.info "Reloading plugin %s" %
::File.basename(::File.basename(object[:path])).sub(".rb",'')
Puppet.info "Reloading downloaded file %s" % path
load object[:path]
rescue => detail
Puppet.warning "Could not reload plugin %s: %s" %
Puppet.warning "Could not reload downloaded file %s: %s" %
[object[:path], detail]
end
end

Просмотреть файл

@ -264,63 +264,38 @@ class TestMasterClient < Test::Unit::TestCase
Puppet[:filetimeout] = -1
Puppet[:pluginsource] = tempfile()
Dir.mkdir(Puppet[:pluginsource])
Dir.mkdir(File.join(Puppet[:pluginsource], "testing"))
myplugin = File.join(Puppet[:pluginsource], "myplugin.rb")
$loaded = []
loader = Puppet::Util::Autoload.new(self, "testing")
myplugin = File.join(Puppet[:pluginsource], "testing", "myplugin.rb")
File.open(myplugin, "w") do |f|
f.puts %{Puppet::Type.newtype(:myplugin) do
newparam(:argument) do
isnamevar
end
end
}
f.puts %{$loaded << :myplugin}
end
assert_nothing_raised {
assert_nothing_raised("Could not get plugins") {
Puppet::Network::Client.master.getplugins
}
destfile = File.join(Puppet[:plugindest], "myplugin.rb")
destfile = File.join(Puppet[:plugindest], "testing", "myplugin.rb")
assert(File.exists?(destfile), "Did not get plugin")
obj = Puppet::Type.type(:myplugin)
assert(loader.load(:myplugin), "Did not load downloaded plugin")
assert(obj, "Did not define type")
assert(obj.validattr?(:argument),
"Did not get namevar")
assert($loaded.include?(:myplugin), "Downloaded code was not evaluated")
# Now modify the file and make sure the type is replaced
File.open(myplugin, "w") do |f|
f.puts %{Puppet::Type.newtype(:myplugin) do
newparam(:yayness) do
isnamevar
end
newparam(:rahness) do
end
end
}
f.puts %{$loaded << :changed}
end
assert_nothing_raised {
assert_nothing_raised("Could not get plugin changes") {
Puppet::Network::Client.master.getplugins
}
destfile = File.join(Puppet[:pluginpath], "myplugin.rb")
obj = Puppet::Type.type(:myplugin)
assert(obj, "Did not define type")
assert(obj.validattr?(:yayness),
"Did not get namevar")
assert(obj.validattr?(:rahness),
"Did not get other var")
assert(! obj.validattr?(:argument),
"Old namevar is still valid")
assert($loaded.include?(:changed), "Changed code was not evaluated")
# Now try it again, to make sure we don't have any objects lying around
assert_nothing_raised {