summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xext/puppetlast27
-rwxr-xr-xspec/unit/indirector/yaml.rb29
2 files changed, 29 insertions, 27 deletions
diff --git a/ext/puppetlast b/ext/puppetlast
index 848fdde6c..d9b698cfe 100755
--- a/ext/puppetlast
+++ b/ext/puppetlast
@@ -10,33 +10,6 @@ Puppet.parse_config
Puppet[:name] = "puppetmasterd"
Puppet::Node::Facts.terminus_class = :yaml
-print "puppetlast\n"
-
-nodes = {}
-
-yfdir = Puppet.settings.value(:vardir) + "/yaml/facts"
-
-if yfdir
- begin
- Dir.chdir(yfdir) do
- Dir.glob("*.yaml").each do |yaml|
- data = YAML.load_file(yaml)
- t = Time.now
- age = t - data.version
- nodes[data.name] = age.to_i
- end
- end
-
- nodes.sort.each do |node,age|
- minutes = age / 60 + 0.5
- print minutes.floor.to_s + ' minutes ago: ' + node + "\n"
- end
-
- rescue
- print 'error: ' + $! + "\n"
- end
-
Puppet::Node::Facts.search("*").sort.each do |node|
puts "#{node.name} #{node.expired? ? 'cached expired, ' : ''}checked in #{((Time.now - node.values[:_timestamp]) / 60).floor} minutes ago"
end
-
diff --git a/spec/unit/indirector/yaml.rb b/spec/unit/indirector/yaml.rb
index 3875d70aa..081ae9666 100755
--- a/spec/unit/indirector/yaml.rb
+++ b/spec/unit/indirector/yaml.rb
@@ -106,4 +106,33 @@ describe Puppet::Indirector::Yaml, " when choosing file location" do
proc { @store.find(@request) }.should raise_error(Puppet::Error)
end
end
+
+ describe Puppet::Indirector::Yaml, " when searching" do
+ it "should return an array of fact instances with one instance for each file when globbing *" do
+ @request = stub 'request', :key => "*", :instance => @subject
+ @one = mock 'one'
+ @two = mock 'two'
+ @store.expects(:base).returns "/my/yaml/dir"
+ Dir.expects(:glob).with(File.join("/my/yaml/dir", @store.class.indirection_name.to_s, @request.key)).returns(%w{one.yaml two.yaml})
+ YAML.expects(:load_file).with("one.yaml").returns @one;
+ YAML.expects(:load_file).with("two.yaml").returns @two;
+ @store.search(@request).should == [@one, @two]
+ end
+
+ it "should return an array containing a single instance of fact when globbing 'one*'" do
+ @request = stub 'request', :key => "one*", :instance => @subject
+ @one = mock 'one'
+ @store.expects(:base).returns "/my/yaml/dir"
+ Dir.expects(:glob).with(File.join("/my/yaml/dir", @store.class.indirection_name.to_s, @request.key)).returns(%w{one.yaml})
+ YAML.expects(:load_file).with("one.yaml").returns @one;
+ @store.search(@request).should == [@one]
+ end
+
+ it "should return an empty array when the glob doesn't match anything" do
+ @request = stub 'request', :key => "f*ilglobcanfail*", :instance => @subject
+ @store.expects(:base).returns "/my/yaml/dir"
+ Dir.expects(:glob).with(File.join("/my/yaml/dir", @store.class.indirection_name.to_s, @request.key)).returns([])
+ @store.search(@request).should == []
+ end
+ end
end