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 | |
| 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')
| -rwxr-xr-x | spec/unit/indirector/code/configuration.rb | 4 | ||||
| -rwxr-xr-x | spec/unit/indirector/indirection.rb | 18 | ||||
| -rwxr-xr-x | spec/unit/indirector/terminus.rb | 20 | ||||
| -rwxr-xr-x | spec/unit/node/configuration.rb | 186 |
4 files changed, 209 insertions, 19 deletions
diff --git a/spec/unit/indirector/code/configuration.rb b/spec/unit/indirector/code/configuration.rb index bc54f4e1c..0038a038e 100755 --- a/spec/unit/indirector/code/configuration.rb +++ b/spec/unit/indirector/code/configuration.rb @@ -143,7 +143,9 @@ describe Puppet::Indirector::Code::Configuration, " when creating configurations it "should return the results of compiling as the configuration" do config = mock 'config' - @compiler.interpreter.expects(:compile).with(@node).returns(:configuration) + result = mock 'result', :to_transportable => :configuration + + @compiler.interpreter.expects(:compile).with(@node).returns(result) @compiler.find(@name).should == :configuration end diff --git a/spec/unit/indirector/indirection.rb b/spec/unit/indirector/indirection.rb index 4fcf5fc11..7a1c4531c 100755 --- a/spec/unit/indirector/indirection.rb +++ b/spec/unit/indirector/indirection.rb @@ -7,7 +7,7 @@ require 'puppet/indirector' describe Puppet::Indirector::Indirection do before do @indirection = Puppet::Indirector::Indirection.new(mock('model'), :test) - @terminus = stub 'terminus', :fresh? => false + @terminus = stub 'terminus', :has_most_recent? => false @indirection.stubs(:terminus).returns(@terminus) @instance = stub 'instance', :version => nil, :version= => nil, :name => "whatever" @name = :mything @@ -286,12 +286,12 @@ describe Puppet::Indirector::Indirection, " when saving and using a cache" do end it "should not update the cache or terminus if the new object is not different" do - @cache.expects(:fresh?).with(@name, 5).returns(true) + @cache.expects(:has_most_recent?).with(@name, 5).returns(true) @indirection.save(@instance) end it "should update the original and the cache if the cached object is different" do - @cache.expects(:fresh?).with(@name, 5).returns(false) + @cache.expects(:has_most_recent?).with(@name, 5).returns(false) @terminus.expects(:save).with(@instance) @cache.expects(:save).with(@instance) @indirection.save(@instance) @@ -311,8 +311,8 @@ describe Puppet::Indirector::Indirection, " when finding and using a cache" do name = "myobject" - @cache.expects(:version).with(name).returns(1) - @terminus.expects(:fresh?).with(name, 1).returns(true) + @terminus.expects(:version).with(name).returns(1) + @cache.expects(:has_most_recent?).with(name, 1).returns(true) @cache.expects(:find).with(name).returns(cached) @@ -324,9 +324,9 @@ describe Puppet::Indirector::Indirection, " when finding and using a cache" do name = "myobject" - @cache.expects(:version).with(name).returns(1) @cache.stubs(:save) - @terminus.expects(:fresh?).with(name, 1).returns(false) + @cache.expects(:has_most_recent?).with(name, 1).returns(false) + @terminus.expects(:version).with(name).returns(1) @terminus.expects(:find).with(name).returns(real) @@ -338,8 +338,8 @@ describe Puppet::Indirector::Indirection, " when finding and using a cache" do name = "myobject" - @cache.expects(:version).with(name).returns(1) - @terminus.expects(:fresh?).with(name, 1).returns(false) + @terminus.expects(:version).with(name).returns(1) + @cache.expects(:has_most_recent?).with(name, 1).returns(false) @terminus.expects(:find).with(name).returns(real) @cache.expects(:save).with(real) diff --git a/spec/unit/indirector/terminus.rb b/spec/unit/indirector/terminus.rb index 2488a1a67..3361bfeeb 100755 --- a/spec/unit/indirector/terminus.rb +++ b/spec/unit/indirector/terminus.rb @@ -247,7 +247,7 @@ describe Puppet::Indirector::Terminus, " when managing indirected instances" do include TerminusInstanceTesting it "should support comparing an instance's version with the terminus's version using just the instance's key" do - @terminus.should respond_to(:fresh?) + @terminus.should respond_to(:has_most_recent?) end it "should fail if the :version method has not been overridden and no :find method is available" do @@ -270,18 +270,30 @@ describe Puppet::Indirector::Terminus, " when managing indirected instances" do it "should consider an instance fresh if its version is more recent than the version provided" do name = "yay" @terminus.expects(:version).with(name).returns(5) - @terminus.fresh?(name, 4).should be_true + @terminus.has_most_recent?(name, 4).should be_true end it "should consider an instance fresh if its version is equal to the version provided" do name = "yay" @terminus.expects(:version).with(name).returns(5) - @terminus.fresh?(name, 5).should be_true + @terminus.has_most_recent?(name, 5).should be_true end it "should consider an instance not fresh if the provided version is more recent than its version" do name = "yay" @terminus.expects(:version).with(name).returns(4) - @terminus.fresh?(name, 5).should be_false + @terminus.has_most_recent?(name, 5).should be_false + end + + # Times annoyingly can't be compared directly to numbers, and our + # default version is 0. + it "should convert versions to floats when checking for freshness" do + existing = mock 'existing version' + new = mock 'new version' + existing.expects(:to_f).returns(1.0) + new.expects(:to_f).returns(1.0) + name = "yay" + @terminus.expects(:version).with(name).returns(existing) + @terminus.has_most_recent?(name, new) end end 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 |
