summaryrefslogtreecommitdiffstats
path: root/spec/unit/indirector/node
diff options
context:
space:
mode:
authorLuke Kanies <luke@madstop.com>2007-09-22 00:16:39 -0500
committerLuke Kanies <luke@madstop.com>2007-09-22 00:16:39 -0500
commitebe7290bf0c9119e268c9037c33da515e527aa5b (patch)
tree3f59b5b3fc46c35f5ef18e0a1110381c94187692 /spec/unit/indirector/node
parentb9dc6cb22f087f419b328cafa945c9604043b22f (diff)
All indirections are working, and they have all
been migrated over to the new organization. Where we would have previously had an 'ldap' node terminus at puppet/indirector/node/ldap.rb, we would not have it at puppet/indirector/ldap/node.rb, and it would be a subclass of puppet/indirector/ldap.rb. These are called terminus classes, and there are now three categories of them: The base class itself, abstract classes that provide most of the functionality (e.g., the ldap and yaml classes), and the classes themselves that implement the functionality for a given model like Node or Facts. The base terminus class handles auto-loading any of these classes from disk.
Diffstat (limited to 'spec/unit/indirector/node')
-rwxr-xr-xspec/unit/indirector/node/external.rb119
-rwxr-xr-xspec/unit/indirector/node/ldap.rb243
-rwxr-xr-xspec/unit/indirector/node/none.rb32
3 files changed, 0 insertions, 394 deletions
diff --git a/spec/unit/indirector/node/external.rb b/spec/unit/indirector/node/external.rb
deleted file mode 100755
index c64a6f6e2..000000000
--- a/spec/unit/indirector/node/external.rb
+++ /dev/null
@@ -1,119 +0,0 @@
-#!/usr/bin/env ruby
-
-require File.dirname(__FILE__) + '/../../../spec_helper'
-
-require 'yaml'
-require 'puppet/indirector'
-
-describe Puppet::Indirector.terminus(:node, :external), " when searching for nodes" do
- require 'puppet/node'
-
- before do
- Puppet.config[:external_nodes] = "/yay/ness"
- @searcher = Puppet::Indirector.terminus(:node, :external).new
-
- # Set the searcher up so that we do not need to actually call the
- # external script.
- @searcher.meta_def(:execute) do |command|
- name = command.last.chomp
- result = {}
-
- if name =~ /a/
- result[:parameters] = {'one' => command.last + '1', 'two' => command.last + '2'}
- end
-
- if name =~ /p/
- result['classes'] = [1,2,3].collect { |n| command.last + n.to_s }
- end
-
- return YAML.dump(result)
- end
- end
-
- it "should throw an exception if the node_source is external but no external node command is set" do
- Puppet[:external_nodes] = "none"
- proc { @searcher.find("foo") }.should raise_error(ArgumentError)
- end
-
- it "should throw an exception if the external node source is not fully qualified" do
- Puppet[:external_nodes] = "mycommand"
- proc { @searcher.find("foo") }.should raise_error(ArgumentError)
- end
-
- it "should execute the command with the node name as the only argument" do
- command = [Puppet[:external_nodes], "yay"]
- @searcher.expects(:execute).with(command).returns("")
- @searcher.find("yay")
- end
-
- it "should return a node object" do
- @searcher.find("apple").should be_instance_of(Puppet::Node)
- end
-
- it "should set the node's name" do
- @searcher.find("apple").name.should == "apple"
- end
-
- # If we use a name that has a 'p' but no 'a', then our test generator
- # will return classes but no parameters.
- it "should be able to configure a node's classes" do
- node = @searcher.find("plum")
- node.classes.should == %w{plum1 plum2 plum3}
- node.parameters.should == {}
- end
-
- # If we use a name that has an 'a' but no 'p', then our test generator
- # will return parameters but no classes.
- it "should be able to configure a node's parameters" do
- node = @searcher.find("guava")
- node.classes.should == []
- node.parameters.should == {"one" => "guava1", "two" => "guava2"}
- end
-
- it "should be able to configure a node's classes and parameters" do
- node = @searcher.find("apple")
- node.classes.should == %w{apple1 apple2 apple3}
- node.parameters.should == {"one" => "apple1", "two" => "apple2"}
- end
-
- it "should merge node facts with returned parameters" do
- facts = Puppet::Node::Facts.new("apple", "three" => "four")
- Puppet::Node::Facts.expects(:find).with("apple").returns(facts)
- node = @searcher.find("apple")
- node.parameters["three"].should == "four"
- end
-
- it "should return nil when it cannot find the node" do
- @searcher.find("honeydew").should be_nil
- end
-
- # Make sure a nodesearch with arguments works
- def test_nodesearch_external_arguments
- mapper = mk_node_mapper
- Puppet[:external_nodes] = "#{mapper} -s something -p somethingelse"
- searcher = mk_searcher(:external)
- node = nil
- assert_nothing_raised do
- node = searcher.nodesearch("apple")
- end
- assert_instance_of(SimpleNode, node, "did not create node")
- end
-
- # A wrapper test, to make sure we're correctly calling the external search method.
- def test_nodesearch_external_functional
- mapper = mk_node_mapper
- searcher = mk_searcher(:external)
-
- Puppet[:external_nodes] = mapper
-
- node = nil
- assert_nothing_raised do
- node = searcher.nodesearch("apple")
- end
- assert_instance_of(SimpleNode, node, "did not create node")
- end
-
- after do
- Puppet.config.clear
- end
-end
diff --git a/spec/unit/indirector/node/ldap.rb b/spec/unit/indirector/node/ldap.rb
deleted file mode 100755
index e4b0cd7d4..000000000
--- a/spec/unit/indirector/node/ldap.rb
+++ /dev/null
@@ -1,243 +0,0 @@
-#!/usr/bin/env ruby
-
-require File.dirname(__FILE__) + '/../../../spec_helper'
-
-require 'yaml'
-require 'puppet/indirector'
-
-describe Puppet::Indirector.terminus(:node, :ldap), " when searching for nodes" do
- require 'puppet/node'
-
- def setup
- Puppet.config[:external_nodes] = "/yay/ness"
- @searcher = Puppet::Indirector.terminus(:node, :ldap).new
- nodetable = {}
- @nodetable = nodetable
- # Override the ldapsearch definition, so we don't have to actually set it up.
- @searcher.meta_def(:ldapsearch) do |name|
- nodetable[name]
- end
- end
-
- it "should return nil for hosts that cannot be found" do
- @searcher.find("foo").should be_nil
- end
-
- it "should return Puppet::Node instances" do
- @nodetable["foo"] = [nil, %w{}, {}]
- @searcher.find("foo").should be_instance_of(Puppet::Node)
- end
-
- it "should set the node name" do
- @nodetable["foo"] = [nil, %w{}, {}]
- @searcher.find("foo").name.should == "foo"
- end
-
- it "should set the classes" do
- @nodetable["foo"] = [nil, %w{one two}, {}]
- @searcher.find("foo").classes.should == %w{one two}
- end
-
- it "should set the parameters" do
- @nodetable["foo"] = [nil, %w{}, {"one" => "two"}]
- @searcher.find("foo").parameters.should == {"one" => "two"}
- end
-
- it "should set classes and parameters from the parent node" do
- @nodetable["foo"] = ["middle", %w{one two}, {"one" => "two"}]
- @nodetable["middle"] = [nil, %w{three four}, {"three" => "four"}]
- node = @searcher.find("foo")
- node.classes.sort.should == %w{one two three four}.sort
- node.parameters.should == {"one" => "two", "three" => "four"}
- end
-
- it "should prefer child parameters to parent parameters" do
- @nodetable["foo"] = ["middle", %w{}, {"one" => "two"}]
- @nodetable["middle"] = [nil, %w{}, {"one" => "four"}]
- @searcher.find("foo").parameters["one"].should == "two"
- end
-
- it "should recurse indefinitely through parent relationships" do
- @nodetable["foo"] = ["middle", %w{one two}, {"one" => "two"}]
- @nodetable["middle"] = ["top", %w{three four}, {"three" => "four"}]
- @nodetable["top"] = [nil, %w{five six}, {"five" => "six"}]
- node = @searcher.find("foo")
- node.parameters.should == {"one" => "two", "three" => "four", "five" => "six"}
- node.classes.sort.should == %w{one two three four five six}.sort
- end
-
- # This can stay in the main test suite because it doesn't actually use ldapsearch,
- # it just overrides the method so it behaves as though it were hitting ldap.
- def test_ldap_nodesearch
-
- # Make sure we get nothing for nonexistent hosts
- node = nil
- assert_nothing_raised do
- node = searcher.nodesearch("nosuchhost")
- end
-
- assert_nil(node, "Got a node for a non-existent host")
-
- # Now add a base node with some classes and parameters
- nodetable["base"] = [nil, %w{one two}, {"base" => "true"}]
-
- assert_nothing_raised do
- node = searcher.nodesearch("base")
- end
-
- assert_instance_of(SimpleNode, node, "Did not get node from ldap nodesearch")
- assert_equal("base", node.name, "node name was not set")
-
- assert_equal(%w{one two}, node.classes, "node classes were not set")
- assert_equal({"base" => "true"}, node.parameters, "node parameters were not set")
-
- # Now use a different with this as the base
- nodetable["middle"] = ["base", %w{three}, {"center" => "boo"}]
- assert_nothing_raised do
- node = searcher.nodesearch("middle")
- end
-
- assert_instance_of(SimpleNode, node, "Did not get node from ldap nodesearch")
- assert_equal("middle", node.name, "node name was not set")
-
- assert_equal(%w{one two three}.sort, node.classes.sort, "node classes were not set correctly with a parent node")
- assert_equal({"base" => "true", "center" => "boo"}, node.parameters, "node parameters were not set correctly with a parent node")
-
- # And one further, to make sure we fully recurse
- nodetable["top"] = ["middle", %w{four five}, {"master" => "far"}]
- assert_nothing_raised do
- node = searcher.nodesearch("top")
- end
-
- assert_instance_of(SimpleNode, node, "Did not get node from ldap nodesearch")
- assert_equal("top", node.name, "node name was not set")
-
- assert_equal(%w{one two three four five}.sort, node.classes.sort, "node classes were not set correctly with the top node")
- assert_equal({"base" => "true", "center" => "boo", "master" => "far"}, node.parameters, "node parameters were not set correctly with the top node")
- end
-end
-
-describe Puppet::Indirector.terminus(:node, :ldap), " when interacting with ldap" do
- confine "LDAP is not available" => Puppet.features.ldap?
- confine "No LDAP test data for networks other than Luke's" => Facter.value(:domain) == "madstop.com"
-
- def ldapconnect
-
- @ldap = LDAP::Conn.new("ldap", 389)
- @ldap.set_option( LDAP::LDAP_OPT_PROTOCOL_VERSION, 3 )
- @ldap.simple_bind("", "")
-
- return @ldap
- end
-
- def ldaphost(name)
- node = Puppet::Node.new(name)
- parent = nil
- found = false
- @ldap.search( "ou=hosts, dc=madstop, dc=com", 2,
- "(&(objectclass=puppetclient)(cn=%s))" % name
- ) do |entry|
- node.classes = entry.vals("puppetclass") || []
- node.parameters = entry.to_hash.inject({}) do |hash, ary|
- if ary[1].length == 1
- hash[ary[0]] = ary[1].shift
- else
- hash[ary[0]] = ary[1]
- end
- hash
- end
- parent = node.parameters["parentnode"]
- found = true
- end
- raise "Could not find node %s" % name unless found
-
- return node, parent
- end
-
- it "should have tests" do
- raise ArgumentError
- end
-
- def test_ldapsearch
- Puppet[:ldapbase] = "ou=hosts, dc=madstop, dc=com"
- Puppet[:ldapnodes] = true
-
- searcher = Object.new
- searcher.extend(Node.node_source(:ldap))
-
- ldapconnect()
-
- # Make sure we get nil and nil back when we search for something missing
- parent, classes, parameters = nil
- assert_nothing_raised do
- parent, classes, parameters = searcher.ldapsearch("nosuchhost")
- end
-
- assert_nil(parent, "Got a parent for a non-existent host")
- assert_nil(classes, "Got classes for a non-existent host")
-
- # Make sure we can find 'culain' in ldap
- assert_nothing_raised do
- parent, classes, parameters = searcher.ldapsearch("culain")
- end
-
- node, realparent = ldaphost("culain")
- assert_equal(realparent, parent, "did not get correct parent node from ldap")
- assert_equal(node.classes, classes, "did not get correct ldap classes from ldap")
- assert_equal(node.parameters, parameters, "did not get correct ldap parameters from ldap")
-
- # Now compare when we specify the attributes to get.
- Puppet[:ldapattrs] = "cn"
- assert_nothing_raised do
- parent, classes, parameters = searcher.ldapsearch("culain")
- end
- assert_equal(realparent, parent, "did not get correct parent node from ldap")
- assert_equal(node.classes, classes, "did not get correct ldap classes from ldap")
-
- list = %w{cn puppetclass parentnode dn}
- should = node.parameters.inject({}) { |h, a| h[a[0]] = a[1] if list.include?(a[0]); h }
- assert_equal(should, parameters, "did not get correct ldap parameters from ldap")
- end
-end
-
-describe Puppet::Indirector.terminus(:node, :ldap), " when connecting to ldap" do
- confine "Not running on culain as root" => (Puppet::Util::SUIDManager.uid == 0 and Facter.value("hostname") == "culain")
-
- it "should have tests" do
- raise ArgumentError
- end
-
- def test_ldapreconnect
- Puppet[:ldapbase] = "ou=hosts, dc=madstop, dc=com"
- Puppet[:ldapnodes] = true
-
- searcher = Object.new
- searcher.extend(Node.node_source(:ldap))
- hostname = "culain.madstop.com"
-
- # look for our host
- assert_nothing_raised {
- parent, classes = searcher.nodesearch(hostname)
- }
-
- # Now restart ldap
- system("/etc/init.d/slapd restart 2>/dev/null >/dev/null")
- sleep(1)
-
- # and look again
- assert_nothing_raised {
- parent, classes = searcher.nodesearch(hostname)
- }
-
- # Now stop ldap
- system("/etc/init.d/slapd stop 2>/dev/null >/dev/null")
- cleanup do
- system("/etc/init.d/slapd start 2>/dev/null >/dev/null")
- end
-
- # And make sure we actually fail here
- assert_raise(Puppet::Error) {
- parent, classes = searcher.nodesearch(hostname)
- }
- end
-end
diff --git a/spec/unit/indirector/node/none.rb b/spec/unit/indirector/node/none.rb
deleted file mode 100755
index 2329cdfbb..000000000
--- a/spec/unit/indirector/node/none.rb
+++ /dev/null
@@ -1,32 +0,0 @@
-#!/usr/bin/env ruby
-
-require File.dirname(__FILE__) + '/../../../spec_helper'
-require 'puppet/indirector'
-require 'puppet/node/facts'
-
-describe Puppet::Indirector.terminus(:node, :none), " when searching for nodes" do
- before do
- Puppet.config[:node_source] = "none"
- @searcher = Puppet::Indirector.terminus(:node, :none).new
- end
-
- it "should create a node instance" do
- @searcher.find("yay").should be_instance_of(Puppet::Node)
- end
-
- it "should create a new node with the correct name" do
- @searcher.find("yay").name.should == "yay"
- end
-
- it "should merge the node's facts" do
- facts = Puppet::Node::Facts.new("yay", "one" => "two", "three" => "four")
- Puppet::Node::Facts.expects(:find).with("yay").returns(facts)
- node = @searcher.find("yay")
- node.parameters["one"].should == "two"
- node.parameters["three"].should == "four"
- end
-
- after do
- Puppet.config.clear
- end
-end