From bf728d23caca4f58ae4ede1a2d477c9fc15e0bdc Mon Sep 17 00:00:00 2001 From: Luke Kanies Date: Tue, 8 Apr 2008 18:21:18 -0500 Subject: Intermediate commit. This commit adds a Request instance into the indirection, pushing it all the way to the terminus instances. It's a big commit because it requires modifying every terminus class. There are still some thorny design issues. In particular, who should be responsible for making the request object? I've tried having both the indirection class and the Indirector module creating it, and both have their issues. Also, the Catalog class previously allowed passing Node instances directly to the find method, which is now no longer possible because the Request class would treat the node as the instance being found. We need the request class to have two modes, one when it's passed an instance and one when it's passed a key. --- spec/integration/node/catalog.rb | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100755 spec/integration/node/catalog.rb (limited to 'spec/integration/node') diff --git a/spec/integration/node/catalog.rb b/spec/integration/node/catalog.rb new file mode 100755 index 000000000..d0ddfd8aa --- /dev/null +++ b/spec/integration/node/catalog.rb @@ -0,0 +1,34 @@ +#!/usr/bin/env ruby +# +# Created by Luke Kanies on 2007-10-18. +# Copyright (c) 2007. All rights reserved. + +require File.dirname(__FILE__) + '/../../spec_helper' + +describe Puppet::Node::Catalog do + describe "when using the indirector" do + after { Puppet::Node::Catalog.indirection.clear_cache } + + it "should be able to delegate to the :yaml terminus" do + Puppet::Node::Catalog.indirection.stubs(:terminus_class).returns :yaml + + # Load now, before we stub the exists? method. + Puppet::Node::Catalog.indirection.terminus(:yaml) + + file = File.join(Puppet[:yamldir], "catalog", "me.yaml") + FileTest.expects(:exist?).with(file).returns false + Puppet::Node::Catalog.find("me").should be_nil + end + + it "should be able to delegate to the :compiler terminus" do + Puppet::Node::Catalog.indirection.stubs(:terminus_class).returns :compiler + + # Load now, before we stub the exists? method. + compiler = Puppet::Node::Catalog.indirection.terminus(:compiler) + + compiler.expects(:compile).with("me").returns nil + + Puppet::Node::Catalog.find("me").should be_nil + end + end +end -- cgit From 7774d9c443f19d44a1e2dab459fc4bfb94e75244 Mon Sep 17 00:00:00 2001 From: Luke Kanies Date: Tue, 8 Apr 2008 21:21:59 -0500 Subject: Ported the rest of the indirection terminuses over to expecting requests instead of having a random interface. --- spec/integration/node/catalog.rb | 10 +++++++--- spec/integration/node/facts.rb | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 3 deletions(-) create mode 100755 spec/integration/node/facts.rb (limited to 'spec/integration/node') diff --git a/spec/integration/node/catalog.rb b/spec/integration/node/catalog.rb index d0ddfd8aa..ca14c2ea8 100755 --- a/spec/integration/node/catalog.rb +++ b/spec/integration/node/catalog.rb @@ -1,7 +1,7 @@ #!/usr/bin/env ruby # -# Created by Luke Kanies on 2007-10-18. -# Copyright (c) 2007. All rights reserved. +# Created by Luke Kanies on 2007-4-8. +# Copyright (c) 2008. All rights reserved. require File.dirname(__FILE__) + '/../../spec_helper' @@ -26,7 +26,11 @@ describe Puppet::Node::Catalog do # Load now, before we stub the exists? method. compiler = Puppet::Node::Catalog.indirection.terminus(:compiler) - compiler.expects(:compile).with("me").returns nil + node = mock 'node' + node.stub_everything + + Puppet::Node.expects(:find).returns(node) + compiler.expects(:compile).with(node).returns nil Puppet::Node::Catalog.find("me").should be_nil end diff --git a/spec/integration/node/facts.rb b/spec/integration/node/facts.rb new file mode 100755 index 000000000..977a1b6c9 --- /dev/null +++ b/spec/integration/node/facts.rb @@ -0,0 +1,34 @@ +#!/usr/bin/env ruby +# +# Created by Luke Kanies on 2008-4-8. +# Copyright (c) 2008. All rights reserved. + +require File.dirname(__FILE__) + '/../../spec_helper' + +describe Puppet::Node::Facts do + describe "when using the indirector" do + after { Puppet::Node::Facts.indirection.clear_cache } + + it "should be able to delegate to the :yaml terminus" do + Puppet::Node::Facts.indirection.stubs(:terminus_class).returns :yaml + + # Load now, before we stub the exists? method. + Puppet::Node::Facts.indirection.terminus(:yaml) + + file = File.join(Puppet[:yamldir], "facts", "me.yaml") + FileTest.expects(:exist?).with(file).returns false + + Puppet::Node::Facts.find("me").should be_nil + end + + it "should be able to delegate to the :facter terminus" do + Puppet::Node::Facts.indirection.stubs(:terminus_class).returns :facter + + Facter.expects(:to_hash).returns "facter_hash" + facts = Puppet::Node::Facts.new("me") + Puppet::Node::Facts.expects(:new).with("me", "facter_hash").returns facts + + Puppet::Node::Facts.find("me").should equal(facts) + end + end +end -- cgit From f285f1aab525a2585532fda0b15b7fd28e994491 Mon Sep 17 00:00:00 2001 From: Luke Kanies Date: Thu, 10 Apr 2008 13:14:58 -0500 Subject: Moved the request creation into the Indirection class instead of the Indirector module. Also, added an 'expire' method to the indirector, so there's an easy way to expire cached instances. --- spec/integration/node/facts.rb | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'spec/integration/node') diff --git a/spec/integration/node/facts.rb b/spec/integration/node/facts.rb index 977a1b6c9..d065918be 100755 --- a/spec/integration/node/facts.rb +++ b/spec/integration/node/facts.rb @@ -9,6 +9,10 @@ describe Puppet::Node::Facts do describe "when using the indirector" do after { Puppet::Node::Facts.indirection.clear_cache } + it "should expire any cached node instances when it is saved" do + raise "This test fails" + end + it "should be able to delegate to the :yaml terminus" do Puppet::Node::Facts.indirection.stubs(:terminus_class).returns :yaml -- cgit From 738889ba027b894867209d5175c716f9a2cc54c6 Mon Sep 17 00:00:00 2001 From: Luke Kanies Date: Thu, 10 Apr 2008 14:44:14 -0500 Subject: Fixing the expire method (it wasn't using a request internally), and fixing the Facts class so it auto-expires any associated cached nodes when facts are saved. --- spec/integration/node/facts.rb | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'spec/integration/node') diff --git a/spec/integration/node/facts.rb b/spec/integration/node/facts.rb index d065918be..c2f876578 100755 --- a/spec/integration/node/facts.rb +++ b/spec/integration/node/facts.rb @@ -10,7 +10,14 @@ describe Puppet::Node::Facts do after { Puppet::Node::Facts.indirection.clear_cache } it "should expire any cached node instances when it is saved" do - raise "This test fails" + Puppet::Node::Facts.indirection.stubs(:terminus_class).returns :yaml + terminus = Puppet::Node::Facts.indirection.terminus(:yaml) + + terminus.expects(:save) + Puppet::Node.expects(:expire).with("me") + + facts = Puppet::Node::Facts.new("me") + facts.save end it "should be able to delegate to the :yaml terminus" do -- cgit