diff options
| author | Luke Kanies <luke@madstop.com> | 2008-03-06 14:43:41 -0600 |
|---|---|---|
| committer | Luke Kanies <luke@madstop.com> | 2008-03-06 14:43:41 -0600 |
| commit | 2261032801a39affa1a4c5e998fc2c4dd145503f (patch) | |
| tree | 0911741b17d17826fc7077ea3d57c98e3f2655cf | |
| parent | 27268ad760435c654ddadb30651437c0dd6953e0 (diff) | |
| download | puppet-2261032801a39affa1a4c5e998fc2c4dd145503f.tar.gz puppet-2261032801a39affa1a4c5e998fc2c4dd145503f.tar.xz puppet-2261032801a39affa1a4c5e998fc2c4dd145503f.zip | |
Partially fixing #1113: LDAP nodes now support environments,
and the schema has been updated accordingly.
| -rw-r--r-- | CHANGELOG | 3 | ||||
| -rw-r--r-- | ext/ldap/puppet.schema | 7 | ||||
| -rw-r--r-- | lib/puppet/indirector/node/ldap.rb | 5 | ||||
| -rwxr-xr-x | spec/unit/indirector/node/ldap.rb | 195 |
4 files changed, 126 insertions, 84 deletions
@@ -1,3 +1,6 @@ + Partially fixing #1113: LDAP nodes now support environments, + and the schema has been updated accordingly. + Always duplicating resource defaults in the parser, so that stacked metaparameter values do not result in all resources that receive a given default also getting those stacked diff --git a/ext/ldap/puppet.schema b/ext/ldap/puppet.schema index b7c715ec2..bbad23eab 100644 --- a/ext/ldap/puppet.schema +++ b/ext/ldap/puppet.schema @@ -12,6 +12,11 @@ attributetype ( 1.1.3.9 NAME 'parentnode' EQUALITY caseIgnoreIA5Match SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 ) +attributetype ( 1.1.3.9 NAME 'environment' + DESC 'Puppet Node Environment' + EQUALITY caseIgnoreIA5Match + SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 ) + objectclass ( 1.1.1.2 NAME 'puppetClient' SUP top AUXILIARY DESC 'Puppet Client objectclass' - MAY ( puppetclass $ parentnode )) + MAY ( puppetclass $ parentnode $ environment )) diff --git a/lib/puppet/indirector/node/ldap.rb b/lib/puppet/indirector/node/ldap.rb index dd11f4e9b..9320f3ba1 100644 --- a/lib/puppet/indirector/node/ldap.rb +++ b/lib/puppet/indirector/node/ldap.rb @@ -36,11 +36,14 @@ class Puppet::Node::Ldap < Puppet::Indirector::Ldap information[:parameters][param] = value unless information[:parameters].include?(param) end + information[:environment] ||= parent_info[:environment] + parent = parent_info[:parent] end node.classes = information[:classes].uniq unless information[:classes].empty? node.parameters = information[:parameters] unless information[:parameters].empty? + node.environment = information[:environment] if information[:environment] node.fact_merge return node @@ -87,6 +90,8 @@ class Puppet::Node::Ldap < Puppet::Indirector::Ldap hash end + result[:environment] = result[:parameters]["environment"] if result[:parameters]["environment"] + return result end diff --git a/spec/unit/indirector/node/ldap.rb b/spec/unit/indirector/node/ldap.rb index 95b73de60..2a4f240ed 100755 --- a/spec/unit/indirector/node/ldap.rb +++ b/spec/unit/indirector/node/ldap.rb @@ -5,27 +5,26 @@ require File.dirname(__FILE__) + '/../../../spec_helper' require 'puppet/indirector/node/ldap' describe Puppet::Node::Ldap do - before :each do - @searcher = Puppet::Node::Ldap.new - @entries = {} - entries = @entries - - @connection = mock 'connection' - @entry = mock 'entry' - @connection.stubs(:search).yields(@entry) - @searcher.stubs(:connection).returns(@connection) - @searcher.stubs(:class_attributes).returns([]) - @searcher.stubs(:parent_attribute).returns(nil) - @searcher.stubs(:search_base).returns(:yay) - @searcher.stubs(:search_filter).returns(:filter) - - @node = mock 'node' - @node.stubs(:fact_merge) - @name = "mynode" - Puppet::Node.stubs(:new).with(@name).returns(@node) - end - - describe Puppet::Node::Ldap, " when searching for nodes" do + describe "when searching for nodes" do + before :each do + @searcher = Puppet::Node::Ldap.new + @entries = {} + entries = @entries + + @connection = mock 'connection' + @entry = mock 'entry' + @connection.stubs(:search).yields(@entry) + @searcher.stubs(:connection).returns(@connection) + @searcher.stubs(:class_attributes).returns([]) + @searcher.stubs(:parent_attribute).returns(nil) + @searcher.stubs(:search_base).returns(:yay) + @searcher.stubs(:search_filter).returns(:filter) + + @node = mock 'node' + @node.stubs(:fact_merge) + @name = "mynode" + Puppet::Node.stubs(:new).with(@name).returns(@node) + end it "should return nil if no results are found in ldap" do @connection.stubs(:search) @@ -61,6 +60,13 @@ describe Puppet::Node::Ldap do @searcher.find("mynode") end + it "should set the node's environment to the environment of the results" do + @entry.stubs(:to_hash).returns("environment" => ["test"]) + @node.stubs(:parameters=) + @node.expects(:environment=).with("test") + @searcher.find("mynode") + end + it "should retain false parameter values" do @entry.stubs(:to_hash).returns("one" => [false]) @node.expects(:parameters=).with("one" => false) @@ -78,91 +84,114 @@ describe Puppet::Node::Ldap do @node.expects(:parameters=).with("one" => ["a", "b"]) @searcher.find("mynode") end - end - describe Puppet::Node::Ldap, " when a parent node is specified" do + describe "and a parent node is specified" do + before do + @parent = mock 'parent' + @parent_parent = mock 'parent_parent' - before do - @parent = mock 'parent' - @parent_parent = mock 'parent_parent' + @searcher.meta_def(:search_filter) do |name| + return name + end + @connection.stubs(:search).with { |*args| args[2] == @name }.yields(@entry) + @connection.stubs(:search).with { |*args| args[2] == 'parent' }.yields(@parent) + @connection.stubs(:search).with { |*args| args[2] == 'parent_parent' }.yields(@parent_parent) - @searcher.meta_def(:search_filter) do |name| - return name + @searcher.stubs(:parent_attribute).returns(:parent) end - @connection.stubs(:search).with { |*args| args[2] == @name }.yields(@entry) - @connection.stubs(:search).with { |*args| args[2] == 'parent' }.yields(@parent) - @connection.stubs(:search).with { |*args| args[2] == 'parent_parent' }.yields(@parent_parent) - @searcher.stubs(:parent_attribute).returns(:parent) - end + it "should fail if the parent cannot be found" do + @connection.stubs(:search).with { |*args| args[2] == 'parent' }.returns("whatever") - it "should fail if the parent cannot be found" do - @connection.stubs(:search).with { |*args| args[2] == 'parent' }.returns("whatever") + @entry.stubs(:to_hash).returns({}) + @entry.stubs(:vals).with(:parent).returns(%w{parent}) - @entry.stubs(:to_hash).returns({}) - @entry.stubs(:vals).with(:parent).returns(%w{parent}) + proc { @searcher.find("mynode") }.should raise_error(Puppet::Error) + end - proc { @searcher.find("mynode") }.should raise_error(Puppet::Error) - end + it "should add any parent classes to the node's classes" do + @entry.stubs(:to_hash).returns({}) + @entry.stubs(:vals).with(:parent).returns(%w{parent}) + @entry.stubs(:vals).with("classes").returns(%w{a b}) - it "should add any parent classes to the node's classes" do - @entry.stubs(:to_hash).returns({}) - @entry.stubs(:vals).with(:parent).returns(%w{parent}) - @entry.stubs(:vals).with("classes").returns(%w{a b}) + @parent.stubs(:to_hash).returns({}) + @parent.stubs(:vals).with("classes").returns(%w{c d}) + @parent.stubs(:vals).with(:parent).returns(nil) - @parent.stubs(:to_hash).returns({}) - @parent.stubs(:vals).with("classes").returns(%w{c d}) - @parent.stubs(:vals).with(:parent).returns(nil) + @searcher.stubs(:class_attributes).returns(%w{classes}) + @node.expects(:classes=).with(%w{a b c d}) + @searcher.find("mynode") + end - @searcher.stubs(:class_attributes).returns(%w{classes}) - @node.expects(:classes=).with(%w{a b c d}) - @searcher.find("mynode") - end + it "should add any parent parameters to the node's parameters" do + @entry.stubs(:to_hash).returns("one" => "two") + @entry.stubs(:vals).with(:parent).returns(%w{parent}) - it "should add any parent parameters to the node's parameters" do - @entry.stubs(:to_hash).returns("one" => "two") - @entry.stubs(:vals).with(:parent).returns(%w{parent}) + @parent.stubs(:to_hash).returns("three" => "four") + @parent.stubs(:vals).with(:parent).returns(nil) - @parent.stubs(:to_hash).returns("three" => "four") - @parent.stubs(:vals).with(:parent).returns(nil) + @node.expects(:parameters=).with("one" => "two", "three" => "four") + @searcher.find("mynode") + end - @node.expects(:parameters=).with("one" => "two", "three" => "four") - @searcher.find("mynode") - end + it "should prefer node parameters over parent parameters" do + @entry.stubs(:to_hash).returns("one" => "two") + @entry.stubs(:vals).with(:parent).returns(%w{parent}) - it "should prefer node parameters over parent parameters" do - @entry.stubs(:to_hash).returns("one" => "two") - @entry.stubs(:vals).with(:parent).returns(%w{parent}) + @parent.stubs(:to_hash).returns("one" => "three") + @parent.stubs(:vals).with(:parent).returns(nil) - @parent.stubs(:to_hash).returns("one" => "three") - @parent.stubs(:vals).with(:parent).returns(nil) + @node.expects(:parameters=).with("one" => "two") + @searcher.find("mynode") + end - @node.expects(:parameters=).with("one" => "two") - @searcher.find("mynode") - end + it "should use the parent's environment if the node has none" do + @entry.stubs(:to_hash).returns({}) + @entry.stubs(:vals).with(:parent).returns(%w{parent}) - it "should recursively look up parent information" do - @entry.stubs(:to_hash).returns("one" => "two") - @entry.stubs(:vals).with(:parent).returns(%w{parent}) + @parent.stubs(:to_hash).returns("environment" => ["parent"]) + @parent.stubs(:vals).with(:parent).returns(nil) - @parent.stubs(:to_hash).returns("three" => "four") - @parent.stubs(:vals).with(:parent).returns(['parent_parent']) + @node.stubs(:parameters=) + @node.expects(:environment=).with("parent") + @searcher.find("mynode") + end - @parent_parent.stubs(:to_hash).returns("five" => "six") - @parent_parent.stubs(:vals).with(:parent).returns(nil) - @parent_parent.stubs(:vals).with(:parent).returns(nil) + it "should prefer the node's environment to the parent's" do + @entry.stubs(:to_hash).returns("environment" => %w{child}) + @entry.stubs(:vals).with(:parent).returns(%w{parent}) - @node.expects(:parameters=).with("one" => "two", "three" => "four", "five" => "six") - @searcher.find("mynode") - end + @parent.stubs(:to_hash).returns("environment" => ["parent"]) + @parent.stubs(:vals).with(:parent).returns(nil) + + @node.stubs(:parameters=) + @node.expects(:environment=).with("child") + @searcher.find("mynode") + end + + it "should recursively look up parent information" do + @entry.stubs(:to_hash).returns("one" => "two") + @entry.stubs(:vals).with(:parent).returns(%w{parent}) + + @parent.stubs(:to_hash).returns("three" => "four") + @parent.stubs(:vals).with(:parent).returns(['parent_parent']) - it "should not allow loops in parent declarations" do - @entry.stubs(:to_hash).returns("one" => "two") - @entry.stubs(:vals).with(:parent).returns(%w{parent}) + @parent_parent.stubs(:to_hash).returns("five" => "six") + @parent_parent.stubs(:vals).with(:parent).returns(nil) + @parent_parent.stubs(:vals).with(:parent).returns(nil) - @parent.stubs(:to_hash).returns("three" => "four") - @parent.stubs(:vals).with(:parent).returns([@name]) - proc { @searcher.find("mynode") }.should raise_error(ArgumentError) + @node.expects(:parameters=).with("one" => "two", "three" => "four", "five" => "six") + @searcher.find("mynode") + end + + it "should not allow loops in parent declarations" do + @entry.stubs(:to_hash).returns("one" => "two") + @entry.stubs(:vals).with(:parent).returns(%w{parent}) + + @parent.stubs(:to_hash).returns("three" => "four") + @parent.stubs(:vals).with(:parent).returns([@name]) + proc { @searcher.find("mynode") }.should raise_error(ArgumentError) + end end end end |
