From d6fd60cca15641fc1341cce52faf0506d7665044 Mon Sep 17 00:00:00 2001 From: Luke Kanies Date: Mon, 24 Sep 2007 14:45:54 -0500 Subject: Removing obsolete fact stores and node sources. The functionality has been moved into the indirector. --- lib/puppet/fact_stores/yaml.rb | 40 ----------- lib/puppet/node_source/external.rb | 51 -------------- lib/puppet/node_source/ldap.rb | 138 ------------------------------------- lib/puppet/node_source/none.rb | 10 --- 4 files changed, 239 deletions(-) delete mode 100644 lib/puppet/fact_stores/yaml.rb delete mode 100644 lib/puppet/node_source/external.rb delete mode 100644 lib/puppet/node_source/ldap.rb delete mode 100644 lib/puppet/node_source/none.rb diff --git a/lib/puppet/fact_stores/yaml.rb b/lib/puppet/fact_stores/yaml.rb deleted file mode 100644 index b33e162ba..000000000 --- a/lib/puppet/fact_stores/yaml.rb +++ /dev/null @@ -1,40 +0,0 @@ -Puppet::Util::FactStore.newstore(:yaml) do - desc "Store client facts as flat files, serialized using YAML." - - # Get a client's facts. - def get(node) - file = path(node) - - return nil unless FileTest.exists?(file) - - begin - facts = YAML::load(File.read(file)) - rescue => detail - Puppet.err "Could not load facts for %s: %s" % [node, detail] - end - facts - end - - def initialize - Puppet.settings.use(:yamlfacts) - end - - # Store the facts to disk. - def set(node, facts) - File.open(path(node), "w", 0600) do |f| - begin - f.print YAML::dump(facts) - rescue => detail - Puppet.err "Could not write facts for %s: %s" % [node, detail] - end - end - nil - end - - private - - # Return the path to a given node's file. - def path(node) - File.join(Puppet[:yamlfactdir], node + ".yaml") - end -end diff --git a/lib/puppet/node_source/external.rb b/lib/puppet/node_source/external.rb deleted file mode 100644 index 54111d924..000000000 --- a/lib/puppet/node_source/external.rb +++ /dev/null @@ -1,51 +0,0 @@ -Puppet::Network::Handler::Node.newnode_source(:external, :fact_merge => true) do - desc "Call an external program to get node information." - - include Puppet::Util - # Look for external node definitions. - def nodesearch(name) - return nil unless Puppet[:external_nodes] != "none" - - # This is a very cheap way to do this, since it will break on - # commands that have spaces in the arguments. But it's good - # enough for most cases. - external_node_command = Puppet[:external_nodes].split - external_node_command << name - begin - output = Puppet::Util.execute(external_node_command) - rescue Puppet::ExecutionFailure => detail - if $?.exitstatus == 1 - return nil - else - Puppet.err "Could not retrieve external node information for %s: %s" % [name, detail] - end - return nil - end - - if output =~ /\A\s*\Z/ # all whitespace - Puppet.debug "Empty response for %s from external node source" % name - return nil - end - - begin - result = YAML.load(output).inject({}) { |hash, data| hash[symbolize(data[0])] = data[1]; hash } - rescue => detail - raise Puppet::Error, "Could not load external node results for %s: %s" % [name, detail] - end - - node = newnode(name) - set = false - [:parameters, :classes].each do |param| - if value = result[param] - node.send(param.to_s + "=", value) - set = true - end - end - - if set - return node - else - return nil - end - end -end diff --git a/lib/puppet/node_source/ldap.rb b/lib/puppet/node_source/ldap.rb deleted file mode 100644 index 7b60a3c62..000000000 --- a/lib/puppet/node_source/ldap.rb +++ /dev/null @@ -1,138 +0,0 @@ -Puppet::Network::Handler::Node.newnode_source(:ldap, :fact_merge => true) do - desc "Search in LDAP for node configuration information." - - # Find the ldap node, return the class list and parent node specially, - # and everything else in a parameter hash. - def ldapsearch(node) - filter = Puppet[:ldapstring] - classattrs = Puppet[:ldapclassattrs].split("\s*,\s*") - if Puppet[:ldapattrs] == "all" - # A nil value here causes all attributes to be returned. - search_attrs = nil - else - search_attrs = classattrs + Puppet[:ldapattrs].split("\s*,\s*") - end - pattr = nil - if pattr = Puppet[:ldapparentattr] - if pattr == "" - pattr = nil - else - search_attrs << pattr unless search_attrs.nil? - end - end - - if filter =~ /%s/ - filter = filter.gsub(/%s/, node) - end - - parent = nil - classes = [] - parameters = nil - - found = false - count = 0 - - begin - # We're always doing a sub here; oh well. - ldap.search(Puppet[:ldapbase], 2, filter, search_attrs) do |entry| - found = true - if pattr - if values = entry.vals(pattr) - if values.length > 1 - raise Puppet::Error, - "Node %s has more than one parent: %s" % - [node, values.inspect] - end - unless values.empty? - parent = values.shift - end - end - end - - classattrs.each { |attr| - if values = entry.vals(attr) - values.each do |v| classes << v end - end - } - - 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 - end - rescue => detail - if count == 0 - # Try reconnecting to ldap - @ldap = nil - retry - else - raise Puppet::Error, "LDAP Search failed: %s" % detail - end - end - - classes.flatten! - - if classes.empty? - classes = nil - end - - if parent or classes or parameters - return parent, classes, parameters - else - return nil - end - end - - # Look for our node in ldap. - def nodesearch(node) - unless ary = ldapsearch(node) - return nil - end - parent, classes, parameters = ary - - while parent - parent, tmpclasses, tmpparams = ldapsearch(parent) - classes += tmpclasses if tmpclasses - tmpparams.each do |param, value| - # Specifically test for whether it's set, so false values are handled - # correctly. - parameters[param] = value unless parameters.include?(param) - end - end - - return newnode(node, :classes => classes, :source => "ldap", :parameters => parameters) - end - - private - - # Create an ldap connection. - def ldap - unless defined? @ldap and @ldap - unless Puppet.features.ldap? - raise Puppet::Error, "Could not set up LDAP Connection: Missing ruby/ldap libraries" - end - begin - if Puppet[:ldapssl] - @ldap = LDAP::SSLConn.new(Puppet[:ldapserver], Puppet[:ldapport]) - elsif Puppet[:ldaptls] - @ldap = LDAP::SSLConn.new( - Puppet[:ldapserver], Puppet[:ldapport], true - ) - else - @ldap = LDAP::Conn.new(Puppet[:ldapserver], Puppet[:ldapport]) - end - @ldap.set_option(LDAP::LDAP_OPT_PROTOCOL_VERSION, 3) - @ldap.set_option(LDAP::LDAP_OPT_REFERRALS, LDAP::LDAP_OPT_ON) - @ldap.simple_bind(Puppet[:ldapuser], Puppet[:ldappassword]) - rescue => detail - raise Puppet::Error, "Could not connect to LDAP: %s" % detail - end - end - - return @ldap - end -end diff --git a/lib/puppet/node_source/none.rb b/lib/puppet/node_source/none.rb deleted file mode 100644 index ce188add5..000000000 --- a/lib/puppet/node_source/none.rb +++ /dev/null @@ -1,10 +0,0 @@ -Puppet::Network::Handler::Node.newnode_source(:none, :fact_merge => true) do - desc "Always return an empty node object. This is the node source you should - use when you don't have some other, functional source you want to use, - as the compiler will not work without this node information." - - # Just return an empty node. - def nodesearch(name) - newnode(name) - end -end -- cgit From 2e3306143b1f58765f48911ba433a119de323b84 Mon Sep 17 00:00:00 2001 From: Luke Kanies Date: Mon, 24 Sep 2007 15:58:44 -0500 Subject: I changed the Terminus class to switch camelcase to underscore-separated words, e.g., FactStore becomes fact_store. --- lib/puppet/indirector/terminus.rb | 6 ++++-- spec/unit/indirector/terminus.rb | 30 +++++++++++++++++++++--------- spec/unit/indirector/yaml.rb | 6 +++--- 3 files changed, 28 insertions(+), 14 deletions(-) diff --git a/lib/puppet/indirector/terminus.rb b/lib/puppet/indirector/terminus.rb index bcff08d79..3e0ea447c 100644 --- a/lib/puppet/indirector/terminus.rb +++ b/lib/puppet/indirector/terminus.rb @@ -26,7 +26,7 @@ class Puppet::Indirector::Terminus elsif ind = Puppet::Indirector::Indirection.instance(name) @indirection = ind else - raise ArgumentError, "Could not find indirection instance %s" % name + raise ArgumentError, "Could not find indirection instance %s for %s" % [name, self.name] end end @@ -39,7 +39,9 @@ class Puppet::Indirector::Terminus raise ArgumentError, "Terminus subclasses must have associated constants" end names = longname.split("::") - name = names.pop.downcase.intern + + # Convert everything to a lower-case symbol, converting camelcase to underscore word separation. + name = names.pop.sub(/^[A-Z]/) { |i| i.downcase }.gsub(/[A-Z]/) { |i| "_" + i.downcase }.intern subclass.name = name diff --git a/spec/unit/indirector/terminus.rb b/spec/unit/indirector/terminus.rb index dc86cf315..44180cf4b 100755 --- a/spec/unit/indirector/terminus.rb +++ b/spec/unit/indirector/terminus.rb @@ -6,8 +6,8 @@ describe Puppet::Indirector::Terminus do before do Puppet::Indirector::Terminus.stubs(:register_terminus_class) - @indirection = stub 'indirection', :name => :mystuff, :register_terminus_type => nil - Puppet::Indirector::Indirection.stubs(:instance).with(:mystuff).returns(@indirection) + @indirection = stub 'indirection', :name => :my_stuff, :register_terminus_type => nil + Puppet::Indirector::Indirection.stubs(:instance).with(:my_stuff).returns(@indirection) @abstract_terminus = Class.new(Puppet::Indirector::Terminus) do def self.to_s "Abstract" @@ -91,7 +91,7 @@ describe Puppet::Indirector::Terminus, " when managing terminus classes" do end it "should fail when no indirection can be found" do - Puppet::Indirector::Indirection.expects(:instance).with(:myindirection).returns(nil) + Puppet::Indirector::Indirection.expects(:instance).with(:my_indirection).returns(nil) @abstract_terminus = Class.new(Puppet::Indirector::Terminus) do def self.to_s @@ -109,10 +109,10 @@ describe Puppet::Indirector::Terminus, " when managing terminus classes" do it "should register the terminus class with the terminus base class" do Puppet::Indirector::Terminus.expects(:register_terminus_class).with do |type| - type.terminus_type == :abstract and type.name == :myindirection + type.terminus_type == :abstract and type.name == :my_indirection end @indirection = stub 'indirection', :name => :myind, :register_terminus_type => nil - Puppet::Indirector::Indirection.expects(:instance).with(:myindirection).returns(@indirection) + Puppet::Indirector::Indirection.expects(:instance).with(:my_indirection).returns(@indirection) @abstract_terminus = Class.new(Puppet::Indirector::Terminus) do def self.to_s @@ -128,6 +128,18 @@ describe Puppet::Indirector::Terminus, " when managing terminus classes" do end end +describe Puppet::Indirector::Terminus, " when converting class constants to indirection names" do + it "should convert camel case to lower case with underscores as word separators" do + subclass = mock 'subclass' + subclass.stubs(:to_s).returns("OneTwo") + subclass.stubs(:mark_as_abstract_terminus) + + subclass.expects(:name=).with(:one_two) + + Puppet::Indirector::Terminus.inherited(subclass) + end +end + describe Puppet::Indirector::Terminus, " when creating terminus class types" do before do Puppet::Indirector::Terminus.stubs(:register_terminus_class) @@ -139,7 +151,7 @@ describe Puppet::Indirector::Terminus, " when creating terminus class types" do end it "should set the name of the abstract subclass to be its class constant" do - @subclass.name.should equal(:mytermtype) + @subclass.name.should equal(:my_term_type) end it "should mark abstract terminus types as such" do @@ -156,7 +168,7 @@ describe Puppet::Indirector::Terminus, " when creating terminus classes" do Puppet::Indirector::Terminus.stubs(:register_terminus_class) @indirection = stub 'indirection', :name => :myind, :register_terminus_type => nil - Puppet::Indirector::Indirection.expects(:instance).with(:myindirection).returns(@indirection) + Puppet::Indirector::Indirection.expects(:instance).with(:my_indirection).returns(@indirection) @abstract_terminus = Class.new(Puppet::Indirector::Terminus) do def self.to_s @@ -179,7 +191,7 @@ describe Puppet::Indirector::Terminus, " when creating terminus classes" do end it "should set the subclass's name to the indirection name" do - @terminus.name.should == :myindirection + @terminus.name.should == :my_indirection end it "should set the subclass's model to the indirection model" do @@ -192,7 +204,7 @@ describe Puppet::Indirector::Terminus, " when a terminus instance" do before do Puppet::Indirector::Terminus.stubs(:register_terminus_class) @indirection = stub 'indirection', :name => :myyaml, :register_terminus_type => nil - Puppet::Indirector::Indirection.stubs(:instance).with(:mystuff).returns(@indirection) + Puppet::Indirector::Indirection.stubs(:instance).with(:my_stuff).returns(@indirection) @abstract_terminus = Class.new(Puppet::Indirector::Terminus) do def self.to_s "Abstract" diff --git a/spec/unit/indirector/yaml.rb b/spec/unit/indirector/yaml.rb index 9e1d65e49..453b703a1 100755 --- a/spec/unit/indirector/yaml.rb +++ b/spec/unit/indirector/yaml.rb @@ -6,8 +6,8 @@ require 'puppet/indirector/yaml' module YamlTesting def setup - @indirection = stub 'indirection', :name => :myyaml, :register_terminus_type => nil - Puppet::Indirector::Indirection.stubs(:instance).with(:myyaml).returns(@indirection) + @indirection = stub 'indirection', :name => :my_yaml, :register_terminus_type => nil + Puppet::Indirector::Indirection.stubs(:instance).with(:my_yaml).returns(@indirection) @store_class = Class.new(Puppet::Indirector::Yaml) do def self.to_s "MyYaml" @@ -33,7 +33,7 @@ describe Puppet::Indirector::Yaml, " when choosing file location" do end it "should use the terminus name for choosing the subdirectory" do - @store.send(:path, :me).should =~ %r{^#{@dir}/myyaml} + @store.send(:path, :me).should =~ %r{^#{@dir}/my_yaml} end it "should use the object's name to determine the file name" do -- cgit From 938b91894d09ea804d2fc9eaac57b52f46de793a Mon Sep 17 00:00:00 2001 From: Luke Kanies Date: Tue, 25 Sep 2007 15:52:26 -0500 Subject: Adding cache support to indirection. If you have a '_cache' setting, then the indirection will use the value there as the name of the cache. --- lib/puppet/indirector/indirection.rb | 32 +++++++- spec/unit/indirector/indirection.rb | 145 +++++++++++++++++++++++++++++------ 2 files changed, 153 insertions(+), 24 deletions(-) diff --git a/lib/puppet/indirector/indirection.rb b/lib/puppet/indirector/indirection.rb index 8afe0012d..9cc116e40 100644 --- a/lib/puppet/indirector/indirection.rb +++ b/lib/puppet/indirector/indirection.rb @@ -15,9 +15,36 @@ class Puppet::Indirector::Indirection attr_accessor :name, :model - # Clear our cached list of termini. + # Create and return our cache terminus. + def cache + terminus(cache_name) + end + + # Should we use a cache? + def cache? + cache_name ? true : false + end + + # Figure out the cache name, if there is one. If there's no name, then + # caching is disabled. + def cache_name + unless @cache_name + setting_name = "%s_cache" % self.name + if ! Puppet.settings.valid?(setting_name) or (value = Puppet.settings[setting_name] and value == "none") + @cache_name = nil + else + @cache_name = value + @cache_name = @cache_name.intern if @cache_name.is_a?(String) + end + end + @cache_name + end + + # Clear our cached list of termini, and reset the cache name + # so it's looked up again. # This is only used for testing. def clear_cache + @cache_name = nil @termini.clear end @@ -38,6 +65,7 @@ class Puppet::Indirector::Indirection end @termini = {} @terminus_types = {} + @cache_name = nil raise(ArgumentError, "Indirection %s is already defined" % @name) if @@indirections.find { |i| i.name == @name } @@indirections << self end @@ -66,6 +94,7 @@ class Puppet::Indirector::Indirection end def destroy(*args) + cache.destroy(*args) if cache? terminus.destroy(*args) end @@ -75,6 +104,7 @@ class Puppet::Indirector::Indirection # these become instance methods def save(*args) + cache.save(*args) if cache? terminus.save(*args) end diff --git a/spec/unit/indirector/indirection.rb b/spec/unit/indirector/indirection.rb index 326b6b470..41f50522f 100755 --- a/spec/unit/indirector/indirection.rb +++ b/spec/unit/indirector/indirection.rb @@ -4,6 +4,39 @@ require File.dirname(__FILE__) + '/../../spec_helper' require 'puppet/indirector' +describe Puppet::Indirector::Indirection do + before do + @indirection = Puppet::Indirector::Indirection.new(mock('model'), :test) + @terminus = mock 'terminus' + @indirection.stubs(:terminus).returns(@terminus) + end + + it "should handle lookups of a model instance by letting the appropriate terminus perform the lookup" do + @terminus.expects(:find).with(:mything).returns(:whev) + @indirection.find(:mything).should == :whev + end + + it "should handle removing model instances from a terminus letting the appropriate terminus remove the instance" do + @terminus.expects(:destroy).with(:mything).returns(:whev) + @indirection.destroy(:mything).should == :whev + end + + it "should handle searching for model instances by letting the appropriate terminus find the matching instances" do + @terminus.expects(:search).with(:mything).returns(:whev) + @indirection.search(:mything).should == :whev + end + + it "should handle storing a model instance by letting the appropriate terminus store the instance" do + @terminus.expects(:save).with(:mything).returns(:whev) + @indirection.save(:mything).should == :whev + end + + after do + @indirection.delete + Puppet::Indirector::Indirection.clear_cache + end +end + describe Puppet::Indirector::Indirection, " when initializing" do it "should keep a reference to the indirecting model" do model = mock 'model' @@ -126,32 +159,98 @@ describe Puppet::Indirector::Indirection, " when managing terminus instances" do end end -describe Puppet::Indirector::Indirection do - before do +describe Puppet::Indirector::Indirection, " when deciding whether to cache" do + before do @indirection = Puppet::Indirector::Indirection.new(mock('model'), :test) @terminus = mock 'terminus' @indirection.stubs(:terminus).returns(@terminus) - end - - it "should handle lookups of a model instance by letting the appropriate terminus perform the lookup" do - @terminus.expects(:find).with(:mything).returns(:whev) - @indirection.find(:mything).should == :whev - end - - it "should handle removing model instances from a terminus letting the appropriate terminus remove the instance" do - @terminus.expects(:destroy).with(:mything).returns(:whev) - @indirection.destroy(:mything).should == :whev - end - - it "should handle searching for model instances by letting the appropriate terminus find the matching instances" do - @terminus.expects(:search).with(:mything).returns(:whev) - @indirection.search(:mything).should == :whev - end - - it "should handle storing a model instance by letting the appropriate terminus store the instance" do - @terminus.expects(:save).with(:mything).returns(:whev) - @indirection.save(:mything).should == :whev - end + end + + it "should not use a cache if there no cache setting" do + Puppet.settings.expects(:valid?).with("test_cache").returns(false) + @indirection.expects(:cache).never + @terminus.stubs(:save) + @indirection.save(:whev) + end + + it "should not use a cache if the cache setting is set to 'none'" do + Puppet.settings.expects(:valid?).with("test_cache").returns(true) + Puppet.settings.expects(:value).with("test_cache").returns("none") + @indirection.expects(:cache).never + @terminus.stubs(:save) + @indirection.save(:whev) + end + + it "should use a cache if there is a related cache setting and it is not set to 'none'" do + Puppet.settings.expects(:valid?).with("test_cache").returns(true) + Puppet.settings.expects(:value).with("test_cache").returns("something") + cache = mock 'cache' + cache.expects(:save).with(:whev) + @indirection.expects(:cache).returns(cache) + @terminus.stubs(:save) + @indirection.save(:whev) + end + + after do + @indirection.delete + Puppet::Indirector::Indirection.clear_cache + end +end + +describe Puppet::Indirector::Indirection, " when using a cache" do + before do + Puppet.settings.stubs(:valid?).returns(true) + Puppet.settings.stubs(:value).with("test_terminus").returns("test_terminus") + @terminus_class = mock 'terminus_class' + @terminus = mock 'terminus' + @terminus_class.stubs(:new).returns(@terminus) + @cache = mock 'cache' + @cache_class = mock 'cache_class' + Puppet::Indirector::Terminus.stubs(:terminus_class).with(:cache_terminus, :test).returns(@cache_class) + Puppet::Indirector::Terminus.stubs(:terminus_class).with(:test_terminus, :test).returns(@terminus_class) + @indirection = Puppet::Indirector::Indirection.new(mock('model'), :test) + end + + it "should copy all writing indirection calls to the cache terminus" do + @cache_class.expects(:new).returns(@cache) + Puppet.settings.stubs(:value).with("test_cache").returns("cache_terminus") + @cache.expects(:save).with(:whev) + @terminus.stubs(:save) + @indirection.save(:whev) + end + + it "should not create a cache terminus at initialization" do + # This is weird, because all of the code is in the setup. If we got + # new() called on the cache class, we'd get an exception here. + end + + it "should reuse the cache terminus" do + @cache_class.expects(:new).returns(@cache) + Puppet.settings.stubs(:value).with("test_cache").returns("cache_terminus") + @indirection.cache.should equal(@cache) + @indirection.cache.should equal(@cache) + end + + it "should remove the cache terminus when all other terminus instances are cleared" do + cache2 = mock 'cache2' + @cache_class.stubs(:new).returns(@cache, cache2) + Puppet.settings.stubs(:value).with("test_cache").returns("cache_terminus") + @indirection.cache.should equal(@cache) + @indirection.clear_cache + @indirection.cache.should equal(cache2) + end + + it "should look up the cache name when recreating the cache terminus after terminus instances have been cleared" do + cache_class2 = mock 'cache_class2' + cache2 = mock 'cache2' + cache_class2.expects(:new).returns(cache2) + @cache_class.expects(:new).returns(@cache) + Puppet::Indirector::Terminus.stubs(:terminus_class).with(:other_cache, :test).returns(cache_class2) + Puppet.settings.stubs(:value).with("test_cache").returns("cache_terminus", "other_cache") + @indirection.cache.should equal(@cache) + @indirection.clear_cache + @indirection.cache.should equal(cache2) + end after do @indirection.delete -- cgit From fa643e61c7451c2c46623d2c801a42c6c7640e1e Mon Sep 17 00:00:00 2001 From: Luke Kanies Date: Tue, 25 Sep 2007 16:01:07 -0500 Subject: Adding more indirection termini, mostly focused on caching information in yaml. --- lib/puppet/indirector/code/facts.rb | 21 +++++++++ lib/puppet/indirector/yaml/configuration.rb | 5 +++ lib/puppet/indirector/yaml/node.rb | 5 +++ spec/unit/indirector/code/facts.rb | 70 +++++++++++++++++++++++++++++ spec/unit/indirector/yaml/configuration.rb | 25 +++++++++++ spec/unit/indirector/yaml/node.rb | 25 +++++++++++ 6 files changed, 151 insertions(+) create mode 100644 lib/puppet/indirector/code/facts.rb create mode 100644 lib/puppet/indirector/yaml/configuration.rb create mode 100644 lib/puppet/indirector/yaml/node.rb create mode 100755 spec/unit/indirector/code/facts.rb create mode 100755 spec/unit/indirector/yaml/configuration.rb create mode 100755 spec/unit/indirector/yaml/node.rb 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 -- cgit