diff options
| author | Luke Kanies <luke@madstop.com> | 2007-09-20 12:57:57 -0500 |
|---|---|---|
| committer | Luke Kanies <luke@madstop.com> | 2007-09-20 12:57:57 -0500 |
| commit | 46d69068fa7b2f3448294c5d3da21c69cef73d2f (patch) | |
| tree | 8abf532af73d4fd7d68d894db639004e331318bc | |
| parent | 9fa2628a844c75b8f554f283dfece01667f20594 (diff) | |
| download | puppet-46d69068fa7b2f3448294c5d3da21c69cef73d2f.tar.gz puppet-46d69068fa7b2f3448294c5d3da21c69cef73d2f.tar.xz puppet-46d69068fa7b2f3448294c5d3da21c69cef73d2f.zip | |
An intermediate commit so I can start working on a different
branch. The file recursion code actually works for the first
time in a painful while, but there are still some quirks and design
issues to resolve, particularly around creating implicit resources
that then fail (i.e., the behaviour of the create_implicit_resource
method in Configuration).
| -rw-r--r-- | lib/puppet/node/configuration.rb | 13 | ||||
| -rw-r--r-- | lib/puppet/pgraph.rb | 2 | ||||
| -rw-r--r-- | lib/puppet/type.rb | 2 | ||||
| -rw-r--r-- | lib/puppet/type/pfile.rb | 24 | ||||
| -rw-r--r-- | lib/puppet/util/config.rb | 2 | ||||
| -rwxr-xr-x | spec/bin/spec | 1 | ||||
| -rwxr-xr-x | spec/unit/indirector/indirection.rb | 2 | ||||
| -rwxr-xr-x | spec/unit/indirector/indirector.rb | 2 | ||||
| -rwxr-xr-x | spec/unit/node/configuration.rb | 19 | ||||
| -rwxr-xr-x | spec/unit/other/modules.rb | 4 | ||||
| -rwxr-xr-x | spec/unit/util/config.rb | 2 | ||||
| -rwxr-xr-x | test/ral/types/file.rb | 4 |
12 files changed, 45 insertions, 32 deletions
diff --git a/lib/puppet/node/configuration.rb b/lib/puppet/node/configuration.rb index c882e0ee1..de6e776c5 100644 --- a/lib/puppet/node/configuration.rb +++ b/lib/puppet/node/configuration.rb @@ -55,13 +55,13 @@ class Puppet::Node::Configuration < Puppet::PGraph # Apply our configuration to the local host. def apply + @applying = true + Puppet::Util::Storage.load if host_config? transaction = Puppet::Transaction.new(self) transaction.addtimes :config_retrieval => @retrieval_duration - @applying = true - begin transaction.evaluate rescue Puppet::Error => detail @@ -122,6 +122,7 @@ class Puppet::Node::Configuration < Puppet::PGraph unless options.include?(:implicit) options[:implicit] = true end + # LAK:FIXME catch exceptions here and return nil when problems if resource = create_resource(type, options) resource.implicit = true @@ -235,6 +236,7 @@ class Puppet::Node::Configuration < Puppet::PGraph @resource_table = {} @transient_resources = [] @applying = false + @relationship_graph = nil if block_given? yield(self) @@ -245,11 +247,12 @@ class Puppet::Node::Configuration < Puppet::PGraph # Create a graph of all of the relationships in our configuration. def relationship_graph unless defined? @relationship_graph and @relationship_graph - relationships = self.class.new + relationships = Puppet::Node::Configuration.new + relationships.host_config = host_config? # First create the dependency graph self.vertices.each do |vertex| - relationships.add_resource vertex + relationships.add_vertex! vertex vertex.builddepends.each do |edge| relationships.add_edge!(edge) end @@ -287,6 +290,7 @@ class Puppet::Node::Configuration < Puppet::PGraph resources.each do |resource| @resource_table.delete(resource.ref) if @resource_table.include?(resource.ref) remove_vertex!(resource) if vertex?(resource) + @relationship_graph.remove_vertex!(resource) if @relationship_graph and @relationship_graph.vertex?(resource) resource.remove end end @@ -345,6 +349,7 @@ class Puppet::Node::Configuration < Puppet::PGraph unless @transient_resources.empty? remove_resource(*@transient_resources) @transient_resources.clear + @relationship_graph = nil end end end diff --git a/lib/puppet/pgraph.rb b/lib/puppet/pgraph.rb index 7a3869dcf..70b466225 100644 --- a/lib/puppet/pgraph.rb +++ b/lib/puppet/pgraph.rb @@ -95,7 +95,7 @@ class Puppet::PGraph < GRATR::Digraph adjacent(source, :direction => :out, :type => :edges).find_all do |edge| edge.match?(event.event) end - end.flatten + end.compact.flatten end # Take container information from another graph and use it diff --git a/lib/puppet/type.rb b/lib/puppet/type.rb index 1db435224..e55873c2b 100644 --- a/lib/puppet/type.rb +++ b/lib/puppet/type.rb @@ -318,7 +318,7 @@ class Type # We should never have more than one parent, so let's just ignore # it if we happen to. - if parents = configuration.adjacent(self, :direction => :in) + if parents = configuration.relationship_graph.adjacent(self, :direction => :in) return parents.shift else return nil diff --git a/lib/puppet/type/pfile.rb b/lib/puppet/type/pfile.rb index da345e5d6..f2fa6a14d 100644 --- a/lib/puppet/type/pfile.rb +++ b/lib/puppet/type/pfile.rb @@ -611,13 +611,14 @@ module Puppet } child = nil - + # The child might already exist because 'localrecurse' runs # before 'sourcerecurse'. I could push the override stuff into # a separate method or something, but the work is the same other # than this last bit, so it doesn't really make sense. if child = configuration.resource(:file, path) unless child.parent.object_id == self.object_id + puts("Parent is %s, I am %s" % [child.parent.ref, self.ref]) if child.parent self.debug "Not managing more explicit file %s" % path return nil @@ -643,22 +644,15 @@ module Puppet args[:parent] = self begin return nil unless child = configuration.create_implicit_resource(:file, args) - rescue Puppet::Error => detail - self.notice( - "Cannot manage: %s" % - [detail.message] - ) - self.debug args.inspect - child = nil rescue => detail - self.notice( - "Cannot manage: %s" % - [detail] - ) - self.debug args.inspect - child = nil + puts detail.backtrace + self.notice "Cannot manage: %s" % [detail] + return nil end - configuration.relationship_graph.add_edge! self, child + end + configuration.relationship_graph.add_edge! self, child + unless child.parent + raise "Did not set parent of %s" % child.ref end return child end diff --git a/lib/puppet/util/config.rb b/lib/puppet/util/config.rb index 3988b3fe0..4b6ae9e5b 100644 --- a/lib/puppet/util/config.rb +++ b/lib/puppet/util/config.rb @@ -1143,7 +1143,7 @@ Generated on #{Time.now}. path = self.value # Skip plain files that don't exist, since we won't be managing them anyway. - return nil unless self.name.to_s =~ /dir$/ or File.exist?(path) + return nil unless self.name.to_s =~ /dir$/ or File.exist?(path) or self.create obj = Puppet::TransObject.new(path, "file") # Only create directories, or files that are specifically marked to diff --git a/spec/bin/spec b/spec/bin/spec index a7e6ce0cb..aaf320f34 100755 --- a/spec/bin/spec +++ b/spec/bin/spec @@ -1,3 +1,4 @@ +#!/usr/bin/env ruby $LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__) + "/../lib")) require 'spec' ::Spec::Runner::CommandLine.run(ARGV, STDERR, STDOUT, true, true) diff --git a/spec/unit/indirector/indirection.rb b/spec/unit/indirector/indirection.rb index e9b10c8c7..c9f15382e 100755 --- a/spec/unit/indirector/indirection.rb +++ b/spec/unit/indirector/indirection.rb @@ -26,7 +26,7 @@ describe Puppet::Indirector::Indirection, " when initializing" do end end -describe Puppet::Indirector, " when managing termini" do +describe Puppet::Indirector::Indirection, " when managing termini" do before do @indirection = Puppet::Indirector::Indirection.new(:node, :to => :node_source) end diff --git a/spec/unit/indirector/indirector.rb b/spec/unit/indirector/indirector.rb index 312c60951..5453d30a7 100755 --- a/spec/unit/indirector/indirector.rb +++ b/spec/unit/indirector/indirector.rb @@ -11,6 +11,8 @@ describe Puppet::Indirector, " when managing indirections" do @indirector.send(:extend, Puppet::Indirector) end + it "should require a name" + it "should create an indirection" do indirection = @indirector.indirects :test, :to => :node_source indirection.name.should == :test diff --git a/spec/unit/node/configuration.rb b/spec/unit/node/configuration.rb index ecf311948..eb4eaa418 100755 --- a/spec/unit/node/configuration.rb +++ b/spec/unit/node/configuration.rb @@ -334,22 +334,28 @@ describe Puppet::Node::Configuration, " when creating a relationship graph" do @three = @file.create :path => "/three" @four = @file.create :path => "/four", :require => ["file", "/three"] - @config.add_resource @compone, @comptwo, @one, @two, @three, @four + @five = @file.create :path => "/five" + @config.add_resource @compone, @comptwo, @one, @two, @three, @four, @five @relationships = @config.relationship_graph end - it "should be able to create a resource graph" do + it "should be able to create a relationship graph" do @relationships.should be_instance_of(Puppet::Node::Configuration) end + it "should copy its host_config setting to the relationship graph" do + config = Puppet::Node::Configuration.new + config.host_config = true + config.relationship_graph.host_config.should be_true + end + it "should not have any components" do @relationships.vertices.find { |r| r.instance_of?(Puppet::Type::Component) }.should be_nil end it "should have all non-component resources from the configuration" do # The failures print out too much info, so i just do a class comparison - @relationships.resource(@one.ref).should be_instance_of(@one.class) - @relationships.resource(@three.ref).should be_instance_of(@three.class) + @relationships.vertex?(@five).should be_true end it "should have all resource relationships set as edges" do @@ -412,6 +418,11 @@ describe Puppet::Node::Configuration, " when creating a relationship graph" do @config.resource("File[/yay]").should be_nil end + it "should remove resources from the relationship graph if it exists" do + @config.remove_resource(@one) + @config.relationship_graph.vertex?(@one).should be_false + end + after do Puppet::Type.allclear end diff --git a/spec/unit/other/modules.rb b/spec/unit/other/modules.rb index 0ab37aa9e..dbd091d9a 100755 --- a/spec/unit/other/modules.rb +++ b/spec/unit/other/modules.rb @@ -5,10 +5,10 @@ require File.dirname(__FILE__) + '/../../spec_helper' describe Puppet::Module, " when building its search path" do include PuppetTest - it "should ignore unqualified paths in the search path" do + it "should fully qualify unqualified paths in the search path" do Puppet[:modulepath] = "something:/my/something" File.stubs(:directory?).returns(true) - Puppet::Module.modulepath.should == %w{/my/something} + Puppet::Module.modulepath.should == [File.join(Dir.getwd, 'something'), "/my/something"] end it "should ignore paths that do not exist" do diff --git a/spec/unit/util/config.rb b/spec/unit/util/config.rb index 353bc2bcb..8114acb8e 100755 --- a/spec/unit/util/config.rb +++ b/spec/unit/util/config.rb @@ -426,6 +426,8 @@ describe Puppet::Util::Config, " when being used to manage the host machine" do pending "Not converted from test/unit yet" end + it "should create files when configured to do so with the :create parameter" + it "should provide a method to convert the file mode enforcement into transportable resources" do # Make it think we're root so it tries to manage user and group. Puppet.features.stubs(:root?).returns(true) diff --git a/test/ral/types/file.rb b/test/ral/types/file.rb index 47fb87afd..b58814a7f 100755 --- a/test/ral/types/file.rb +++ b/test/ral/types/file.rb @@ -1283,8 +1283,6 @@ class TestFile < Test::Unit::TestCase :content => "rahtest", :backup => false ) - - Puppet[:evaltrace] = true destobj = Puppet::Type.newfile(:title => "destdir", :path => destdir, :source => sourcedir, @@ -1299,6 +1297,7 @@ class TestFile < Test::Unit::TestCase assert(FileTest.exists?(purgee), "File got prematurely purged") assert_nothing_raised { destobj[:purge] = true } + Puppet.err :yay config.apply assert(FileTest.exists?(localfile), "Local file got purged") @@ -1755,7 +1754,6 @@ class TestFile < Test::Unit::TestCase assert_nothing_raised("Failure when recursing") do children = obj.eval_generate end - config.add_resource(*children) assert(obj.class[subdir], "did not create subdir object") children.each do |c| assert_nothing_raised("Failure when recursing on %s" % c) do |
