From 5aa4440b6fb8c9199ee549bd8fe0e4afb296c259 Mon Sep 17 00:00:00 2001 From: Luke Kanies Date: Tue, 11 Sep 2007 12:38:56 -0500 Subject: Doing an intermediate commit so rick can look at the work I have done so far. --- spec/unit/node/node.rb | 116 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 116 insertions(+) create mode 100755 spec/unit/node/node.rb (limited to 'spec/unit/node/node.rb') diff --git a/spec/unit/node/node.rb b/spec/unit/node/node.rb new file mode 100755 index 000000000..a6cc1e301 --- /dev/null +++ b/spec/unit/node/node.rb @@ -0,0 +1,116 @@ +#!/usr/bin/env ruby + +require File.dirname(__FILE__) + '/../../spec_helper' + +describe Puppet::Node, " when initializing" do + before do + @node = Puppet::Node.new("testnode") + end + + it "should set the node name" do + @node.name.should == "testnode" + end + + it "should default to an empty parameter hash" do + @node.parameters.should == {} + end + + it "should default to an empty class array" do + @node.classes.should == [] + end + + it "should note its creation time" do + @node.time.should be_instance_of(Time) + end + + it "should accept parameters passed in during initialization" do + params = {"a" => "b"} + @node = Puppet::Node.new("testing", :parameters => params) + @node.parameters.should == params + end + + it "should accept classes passed in during initialization" do + classes = %w{one two} + @node = Puppet::Node.new("testing", :classes => classes) + @node.classes.should == classes + end + + it "should always return classes as an array" do + @node = Puppet::Node.new("testing", :classes => "myclass") + @node.classes.should == ["myclass"] + end + + it "should accept the environment during initialization" do + @node = Puppet::Node.new("testing", :environment => "myenv") + @node.environment.should == "myenv" + end + + it "should accept names passed in" do + @node = Puppet::Node.new("testing", :names => ["myenv"]) + @node.names.should == ["myenv"] + end +end + +describe Puppet::Node, " when returning the environment" do + before do + @node = Puppet::Node.new("testnode") + end + + it "should return the 'environment' fact if present and there is no explicit environment" do + @node.parameters = {"environment" => "myenv"} + @node.environment.should == "myenv" + end + + it "should return the central environment if there is no environment fact nor explicit environment" do + Puppet.config.expects(:[]).with(:environment).returns(:centralenv) + @node.environment.should == :centralenv + end + + it "should not use an explicit environment that is an empty string" do + @node.environment == "" + @node.environment.should be_nil + end + + it "should not use an environment fact that is an empty string" do + @node.parameters = {"environment" => ""} + @node.environment.should be_nil + end + + it "should not use an explicit environment that is an empty string" do + Puppet.config.expects(:[]).with(:environment).returns(nil) + @node.environment.should be_nil + end +end + +describe Puppet::Node, " when merging facts" do + before do + @node = Puppet::Node.new("testnode") + end + + it "should prefer parameters already set on the node over facts from the node" do + @node.parameters = {"one" => "a"} + @node.fact_merge("one" => "c") + @node.parameters["one"].should == "a" + end + + it "should add passed parameters to the parameter list" do + @node.parameters = {"one" => "a"} + @node.fact_merge("two" => "b") + @node.parameters["two"].should == "b" + end +end + +describe Puppet::Node, " when indirecting" do + before do + Puppet[:node_source] = :test_source + @terminus_class = mock 'terminus_class' + @terminus = mock 'terminus' + @terminus_class.expects(:new).returns(@terminus) + Puppet::Indirector.expects(:terminus).with(:node, :test_source).returns(@terminus_class) + end + + it "should redirect to the specified node source" do + @terminus.expects(:get).with(:my_node) + Puppet::Node.get(:my_node) + end +end -- cgit From a6fe70054f4fb3efe4d558ffdd244917ca1c6f9c Mon Sep 17 00:00:00 2001 From: Luke Kanies Date: Wed, 12 Sep 2007 15:32:25 -0500 Subject: Another intermediate commit. The node and fact classes are now functional and are used instead of the network handlers, which have been removed. There are some failing tests as a result, but I want to get this code committed before I massage the rest of the system to make it work again. --- spec/unit/node/node.rb | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) (limited to 'spec/unit/node/node.rb') diff --git a/spec/unit/node/node.rb b/spec/unit/node/node.rb index a6cc1e301..9342dc5ce 100755 --- a/spec/unit/node/node.rb +++ b/spec/unit/node/node.rb @@ -85,32 +85,40 @@ end describe Puppet::Node, " when merging facts" do before do @node = Puppet::Node.new("testnode") + Puppet::Node::Facts.stubs(:get).with(@node.name).returns(Puppet::Node::Facts.new(@node.name, "one" => "c", "two" => "b")) end it "should prefer parameters already set on the node over facts from the node" do @node.parameters = {"one" => "a"} - @node.fact_merge("one" => "c") + @node.fact_merge @node.parameters["one"].should == "a" end it "should add passed parameters to the parameter list" do @node.parameters = {"one" => "a"} - @node.fact_merge("two" => "b") + @node.fact_merge @node.parameters["two"].should == "b" end + + it "should accept arbitrary parameters to merge into its parameters" do + @node.parameters = {"one" => "a"} + @node.merge "two" => "three" + @node.parameters["two"].should == "three" + end end describe Puppet::Node, " when indirecting" do before do - Puppet[:node_source] = :test_source - @terminus_class = mock 'terminus_class' @terminus = mock 'terminus' - @terminus_class.expects(:new).returns(@terminus) - Puppet::Indirector.expects(:terminus).with(:node, :test_source).returns(@terminus_class) + Puppet::Indirector.terminus(:node, Puppet[:node_source]).stubs(:new).returns(@terminus) end it "should redirect to the specified node source" do @terminus.expects(:get).with(:my_node) Puppet::Node.get(:my_node) end + + after do + Puppet::Indirector::Indirection.clear_cache + end end -- cgit From f17f19dae941b17a56c1fc83ed3a89712b98c427 Mon Sep 17 00:00:00 2001 From: Luke Kanies Date: Sat, 15 Sep 2007 22:17:20 -0600 Subject: The whole system now uses Configuration objects instead of ever converting the Transportable objects into a tree of components and then converting that into a graph. This is a significant step, and drastically simplifies the model of how to use a configuration. The old code might have looked something like this: file = Puppet::Type.create :path => "/whatever", ... comp = Puppet::Type.create :name => :whatever comp.push file transaction = comp.evaluate transaction.evaluate The new code looks like this: file = Puppet::Type.create :path => "/whatever", ... config = Puppet::Node::Configuration.new config.add_resource file config.apply I did not really intend to do this much refactoring, but I found I could not use a Configuration object to do work without refactoring a lot of the system. The primary problem was that the Client::Master and the Config classes determined how the transactions behaved; when I moved to using a Configuration, this distinction was lost, which meant that configurations were often needing to create other configurations, which resulted in a whole lot of infinite recursion (e.g., Config objects that create directories for Puppet use Configuration objects -- yes, I'm s/Config/Settings/g soon -- and these Configuration objects would need to create directories). Not everything is fixed, but it's very close. I am clearly over the hump, though, so I wanted to get a commit in. --- spec/unit/node/node.rb | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'spec/unit/node/node.rb') diff --git a/spec/unit/node/node.rb b/spec/unit/node/node.rb index 9342dc5ce..2f63c253d 100755 --- a/spec/unit/node/node.rb +++ b/spec/unit/node/node.rb @@ -11,6 +11,10 @@ describe Puppet::Node, " when initializing" do @node.name.should == "testnode" end + it "should not allow nil node names" do + proc { Puppet::Node.new(nil) }.should raise_error(ArgumentError) + end + it "should default to an empty parameter hash" do @node.parameters.should == {} end -- cgit From 8212f88ce3ad2ddbc7e1e713111d9478171c42b8 Mon Sep 17 00:00:00 2001 From: Luke Kanies Date: Thu, 20 Sep 2007 15:24:20 -0500 Subject: Fixing all existing spec tests so that they now pass given the redesign that Rick implemented. This was mostly a question of fixing the method names and the mocks. --- spec/unit/node/node.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'spec/unit/node/node.rb') diff --git a/spec/unit/node/node.rb b/spec/unit/node/node.rb index 9342dc5ce..899d81ac7 100755 --- a/spec/unit/node/node.rb +++ b/spec/unit/node/node.rb @@ -85,7 +85,7 @@ end describe Puppet::Node, " when merging facts" do before do @node = Puppet::Node.new("testnode") - Puppet::Node::Facts.stubs(:get).with(@node.name).returns(Puppet::Node::Facts.new(@node.name, "one" => "c", "two" => "b")) + Puppet::Node::Facts.stubs(:find).with(@node.name).returns(Puppet::Node::Facts.new(@node.name, "one" => "c", "two" => "b")) end it "should prefer parameters already set on the node over facts from the node" do @@ -110,12 +110,12 @@ end describe Puppet::Node, " when indirecting" do before do @terminus = mock 'terminus' - Puppet::Indirector.terminus(:node, Puppet[:node_source]).stubs(:new).returns(@terminus) + Puppet::Node.stubs(:indirection).returns(@terminus) end it "should redirect to the specified node source" do - @terminus.expects(:get).with(:my_node) - Puppet::Node.get(:my_node) + @terminus.expects(:find).with(:my_node.to_s) + Puppet::Node.find(:my_node.to_s) end after do -- cgit From 3a18348fdbea39f56857b03c8f531bd5a2a8105d Mon Sep 17 00:00:00 2001 From: Luke Kanies Date: Sat, 22 Sep 2007 17:54:46 -0500 Subject: Renaming the 'Puppet::Util::Config' class to 'Puppet::Util::Settings'. This is to clear up confusion caused by the fact that we now have a 'Configuration' class to model host configurations, or any set of resources as a "configuration". --- spec/unit/node/node.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'spec/unit/node/node.rb') diff --git a/spec/unit/node/node.rb b/spec/unit/node/node.rb index 53f362da6..3146f6e7e 100755 --- a/spec/unit/node/node.rb +++ b/spec/unit/node/node.rb @@ -66,7 +66,7 @@ describe Puppet::Node, " when returning the environment" do end it "should return the central environment if there is no environment fact nor explicit environment" do - Puppet.config.expects(:[]).with(:environment).returns(:centralenv) + Puppet.settings.expects(:[]).with(:environment).returns(:centralenv) @node.environment.should == :centralenv end @@ -81,7 +81,7 @@ describe Puppet::Node, " when returning the environment" do end it "should not use an explicit environment that is an empty string" do - Puppet.config.expects(:[]).with(:environment).returns(nil) + Puppet.settings.expects(:[]).with(:environment).returns(nil) @node.environment.should be_nil end end -- cgit From cdc8ea6e81c1b5eba5ea784bb7079c4c1f3965a4 Mon Sep 17 00:00:00 2001 From: Luke Kanies Date: Sun, 23 Sep 2007 19:04:31 -0500 Subject: Taking a first stab at moving configuration compiling into the indirection system. There are still quite a few unanswered questions, the two most notable being embodied in unimplemented tests in the Configuration Code terminus. This also requires changing the behaviour in a few places. In particular, 'puppet' and the 'module_puppet' cfengine module need to store a Node object in memory with the appropriate classes, since that's now the only way to communicate with the compiler. That integration work has not yet been done, partially because the old configuration handler (which the soon-to-be-deprecated master handler now uses) still exists. --- spec/unit/node/node.rb | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'spec/unit/node/node.rb') diff --git a/spec/unit/node/node.rb b/spec/unit/node/node.rb index 3146f6e7e..fe5d2be8b 100755 --- a/spec/unit/node/node.rb +++ b/spec/unit/node/node.rb @@ -126,3 +126,10 @@ describe Puppet::Node, " when indirecting" do Puppet::Indirector::Indirection.clear_cache end end + +describe Puppet::Node do + # LAK:NOTE This is used to keep track of when a given node has connected, + # so we can report on nodes that do not appear to connecting to the + # central server. + it "should provide a method for noting that the node has connected" +end -- cgit