diff options
author | Luke Kanies <luke@madstop.com> | 2007-10-08 19:12:39 -0500 |
---|---|---|
committer | Luke Kanies <luke@madstop.com> | 2007-10-08 19:12:39 -0500 |
commit | d24c1ccc56b912e0ff69f7572dd36912c8c739c2 (patch) | |
tree | f86a02ae5845f1b7cb8327247356268a70e0948e /spec/unit/node | |
parent | fc9c850414baff17dc97b0184f34e58b4bec5785 (diff) | |
download | puppet-d24c1ccc56b912e0ff69f7572dd36912c8c739c2.tar.gz puppet-d24c1ccc56b912e0ff69f7572dd36912c8c739c2.tar.xz puppet-d24c1ccc56b912e0ff69f7572dd36912c8c739c2.zip |
All tests should now pass again.
This is the first real pass towards using caching. The `puppet`
executable actually uses the indirection work, instead of
handlers and such (and man! is it cleaner).
Most of this work was a result of trying to get the client-side
story working, with correct yaml caching of configurations, which
means this commit also covers converting configurations to yaml,
which was a much bigger PITA than it needed to be.
I still need to write integration tests, and I also need to cover
the server-side story of a normal configuration retrieval.
Diffstat (limited to 'spec/unit/node')
-rwxr-xr-x | spec/unit/node/configuration.rb | 186 |
1 files changed, 181 insertions, 5 deletions
diff --git a/spec/unit/node/configuration.rb b/spec/unit/node/configuration.rb index 153d0b182..ee3834ef3 100755 --- a/spec/unit/node/configuration.rb +++ b/spec/unit/node/configuration.rb @@ -52,10 +52,6 @@ describe Puppet::Node::Configuration, " when extracting" do end end -describe Puppet::Node::Configuration, " when extracting RAL resources" do - it "should support an extraction method for converting a parser configuration into a RAL configuration" -end - describe Puppet::Node::Configuration, " when extracting transobjects" do def mkscope @@ -155,6 +151,153 @@ describe Puppet::Node::Configuration, " when extracting transobjects" do end end +describe Puppet::Node::Configuration, " when converting to a transobject configuration" do + class TestResource + attr_accessor :name, :virtual, :builtin + def initialize(name, options = {}) + @name = name + options.each { |p,v| send(p.to_s + "=", v) } + end + + def ref + if builtin? + "File[%s]" % name + else + "Class[%s]" % name + end + end + + def virtual? + virtual + end + + def builtin? + builtin + end + + def to_transobject + Puppet::TransObject.new(name, builtin? ? "file" : "class") + end + end + + before do + @original = Puppet::Node::Configuration.new("mynode") + @original.tag(*%w{one two three}) + @original.add_class *%w{four five six} + + @top = TestResource.new 'top' + @topobject = TestResource.new 'topobject', :builtin => true + @virtual = TestResource.new 'virtual', :virtual => true + @virtualobject = TestResource.new 'virtualobject', :builtin => true, :virtual => true + @middle = TestResource.new 'middle' + @middleobject = TestResource.new 'middleobject', :builtin => true + @bottom = TestResource.new 'bottom' + @bottomobject = TestResource.new 'bottomobject', :builtin => true + + @resources = [@top, @topobject, @middle, @middleobject, @bottom, @bottomobject] + + @original.add_edge!(@top, @topobject) + @original.add_edge!(@top, @virtual) + @original.add_edge!(@virtual, @virtualobject) + @original.add_edge!(@top, @middle) + @original.add_edge!(@middle, @middleobject) + @original.add_edge!(@middle, @bottom) + @original.add_edge!(@bottom, @bottomobject) + + @config = @original.to_transportable + end + + it "should add all resources as TransObjects" do + @resources.each { |resource| @config.resource(resource.ref).should be_instance_of(Puppet::TransObject) } + end + + it "should not extract defined virtual resources" do + @config.vertices.find { |v| v.name == "virtual" }.should be_nil + end + + it "should not extract builtin virtual resources" do + @config.vertices.find { |v| v.name == "virtualobject" }.should be_nil + end + + it "should copy the tag list to the new configuration" do + @config.tags.sort.should == @original.tags.sort + end + + it "should copy the class list to the new configuration" do + @config.classes.should == @original.classes + end + + it "should duplicate the original edges" do + @original.edges.each do |edge| + next if edge.source.virtual? or edge.target.virtual? + source = @config.resource(edge.source.ref) + target = @config.resource(edge.target.ref) + + source.should_not be_nil + target.should_not be_nil + @config.edge?(source, target).should be_true + end + end + + it "should set itself as the configuration for each converted resource" do + @config.vertices.each { |v| v.configuration.object_id.should equal(@config.object_id) } + end +end + +describe Puppet::Node::Configuration, " when converting to a RAL configuration" do + before do + @original = Puppet::Node::Configuration.new("mynode") + @original.tag(*%w{one two three}) + @original.add_class *%w{four five six} + + @top = Puppet::TransObject.new 'Class[top]', "component" + @topobject = Puppet::TransObject.new '/topobject', "file" + @middle = Puppet::TransObject.new 'Class[middle]', "component" + @middleobject = Puppet::TransObject.new '/middleobject', "file" + @bottom = Puppet::TransObject.new 'Class[bottom]', "component" + @bottomobject = Puppet::TransObject.new '/bottomobject', "file" + + @resources = [@top, @topobject, @middle, @middleobject, @bottom, @bottomobject] + + @original.add_resource(*@resources) + + @original.add_edge!(@top, @topobject) + @original.add_edge!(@top, @middle) + @original.add_edge!(@middle, @middleobject) + @original.add_edge!(@middle, @bottom) + @original.add_edge!(@bottom, @bottomobject) + + @config = @original.to_ral + end + + it "should add all resources as RAL instances" do + @resources.each { |resource| @config.resource(resource.ref).should be_instance_of(Puppet::Type) } + end + + it "should copy the tag list to the new configuration" do + @config.tags.sort.should == @original.tags.sort + end + + it "should copy the class list to the new configuration" do + @config.classes.should == @original.classes + end + + it "should duplicate the original edges" do + @original.edges.each do |edge| + @config.edge?(@config.resource(edge.source.ref), @config.resource(edge.target.ref)).should be_true + end + end + + it "should set itself as the configuration for each converted resource" do + @config.vertices.each { |v| v.configuration.object_id.should equal(@config.object_id) } + end + + after do + # Remove all resource instances. + @config.clear(true) + end +end + describe Puppet::Node::Configuration, " when functioning as a resource container" do before do @config = Puppet::Node::Configuration.new("host") @@ -500,7 +643,6 @@ describe Puppet::Node::Configuration, " when indirecting" do @indirection = mock 'indirection' Puppet::Indirector::Indirection.clear_cache - @configuration = Puppet::Node::Facts.new("me") end it "should redirect to the indirection for retrieval" do @@ -518,3 +660,37 @@ describe Puppet::Node::Configuration, " when indirecting" do Puppet::Indirector::Indirection.clear_cache end end + +describe Puppet::Node::Configuration, " when converting to yaml" do + before do + @configuration = Puppet::Node::Configuration.new("me") + @configuration.add_edge!("one", "two") + end + + it "should be able to be dumped to yaml" do + YAML.dump(@configuration).should be_instance_of(String) + end +end + +describe Puppet::Node::Configuration, " when converting from yaml" do + before do + @configuration = Puppet::Node::Configuration.new("me") + @configuration.add_edge!("one", "two") + + text = YAML.dump(@configuration) + @newconfig = YAML.load(text) + end + + it "should get converted back to a configuration" do + @newconfig.should be_instance_of(Puppet::Node::Configuration) + end + + it "should have all vertices" do + @newconfig.vertex?("one").should be_true + @newconfig.vertex?("two").should be_true + end + + it "should have all edges" do + @newconfig.edge?("one", "two").should be_true + end +end |