summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLuke Kanies <luke@madstop.com>2007-09-25 16:01:07 -0500
committerLuke Kanies <luke@madstop.com>2007-09-25 16:01:07 -0500
commitfa643e61c7451c2c46623d2c801a42c6c7640e1e (patch)
tree05128cedf0e7010c2c8b9c6f3ae4104e1332ad1c
parent938b91894d09ea804d2fc9eaac57b52f46de793a (diff)
downloadpuppet-fa643e61c7451c2c46623d2c801a42c6c7640e1e.tar.gz
puppet-fa643e61c7451c2c46623d2c801a42c6c7640e1e.tar.xz
puppet-fa643e61c7451c2c46623d2c801a42c6c7640e1e.zip
Adding more indirection termini, mostly focused on caching
information in yaml.
-rw-r--r--lib/puppet/indirector/code/facts.rb21
-rw-r--r--lib/puppet/indirector/yaml/configuration.rb5
-rw-r--r--lib/puppet/indirector/yaml/node.rb5
-rwxr-xr-xspec/unit/indirector/code/facts.rb70
-rwxr-xr-xspec/unit/indirector/yaml/configuration.rb25
-rwxr-xr-xspec/unit/indirector/yaml/node.rb25
6 files changed, 151 insertions, 0 deletions
diff --git a/lib/puppet/indirector/code/facts.rb b/lib/puppet/indirector/code/facts.rb
new file mode 100644
index 000000000..b64e9854e
--- /dev/null
+++ b/lib/puppet/indirector/code/facts.rb
@@ -0,0 +1,21 @@
+require 'puppet/node/facts'
+require 'puppet/indirector/code'
+
+class Puppet::Indirector::Code::Facts < Puppet::Indirector::Code
+ desc "Retrieve facts from Facter. This provides a somewhat abstract interface
+ between Puppet and Facter. It's only 'somewhat' abstract because it always
+ returns the local host's facts, regardless of what you attempt to find."
+
+ def destroy(facts)
+ raise Puppet::DevError, "You cannot destroy facts in the code store; it is only used for getting facts from Facter"
+ end
+
+ # Look a host's facts up in Facter.
+ def find(key)
+ Puppet::Node::Facts.new(key, Facter.to_hash)
+ end
+
+ def save(facts)
+ raise Puppet::DevError, "You cannot save facts to the code store; it is only used for getting facts from Facter"
+ end
+end
diff --git a/lib/puppet/indirector/yaml/configuration.rb b/lib/puppet/indirector/yaml/configuration.rb
new file mode 100644
index 000000000..691f0e343
--- /dev/null
+++ b/lib/puppet/indirector/yaml/configuration.rb
@@ -0,0 +1,5 @@
+require 'puppet/indirector/yaml'
+
+class Puppet::Indirector::Yaml::Configuration < Puppet::Indirector::Yaml
+ desc "Store configurations as flat files, serialized using YAML."
+end
diff --git a/lib/puppet/indirector/yaml/node.rb b/lib/puppet/indirector/yaml/node.rb
new file mode 100644
index 000000000..62fef58ac
--- /dev/null
+++ b/lib/puppet/indirector/yaml/node.rb
@@ -0,0 +1,5 @@
+require 'puppet/indirector/yaml'
+
+class Puppet::Indirector::Yaml::Node < Puppet::Indirector::Yaml
+ desc "Store node information as flat files, serialized using YAML."
+end
diff --git a/spec/unit/indirector/code/facts.rb b/spec/unit/indirector/code/facts.rb
new file mode 100755
index 000000000..9b645617f
--- /dev/null
+++ b/spec/unit/indirector/code/facts.rb
@@ -0,0 +1,70 @@
+#!/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/code/facts'
+
+describe Puppet::Indirector::Code::Facts do
+ it "should be a subclass of the Code terminus" do
+ Puppet::Indirector::Code::Facts.superclass.should equal(Puppet::Indirector::Code)
+ end
+
+ it "should have documentation" do
+ Puppet::Indirector::Code::Facts.doc.should_not be_nil
+ end
+
+ it "should be registered with the configuration store indirection" do
+ indirection = Puppet::Indirector::Indirection.instance(:facts)
+ Puppet::Indirector::Code::Facts.indirection.should equal(indirection)
+ end
+
+ it "should have its name set to :facts" do
+ Puppet::Indirector::Code::Facts.name.should == :facts
+ end
+end
+
+module TestingCodeFacts
+ def setup
+ @facter = Puppet::Indirector::Code::Facts.new
+ Facter.stubs(:to_hash).returns({})
+ @name = "me"
+ @facts = @facter.find(@name)
+ end
+end
+
+describe Puppet::Indirector::Code::Facts, " when finding facts" do
+ include TestingCodeFacts
+
+ it "should return a Facts instance" do
+ @facts.should be_instance_of(Puppet::Node::Facts)
+ end
+
+ it "should return a Facts instance with the provided key as the name" do
+ @facts.name.should == @name
+ end
+
+ it "should return the Facter facts as the values in the Facts instance" do
+ Facter.expects(:to_hash).returns("one" => "two")
+ facts = @facter.find(@name)
+ facts.values["one"].should == "two"
+ end
+end
+
+describe Puppet::Indirector::Code::Facts, " when saving facts" do
+ include TestingCodeFacts
+
+ it "should fail" do
+ proc { @facter.save(@facts) }.should raise_error(Puppet::DevError)
+ end
+end
+
+describe Puppet::Indirector::Code::Facts, " when destroying facts" do
+ include TestingCodeFacts
+
+ it "should fail" do
+ proc { @facter.destroy(@facts) }.should raise_error(Puppet::DevError)
+ end
+end
diff --git a/spec/unit/indirector/yaml/configuration.rb b/spec/unit/indirector/yaml/configuration.rb
new file mode 100755
index 000000000..3f0bc6f30
--- /dev/null
+++ b/spec/unit/indirector/yaml/configuration.rb
@@ -0,0 +1,25 @@
+#!/usr/bin/env ruby
+
+require File.dirname(__FILE__) + '/../../../spec_helper'
+
+require 'puppet/node/configuration'
+require 'puppet/indirector/yaml/configuration'
+
+describe Puppet::Indirector::Yaml::Configuration do
+ it "should be a subclass of the Yaml terminus" do
+ Puppet::Indirector::Yaml::Configuration.superclass.should equal(Puppet::Indirector::Yaml)
+ end
+
+ it "should have documentation" do
+ Puppet::Indirector::Yaml::Configuration.doc.should_not be_nil
+ end
+
+ it "should be registered with the configuration store indirection" do
+ indirection = Puppet::Indirector::Indirection.instance(:configuration)
+ Puppet::Indirector::Yaml::Configuration.indirection.should equal(indirection)
+ end
+
+ it "should have its name set to :configuration" do
+ Puppet::Indirector::Yaml::Configuration.name.should == :configuration
+ end
+end
diff --git a/spec/unit/indirector/yaml/node.rb b/spec/unit/indirector/yaml/node.rb
new file mode 100755
index 000000000..a14171b05
--- /dev/null
+++ b/spec/unit/indirector/yaml/node.rb
@@ -0,0 +1,25 @@
+#!/usr/bin/env ruby
+
+require File.dirname(__FILE__) + '/../../../spec_helper'
+
+require 'puppet/node'
+require 'puppet/indirector/yaml/node'
+
+describe Puppet::Indirector::Yaml::Node do
+ it "should be a subclass of the Yaml terminus" do
+ Puppet::Indirector::Yaml::Node.superclass.should equal(Puppet::Indirector::Yaml)
+ end
+
+ it "should have documentation" do
+ Puppet::Indirector::Yaml::Node.doc.should_not be_nil
+ end
+
+ it "should be registered with the configuration store indirection" do
+ indirection = Puppet::Indirector::Indirection.instance(:node)
+ Puppet::Indirector::Yaml::Node.indirection.should equal(indirection)
+ end
+
+ it "should have its name set to :node" do
+ Puppet::Indirector::Yaml::Node.name.should == :node
+ end
+end