diff options
| author | Luke Kanies <luke@madstop.com> | 2007-09-15 22:17:20 -0600 |
|---|---|---|
| committer | Luke Kanies <luke@madstop.com> | 2007-09-15 22:17:20 -0600 |
| commit | f17f19dae941b17a56c1fc83ed3a89712b98c427 (patch) | |
| tree | 3615e9be9ed585511bbe0b85737208bbd85f00f0 /spec/unit/node | |
| parent | 3ccf483f77b026dde8a53bd8e9dff6a5fd0f6722 (diff) | |
| download | puppet-f17f19dae941b17a56c1fc83ed3a89712b98c427.tar.gz puppet-f17f19dae941b17a56c1fc83ed3a89712b98c427.tar.xz puppet-f17f19dae941b17a56c1fc83ed3a89712b98c427.zip | |
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.
Diffstat (limited to 'spec/unit/node')
| -rwxr-xr-x | spec/unit/node/configuration.rb | 147 | ||||
| -rwxr-xr-x | spec/unit/node/node.rb | 4 |
2 files changed, 144 insertions, 7 deletions
diff --git a/spec/unit/node/configuration.rb b/spec/unit/node/configuration.rb index 774a1550f..3c30d9b3e 100755 --- a/spec/unit/node/configuration.rb +++ b/spec/unit/node/configuration.rb @@ -134,25 +134,158 @@ describe Puppet::Node::Configuration, " when extracting transobjects" do end end -describe Puppet::Node::Configuration, " functioning as a resource container" do +describe Puppet::Node::Configuration, " when functioning as a resource container" do before do - @graph = Puppet::Node::Configuration.new("host") + @config = Puppet::Node::Configuration.new("host") @one = stub 'resource1', :ref => "Me[you]" @two = stub 'resource2', :ref => "Me[him]" @dupe = stub 'resource3', :ref => "Me[you]" end it "should make all vertices available by resource reference" do - @graph.add_resource(@one) - @graph.resource(@one.ref).should equal(@one) + @config.add_resource(@one) + @config.resource(@one.ref).should equal(@one) + @config.vertices.find { |r| r.ref == @one.ref }.should equal(@one) end it "should not allow two resources with the same resource reference" do - @graph.add_resource(@one) - proc { @graph.add_resource(@dupe) }.should raise_error(ArgumentError) + @config.add_resource(@one) + proc { @config.add_resource(@dupe) }.should raise_error(ArgumentError) end it "should not store objects that do not respond to :ref" do - proc { @graph.add_resource("thing") }.should raise_error(ArgumentError) + proc { @config.add_resource("thing") }.should raise_error(ArgumentError) end + + it "should remove all resources when asked" do + @config.add_resource @one + @config.add_resource @two + @one.expects :remove + @two.expects :remove + @config.clear(true) + end + + it "should support a mechanism for finishing resources" do + @one.expects :finish + @two.expects :finish + @config.add_resource @one + @config.add_resource @two + + @config.finalize + end + + it "should optionally support an initialization block and should finalize after such blocks" do + @one.expects :finish + @two.expects :finish + config = Puppet::Node::Configuration.new("host") do |conf| + conf.add_resource @one + conf.add_resource @two + end + end +end + +module ApplyingConfigurations + def setup + @config = Puppet::Node::Configuration.new("host") + + @config.retrieval_duration = Time.now + @transaction = mock 'transaction' + Puppet::Transaction.stubs(:new).returns(@transaction) + @transaction.stubs(:evaluate) + @transaction.stubs(:cleanup) + @transaction.stubs(:addtimes) + end +end + +describe Puppet::Node::Configuration, " when applying" do + include ApplyingConfigurations + + it "should create and evaluate a transaction" do + @transaction.expects(:evaluate) + @config.apply + end + + it "should provide the configuration time to the transaction" do + @transaction.expects(:addtimes).with do |arg| + arg[:config_retrieval].should be_instance_of(Time) + true + end + @config.apply + end + + it "should clean up the transaction" do + @transaction.expects :cleanup + @config.apply + end + + it "should return the transaction" do + @config.apply.should equal(@transaction) + end + + it "should yield the transaction if a block is provided" do + pending "the code works but is not tested" + end + + it "should default to not being a host configuration" do + @config.host_config.should be_nil + end +end + +describe Puppet::Node::Configuration, " when applying host configurations" do + include ApplyingConfigurations + + # super() doesn't work in the setup method for some reason + before do + @config.host_config = true + end + + it "should send a report if reporting is enabled" do + Puppet[:report] = true + @transaction.expects :send_report + @config.apply + end + + it "should send a report if report summaries are enabled" do + Puppet[:summarize] = true + @transaction.expects :send_report + @config.apply + end + + it "should initialize the state database before applying a configuration" do + Puppet::Util::Storage.expects(:load) + + # Short-circuit the apply, so we know we're loading before the transaction + Puppet::Transaction.expects(:new).raises ArgumentError + proc { @config.apply }.should raise_error(ArgumentError) + end + + it "should sync the state database after applying" do + Puppet::Util::Storage.expects(:store) + @config.apply + end + + after { Puppet.config.clear } +end + +describe Puppet::Node::Configuration, " when applying non-host configurations" do + include ApplyingConfigurations + + before do + @config.host_config = false + end + + it "should never send reports" do + Puppet[:report] = true + Puppet[:summarize] = true + @transaction.expects(:send_report).never + @config.apply + end + + it "should never modify the state database" do + Puppet::Util::Storage.expects(:load).never + Puppet::Util::Storage.expects(:store).never + @config.apply + end + + after { Puppet.config.clear } end 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 |
