This delegates facts looking up to the remote network device registered.
Signed-off-by: Brice Figureau <[email protected]>
---
lib/puppet/indirector/facts/network_device.rb | 25 ++++++
spec/unit/indirector/facts/network_device_spec.rb | 89 +++++++++++++++++++++
2 files changed, 114 insertions(+), 0 deletions(-)
create mode 100644 lib/puppet/indirector/facts/network_device.rb
create mode 100644 spec/unit/indirector/facts/network_device_spec.rb
diff --git a/lib/puppet/indirector/facts/network_device.rb
b/lib/puppet/indirector/facts/network_device.rb
new file mode 100644
index 0000000..c9bac80
--- /dev/null
+++ b/lib/puppet/indirector/facts/network_device.rb
@@ -0,0 +1,25 @@
+require 'puppet/node/facts'
+require 'puppet/indirector/code'
+
+class Puppet::Node::Facts::NetworkDevice < Puppet::Indirector::Code
+ desc "Retrieve facts from a network device."
+
+ # Look a device's facts up through the current device.
+ def find(request)
+ result = Puppet::Node::Facts.new(request.key,
Puppet::Util::NetworkDevice.current.facts)
+
+ result.add_local_facts
+ result.stringify
+ result.downcase_if_necessary
+
+ result
+ end
+
+ def destroy(facts)
+ raise Puppet::DevError, "You cannot destroy facts in the code store; it is
only used for getting facts from a remote device"
+ end
+
+ def save(facts)
+ raise Puppet::DevError, "You cannot save facts to the code store; it is
only used for getting facts from a remote device"
+ end
+end
\ No newline at end of file
diff --git a/spec/unit/indirector/facts/network_device_spec.rb
b/spec/unit/indirector/facts/network_device_spec.rb
new file mode 100644
index 0000000..302a810
--- /dev/null
+++ b/spec/unit/indirector/facts/network_device_spec.rb
@@ -0,0 +1,89 @@
+#!/usr/bin/env ruby
+#
+# Created by Luke Kanies on 2007-9-23.
+# Copyright (c) 2007. All rights reserved.
+
+require File.dirname(__FILE__) + '/../../../spec_helper'
+
+require 'puppet/indirector/facts/network_device'
+
+describe Puppet::Node::Facts::NetworkDevice do
+ it "should be a subclass of the Code terminus" do
+ Puppet::Node::Facts::NetworkDevice.superclass.should
equal(Puppet::Indirector::Code)
+ end
+
+ it "should have documentation" do
+ Puppet::Node::Facts::NetworkDevice.doc.should_not be_nil
+ end
+
+ it "should be registered with the configuration store indirection" do
+ indirection = Puppet::Indirector::Indirection.instance(:facts)
+ Puppet::Node::Facts::NetworkDevice.indirection.should equal(indirection)
+ end
+
+ it "should have its name set to :facter" do
+ Puppet::Node::Facts::NetworkDevice.name.should == :network_device
+ end
+end
+
+describe Puppet::Node::Facts::NetworkDevice do
+ before :each do
+ @remote_device = stub 'remote_device', :facts => {}
+ Puppet::Util::NetworkDevice.stubs(:current).returns(@remote_device)
+ @device = Puppet::Node::Facts::NetworkDevice.new
+ @name = "me"
+ @request = stub 'request', :key => @name
+ end
+
+ describe Puppet::Node::Facts::NetworkDevice, " when finding facts" do
+ it "should return a Facts instance" do
+ @device.find(@request).should be_instance_of(Puppet::Node::Facts)
+ end
+
+ it "should return a Facts instance with the provided key as the name" do
+ @device.find(@request).name.should == @name
+ end
+
+ it "should return the device facts as the values in the Facts instance" do
+ @remote_device.expects(:facts).returns("one" => "two")
+ facts = @device.find(@request)
+ facts.values["one"].should == "two"
+ end
+
+ it "should add local facts" do
+ facts = Puppet::Node::Facts.new("foo")
+ Puppet::Node::Facts.expects(:new).returns facts
+ facts.expects(:add_local_facts)
+
+ @device.find(@request)
+ end
+
+ it "should convert all facts into strings" do
+ facts = Puppet::Node::Facts.new("foo")
+ Puppet::Node::Facts.expects(:new).returns facts
+ facts.expects(:stringify)
+
+ @device.find(@request)
+ end
+
+ it "should call the downcase hook" do
+ facts = Puppet::Node::Facts.new("foo")
+ Puppet::Node::Facts.expects(:new).returns facts
+ facts.expects(:downcase_if_necessary)
+
+ @device.find(@request)
+ end
+ end
+
+ describe Puppet::Node::Facts::NetworkDevice, " when saving facts" do
+ it "should fail" do
+ proc { @device.save(@facts) }.should raise_error(Puppet::DevError)
+ end
+ end
+
+ describe Puppet::Node::Facts::NetworkDevice, " when destroying facts" do
+ it "should fail" do
+ proc { @device.destroy(@facts) }.should raise_error(Puppet::DevError)
+ end
+ end
+end
--
1.7.2.1
--
You received this message because you are subscribed to the Google Groups
"Puppet Developers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/puppet-dev?hl=en.