diff options
author | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2006-12-13 17:59:21 +0000 |
---|---|---|
committer | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2006-12-13 17:59:21 +0000 |
commit | c35988aafbbbe3882ff1a5a7ff3ee472f77fb4c1 (patch) | |
tree | 1c403719ba7383efd2b9276381e4ecc8afff468f | |
parent | ab604527648e91b84529c3fb83761b5e9b269b77 (diff) | |
download | puppet-c35988aafbbbe3882ff1a5a7ff3ee472f77fb4c1.tar.gz puppet-c35988aafbbbe3882ff1a5a7ff3ee472f77fb4c1.tar.xz puppet-c35988aafbbbe3882ff1a5a7ff3ee472f77fb4c1.zip |
Another round of bug fixing. Now everything passes except mounts, at least on OS X.
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@1918 980ebf18-57e1-0310-9a29-db15c13687c0
-rw-r--r-- | lib/puppet/event.rb | 233 | ||||
-rw-r--r-- | lib/puppet/metatype/manager.rb | 1 | ||||
-rw-r--r-- | lib/puppet/provider/nameservice/netinfo.rb | 3 | ||||
-rw-r--r-- | lib/puppet/type/state.rb | 2 | ||||
-rwxr-xr-x | test/other/events.rb | 4 | ||||
-rwxr-xr-x | test/other/relationships.rb | 65 | ||||
-rwxr-xr-x | test/other/report.rb | 3 | ||||
-rwxr-xr-x | test/other/transactions.rb | 6 | ||||
-rwxr-xr-x | test/types/file.rb | 7 | ||||
-rwxr-xr-x | test/types/filesources.rb | 4 | ||||
-rwxr-xr-x | test/types/host.rb | 20 | ||||
-rwxr-xr-x | test/types/type.rb | 3 |
12 files changed, 39 insertions, 312 deletions
diff --git a/lib/puppet/event.rb b/lib/puppet/event.rb index 307c3540a..98ea92c9d 100644 --- a/lib/puppet/event.rb +++ b/lib/puppet/event.rb @@ -7,243 +7,10 @@ module Puppet # eventually, these will be passed on to some central event system class Event include Puppet - - # subscriptions are permanent associations determining how different - # objects react to an event - class Subscription - include Puppet - attr_accessor :event, :callback - - # Remove the existing subscriptions and such - def self.clear - self.init - end - - # Remove a subscription - def self.delete(sub) - type, name = sub.targetarray - if @dependencies[type][name].include?(sub) - @dependencies[type][name].delete(sub) - end - - type, name = sub.sourcearray - if @subscriptions[type][name].include?(sub) - @subscriptions[type][name].delete(sub) - end - end - - # Initialize our class variables. This is in a method so it can - # be called to clear the variables, too. - def self.init - # A hash of subscriptions and another of dependencies, organized by - # type, then by name. I'm storing them all here, so that I don't - # have to store the subscriptions with the individual objects, - # which makes creating and destroying objects as necessary much - # easier. - @subscriptions = Hash.new { |hash, key| - hash[key] = Hash.new { |shash, skey| - # Each object has an array of subscriptions - shash[skey] = [] - } - } - - @dependencies = Hash.new { |hash, key| - hash[key] = Hash.new { |shash, skey| - # Each object has an array of subscriptions - shash[skey] = [] - } - } - end - - self.init - - # Store the new subscription in a central hash. - def self.newsub(sub) - # The dependencies map allows me to look up a subscription by - # target -- find out which objects a given object is subscribed - # to, and thus find out which objects that given object depends - # upon. - # DEPENDENCIES == TARGET - ttype, tname = sub.targetarray - @dependencies[ttype][tname] << sub - - # Subscriptions are the list of subscriptions for a given object, - # i.e., the list of all objects that care about a given object's - # events. - # SUBSCRIPTION == SOURCE - stype, sname = sub.sourcearray - @subscriptions[stype][sname] << sub - end - - # Collect all of the subscriptions that target a specific event. - def self.targets_of(event, source) - type, name = self.split(source) - - @subscriptions[type][name].each { |sub| - if sub.match?(event) - yield sub - end - } - end - - # Trigger the subscriptions related to an event, and then pass it up - # as appropriate - def self.trigger(source, event) - type, name = self.split(source) - - @subscriptions[type][name].each { |sub| - if sub.match?(event) - yield sub - #sub.trigger(transaction) - end - } - end - - # Look up an object by type and name. This is used because we - # store symbolic links in our subscription hash rather than storing - # actual object references. - def self.retrieve(ary) - type, name = ary - typeobj = Puppet::Type.type(type) - - unless typeobj - return nil - end - - obj = typeobj[name] - return obj - end - - # Split an object into its type and name - def self.split(object) - return [object.class.name, object.title] - end - - # Retrieve all of the subscriptions that result in a dependency. - # We return the whole dependency here, because it is being returned - # to the object that made the subscription. - def self.dependencies(target) - type, name = self.split(target) - return @dependencies[type][name] - end - - # Return all objects that are subscribed to us. We are only willing - # to return the object, not the subscription object, because the - # source shouldn't need to know things like the event or method that - # we're subscribed to. - def self.subscribers(source) - type, name = self.split(source) - return @subscriptions[type][name].collect { |sub| - sub.target - }.reject { |o| - o.nil? - } - end - - def delete - self.class.delete(self) - end - - # The hash here must include the target and source objects, the event, - # and the callback to call. - def initialize(hash) - hash.each { |param,value| - # assign each value appropriately - # this is probably wicked-slow - self.send(param.to_s + "=",value) - } - - self.class.newsub(self) - #Puppet.debug "New Subscription: '%s' => '%s'" % - # [@source,@event] - end - - # Determine whether the passed event matches our event - def match?(event) - if event == :NONE or @event == :NONE - return false - elsif @event == :ALL_EVENTS or event == :ALL_EVENTS or event == @event - return true - else - return false - end - end - - # The source is the event source. - def source=(object) - type, name = self.class.split(object) - @source = [type, name] - end - - def source - if source = self.class.retrieve(@source) - return source - else - raise Puppet::Error, - "Could not retrieve dependency %s[%s] for %s[%s]" % - [@source[0], @source[1], @target[0], @target[1]] - end - end - - def sourcearray - @source - end - - # The target is the object who will receive the callbacks, i.e., - # a source generates an event, which results in a callback on the - # target. - def target=(object) - type, name = self.class.split(object) - @target = [type, name] - end - - def target - self.class.retrieve(@target) - end - - def targetarray - @target - end - - # Trigger a subscription, which basically calls the associated method - # on the target object. XXX This is currently unused. - def trigger(transaction) - event = nil - - if @event == :NONE - # just ignore these subscriptions - return - end - - if transaction.triggered?(self.target, @callback) > 0 - self.target.info "already applied %s" % [@callback] - else - # We need to call the method, so that it gets retrieved - # as a real object. - target = self.target - #Puppet.debug "'%s' matched '%s'; triggering '%s' on '%s'" % - # [@source,@event,@method,target] - if target.respond_to?(@callback) - target.log "triggering %s" % @callback - event = target.send(@callback) - else - Puppet.debug( - "'%s' of type '%s' does not respond to '%s'" % - [target,target.class,@callback.inspect] - ) - end - transaction.triggered(target, @callback) - end - return event - end - end - attr_accessor :event, :source, :transaction @@events = [] - @@subscriptions = [] - def initialize(args) unless args.include?(:event) and args.include?(:source) raise Puppet::DevError, "Event.new called incorrectly" diff --git a/lib/puppet/metatype/manager.rb b/lib/puppet/metatype/manager.rb index bad41570a..53cb5951d 100644 --- a/lib/puppet/metatype/manager.rb +++ b/lib/puppet/metatype/manager.rb @@ -9,7 +9,6 @@ module Manager # remove all type instances; this is mostly only useful for testing def allclear - Puppet::Event::Subscription.clear @types.each { |name, type| type.clear } diff --git a/lib/puppet/provider/nameservice/netinfo.rb b/lib/puppet/provider/nameservice/netinfo.rb index 879bb7757..313b41753 100644 --- a/lib/puppet/provider/nameservice/netinfo.rb +++ b/lib/puppet/provider/nameservice/netinfo.rb @@ -168,6 +168,9 @@ class NetInfo < Puppet::Provider::NameService def modifycmd(param, value) cmd = [command(:niutil)] + # if value.is_a?(Array) + # warning "Netinfo providers cannot currently handle multiple values" + # end cmd << "-createprop" << "/" << "/%s/%s" % [self.class.netinfodir, @model[:name]] diff --git a/lib/puppet/type/state.rb b/lib/puppet/type/state.rb index 6dd5f1567..24dec6903 100644 --- a/lib/puppet/type/state.rb +++ b/lib/puppet/type/state.rb @@ -461,6 +461,7 @@ class State < Puppet::Parameter else @parent.create end + nil # return nil so the event is autogenerated end newvalue(:absent) do @@ -469,6 +470,7 @@ class State < Puppet::Parameter else @parent.destroy end + nil # return nil so the event is autogenerated end defaultto do diff --git a/test/other/events.rb b/test/other/events.rb index 078e6351f..802a701a3 100755 --- a/test/other/events.rb +++ b/test/other/events.rb @@ -9,10 +9,6 @@ require 'puppettest' class TestEvents < Test::Unit::TestCase include PuppetTest - def teardown - super - Puppet::Event::Subscription.clear - end def test_simplesubscribe name = tempfile() diff --git a/test/other/relationships.rb b/test/other/relationships.rb index 164d52d2a..7b321d821 100755 --- a/test/other/relationships.rb +++ b/test/other/relationships.rb @@ -7,6 +7,11 @@ require 'puppettest' class TestRelationships < Test::Unit::TestCase include PuppetTest + def setup + super + Puppet::Type.type(:exec) + end + def newfile assert_nothing_raised() { return Puppet.type(:file).create( @@ -151,66 +156,6 @@ class TestRelationships < Test::Unit::TestCase assert_equal(symbols, result) end - - def test_newsub - file1 = newfile() - file2 = newfile() - - sub = nil - assert_nothing_raised("Could not create subscription") { - sub = Puppet::Event::Subscription.new( - :source => file1, - :target => file2, - :event => :ALL_EVENTS, - :callback => :refresh - ) - } - - subs = nil - - assert_nothing_raised { - subs = Puppet::Event::Subscription.subscribers(file1) - } - assert_equal(1, subs.length, "Got incorrect number of subs") - assert_equal(sub.target, subs[0], "Got incorrect sub") - - deps = nil - assert_nothing_raised { - deps = Puppet::Event::Subscription.dependencies(file2) - } - assert_equal(1, deps.length, "Got incorrect number of deps") - assert_equal(sub, deps[0], "Got incorrect dep") - end - - def test_eventmatch - file1 = newfile() - file2 = newfile() - - sub = nil - assert_nothing_raised("Could not create subscription") { - sub = Puppet::Event::Subscription.new( - :source => file1, - :target => file2, - :event => :ALL_EVENTS, - :callback => :refresh - ) - } - - assert(sub.match?(:anything), "ALL_EVENTS did not match") - assert(! sub.match?(:NONE), "ALL_EVENTS matched :NONE") - - sub.event = :file_created - - assert(sub.match?(:file_created), "event did not match") - assert(sub.match?(:ALL_EVENTS), "ALL_EVENTS did not match") - assert(! sub.match?(:NONE), "ALL_EVENTS matched :NONE") - - sub.event = :NONE - - assert(! sub.match?(:file_created), "Invalid match") - assert(! sub.match?(:ALL_EVENTS), "ALL_EVENTS matched") - assert(! sub.match?(:NONE), "matched :NONE") - end def test_autorequire # We know that execs autorequire their cwd, so we'll use that diff --git a/test/other/report.rb b/test/other/report.rb index 939d87aaf..551cf4b28 100755 --- a/test/other/report.rb +++ b/test/other/report.rb @@ -60,6 +60,9 @@ class TestReports < Test::Unit::TestCase def test_store_report # Create a bunch of log messages in an array. report = Puppet::Transaction::Report.new + + # We have to reuse reporting here because of something going on in the server/report.rb file + Puppet.config.use(:reporting) 3.times { |i| log = Puppet.warning("Report test message %s" % i) diff --git a/test/other/transactions.rb b/test/other/transactions.rb index 256c815f7..d9a173986 100755 --- a/test/other/transactions.rb +++ b/test/other/transactions.rb @@ -527,14 +527,14 @@ class TestTransactions < Test::Unit::TestCase sorted = graph.topsort.reverse # Now make sure the appropriate edges are there and are in the right order - assert(graph.dependencies(f(:f)).include?(f(:c)), + assert(graph.dependents(f(:f)).include?(f(:c)), "c not marked a dep of f") assert(sorted.index(f(:c)) < sorted.index(f(:f)), "c is not before f") one.each do |o| two.each do |t| - assert(graph.dependencies(o).include?(t), + assert(graph.dependents(o).include?(t), "%s not marked a dep of %s" % [t.ref, o.ref]) assert(sorted.index(t) < sorted.index(o), "%s is not before %s" % [t.ref, o.ref]) @@ -542,7 +542,7 @@ class TestTransactions < Test::Unit::TestCase end trans.resources.leaves(middle).each do |child| - assert(graph.dependencies(f(:h)).include?(child), + assert(graph.dependents(f(:h)).include?(child), "%s not marked a dep of h" % [child.ref]) assert(sorted.index(child) < sorted.index(f(:h)), "%s is not before h" % child.ref) diff --git a/test/types/file.rb b/test/types/file.rb index 917b2e755..f93d3670b 100755 --- a/test/types/file.rb +++ b/test/types/file.rb @@ -1571,14 +1571,8 @@ class TestFile < Test::Unit::TestCase :source => sourcedir, :recurse => true) - puts "a" comp = newcomp(lfobj, destobj) - # trans = comp.evaluate assert_apply(comp) - # assert_nothing_raised { trans.evaluate } - puts "b" - # graph = trans.relgraph - # graph.to_jpg("/Users/luke/Desktop/pics", "purging") assert(FileTest.exists?(dsourcefile), "File did not get copied") assert(FileTest.exists?(localfile), "File did not get created") @@ -1586,7 +1580,6 @@ class TestFile < Test::Unit::TestCase assert_nothing_raised { destobj[:purge] = true } assert_apply(comp) - system("find %s" % destdir) assert(FileTest.exists?(dsourcefile), "File got purged") assert(FileTest.exists?(localfile), "File got purged") diff --git a/test/types/filesources.rb b/test/types/filesources.rb index c1c601b59..09036cca0 100755 --- a/test/types/filesources.rb +++ b/test/types/filesources.rb @@ -102,9 +102,9 @@ class TestFileSources < Test::Unit::TestCase assert_equal("file", result[:type]) assert(result[:checksum], "did not get value for checksum") if Puppet::SUIDManager.uid == 0 - assert(result.has_key?("owner"), "Lost owner in describe") + assert(result.has_key?(:owner), "Lost owner in describe") else - assert(! result.has_key?("owner"), + assert(! result.has_key?(:owner), "Kept owner in describe even tho not root") end diff --git a/test/types/host.rb b/test/types/host.rb index a68e46020..280959c45 100755 --- a/test/types/host.rb +++ b/test/types/host.rb @@ -92,7 +92,18 @@ class TestHost < Test::Unit::TestCase end def test_moddinghost + # We want to actually use the netinfo provider on darwin + if Facter.value(:operatingsystem) == "Darwin" + Puppet::Type.type(:host).defaultprovider = nil + end host = mkhost() + if Facter.value(:operatingsystem) == "Darwin" + assert_equal(:netinfo, host[:provider], "Got incorrect provider") + end + cleanup do + host[:ensure] = :absent + assert_apply(host) + end assert_events([:host_created], host) @@ -107,7 +118,14 @@ class TestHost < Test::Unit::TestCase host.retrieve - assert_equal(%w{madstop kirby yayness}, host.is(:alias)) + if Facter.value(:operatingsystem) == "Darwin" + # Netinfo can't handle arrays right now + assert_equal(%w{madstop}, host.is(:alias)) + else + assert_equal(%w{madstop kirby yayness}, host.is(:alias)) + end + host[:ensure] = :absent + assert_events([:host_removed], host) end end diff --git a/test/types/type.rb b/test/types/type.rb index aa37f2a18..e8a4d45f1 100755 --- a/test/types/type.rb +++ b/test/types/type.rb @@ -752,11 +752,12 @@ end def test_ref path = tempfile() + Puppet::Type.type(:exec) # uggh, the methods need to load the types file = Puppet::Type.newfile(:path => path) assert_equal("File[#{path}]", file.ref) exec = Puppet::Type.newexec(:title => "yay", :command => "/bin/echo yay") - assert_equal("exec[yay]", exec.ref) + assert_equal("Exec[yay]", exec.ref) end def test_noop_metaparam |