summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorluke <luke@980ebf18-57e1-0310-9a29-db15c13687c0>2006-06-20 00:25:35 +0000
committerluke <luke@980ebf18-57e1-0310-9a29-db15c13687c0>2006-06-20 00:25:35 +0000
commit0a1e847961977221b36d7d6c8babffe6fa69c4b6 (patch)
tree643b1f62852be92a6d03270c47135bff795e4fbf
parentedabf9e4938b06d2c03117e4812749fb7779bce7 (diff)
downloadpuppet-0a1e847961977221b36d7d6c8babffe6fa69c4b6.tar.gz
puppet-0a1e847961977221b36d7d6c8babffe6fa69c4b6.tar.xz
puppet-0a1e847961977221b36d7d6c8babffe6fa69c4b6.zip
Adding plugins and plugin management. The Master Client will now automatically download plugins if pluginsync is enabled, and they will be automatically sourced.
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@1302 980ebf18-57e1-0310-9a29-db15c13687c0
-rw-r--r--lib/puppet/client/master.rb59
-rw-r--r--lib/puppet/transaction.rb8
-rw-r--r--lib/puppet/type.rb5
-rw-r--r--test/client/master.rb64
4 files changed, 134 insertions, 2 deletions
diff --git a/lib/puppet/client/master.rb b/lib/puppet/client/master.rb
index 53d58daa1..cadabe33b 100644
--- a/lib/puppet/client/master.rb
+++ b/lib/puppet/client/master.rb
@@ -17,8 +17,18 @@ class Puppet::Client::MasterClient < Puppet::Client
new configurations, where you want to fix the broken configuration
rather than reverting to a known-good one."
]
+ )
-
+ Puppet.setdefaults("puppet",
+ :pluginpath => ["$vardir/plugins",
+ "Where Puppet should look for plugins. Multiple directories should
+ be comma-separated."],
+ :pluginsource => ["puppet://puppet/plugins",
+ "From where to retrieve plugins. The standard Puppet ``file`` type
+ is used for retrieval, so anything that is a valid file source can
+ be used here."],
+ :pluginsync => [true,
+ "Whether plugins should be synced with the central server."]
)
@drivername = :Master
@@ -194,6 +204,11 @@ class Puppet::Client::MasterClient < Puppet::Client
)
end
+ # Retrieve the plugins.
+ if Puppet[:pluginsync]
+ getplugins()
+ end
+
objects = nil
if @local
# If we're local, we don't have to do any of the conversion
@@ -379,6 +394,48 @@ class Puppet::Client::MasterClient < Puppet::Client
[Puppet[:classfile], detail]
end
end
+
+ private
+ # Retrieve the plugins from the central server.
+ def getplugins
+ plugins = Puppet::Type.type(:component).create(
+ :name => "plugin_collector"
+ )
+ plugins.push Puppet::Type.type(:file).create(
+ :path => Puppet[:pluginpath],
+ :recurse => true,
+ :source => Puppet[:pluginsource]
+ )
+
+ trans = plugins.evaluate
+
+ begin
+ trans.evaluate
+ rescue Puppet::Error => detail
+ if Puppet[:debug]
+ puts detail.backtrace
+ end
+ Puppet.err "Could not retrieve plugins: %s" % detail
+ end
+
+ # Now source all of the changed objects, but only source those
+ # that are top-level.
+ trans.changed?.find_all { |object|
+ File.dirname(object[:path]) == Puppet[:pluginpath]
+ }.each do |object|
+ begin
+ Puppet.info "Loading plugin %s" %
+ File.basename(object[:path]).sub(".rb",'')
+ load object[:path]
+ rescue => detail
+ Puppet.warning "Could not load %s: %s" %
+ [object[:path], detail]
+ end
+ end
+
+ # Now clean up after ourselves
+ plugins.remove
+ end
end
# $Id$
diff --git a/lib/puppet/transaction.rb b/lib/puppet/transaction.rb
index 682727fe5..6e91f6110 100644
--- a/lib/puppet/transaction.rb
+++ b/lib/puppet/transaction.rb
@@ -8,7 +8,6 @@ module Puppet
class Transaction
attr_accessor :toplevel, :component, :objects, :tags, :ignoreschedules
-
Puppet.config.setdefaults(:transaction,
:tags => ["", "Tags to use to find objects. If this is set, then
only objects tagged with the specified tags will be applied.
@@ -89,6 +88,13 @@ class Transaction
@changes.push change
end
+ # Find all of the changed objects.
+ def changed?
+ @changes.find_all { |change| change.changed }.collect { |change|
+ change.state.parent
+ }.uniq
+ end
+
# Collect all of the targets for the list of events. This is an unintuitive
# method because it recurses up through the source the event.
def collecttargets(events)
diff --git a/lib/puppet/type.rb b/lib/puppet/type.rb
index 2bae3b39d..758f2f1c2 100644
--- a/lib/puppet/type.rb
+++ b/lib/puppet/type.rb
@@ -158,6 +158,11 @@ class Type < Puppet::Element
t = Class.new(parent) do
@name = name
end
+ const = name.to_s.capitalize
+ if const_defined?(const)
+ Puppet.info "Redefining %s" % name
+ remove_const(const)
+ end
const_set(name.to_s.capitalize,t)
# Initialize any necessary variables.
diff --git a/test/client/master.rb b/test/client/master.rb
index 24cc195e6..a2dbad22d 100644
--- a/test/client/master.rb
+++ b/test/client/master.rb
@@ -133,4 +133,68 @@ class TestMasterClient < Test::Unit::TestCase
client.run
}
end
+
+ def test_getplugins
+ Puppet[:pluginsource] = tempfile()
+ Dir.mkdir(Puppet[:pluginsource])
+
+ myplugin = File.join(Puppet[:pluginsource], "myplugin.rb")
+ File.open(myplugin, "w") do |f|
+ f.puts %{Puppet::Type.newtype(:myplugin) do
+ newparam(:argument) do
+ isnamevar
+ end
+end
+}
+ end
+
+ client = mkclient()
+
+ assert_nothing_raised {
+ client.send(:getplugins)
+ }
+
+ destfile = File.join(Puppet[:pluginpath], "myplugin.rb")
+
+ assert(File.exists?(destfile), "Did not get plugin")
+
+ obj = Puppet::Type.type(:myplugin)
+
+ assert(obj, "Did not define type")
+
+ assert(obj.validattr?(:argument),
+ "Did not get namevar")
+
+ # 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
+}
+ end
+
+ assert_nothing_raised {
+ client.send(: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")
+ end
end