It is now possible to specify queries in the form “meta.timestamp.xx”
where xx is eq,ne,gt,lt,ge,le when searching the inventory service.

Signed-off-by: Paul Berry <[email protected]>
---
 lib/puppet/indirector/inventory/yaml.rb     |   22 ++++++
 spec/unit/indirector/inventory/yaml_spec.rb |  103 +++++++++++++++++++++++++++
 2 files changed, 125 insertions(+), 0 deletions(-)

diff --git a/lib/puppet/indirector/inventory/yaml.rb 
b/lib/puppet/indirector/inventory/yaml.rb
index 5acbef6..fe3489a 100644
--- a/lib/puppet/indirector/inventory/yaml.rb
+++ b/lib/puppet/indirector/inventory/yaml.rb
@@ -33,6 +33,11 @@ class Puppet::Node::Inventory::Yaml < 
Puppet::Indirector::Yaml
 
   def node_matches_option?(type, name, operator, value, facts)
     case type
+    when "meta"
+      case name
+      when "timestamp"
+        compare_timestamp(operator, facts.timestamp, Time.parse(value))
+      end
     when "facts"
       compare_facts(operator, facts.values[name], value)
     end
@@ -56,4 +61,21 @@ class Puppet::Node::Inventory::Yaml < 
Puppet::Indirector::Yaml
       value1.to_s != value2.to_s
     end
   end
+
+  def compare_timestamp(operator, value1, value2)
+    case operator
+    when "eq"
+      value1 == value2
+    when "le"
+      value1 <= value2
+    when "ge"
+      value1 >= value2
+    when "lt"
+      value1 < value2
+    when "gt"
+      value1 > value2
+    when "ne"
+      value1 != value2
+    end
+  end
 end
diff --git a/spec/unit/indirector/inventory/yaml_spec.rb 
b/spec/unit/indirector/inventory/yaml_spec.rb
index a595f8a..9f0c543 100644
--- a/spec/unit/indirector/inventory/yaml_spec.rb
+++ b/spec/unit/indirector/inventory/yaml_spec.rb
@@ -115,4 +115,107 @@ describe Puppet::Node::Inventory::Yaml do
       {'facts.architecture.ne' => 'i386'}
     )
   end
+
+  def apply_timestamp(facts, timestamp)
+    facts.timestamp = timestamp
+    facts
+  end
+
+  it "should be able to query based on meta.timestamp.gt" do
+    assert_search_matches({
+        '/path/to/2010-11-01.yaml' => 
apply_timestamp(Puppet::Node::Facts.new("2010-11-01", {}), 
Time.parse("2010-11-01")),
+        '/path/to/2010-11-10.yaml' => 
apply_timestamp(Puppet::Node::Facts.new("2010-11-10", {}), 
Time.parse("2010-11-10")),
+      },
+      {
+        '/path/to/2010-10-01.yaml' => 
apply_timestamp(Puppet::Node::Facts.new("2010-10-01", {}), 
Time.parse("2010-10-01")),
+        '/path/to/2010-10-10.yaml' => 
apply_timestamp(Puppet::Node::Facts.new("2010-10-10", {}), 
Time.parse("2010-10-10")),
+        '/path/to/2010-10-15.yaml' => 
apply_timestamp(Puppet::Node::Facts.new("2010-10-15", {}), 
Time.parse("2010-10-15")),
+      },
+      {'meta.timestamp.gt' => '2010-10-15'}
+    )
+  end
+
+  it "should be able to query based on meta.timestamp.le" do
+    assert_search_matches({
+        '/path/to/2010-10-01.yaml' => 
apply_timestamp(Puppet::Node::Facts.new("2010-10-01", {}), 
Time.parse("2010-10-01")),
+        '/path/to/2010-10-10.yaml' => 
apply_timestamp(Puppet::Node::Facts.new("2010-10-10", {}), 
Time.parse("2010-10-10")),
+        '/path/to/2010-10-15.yaml' => 
apply_timestamp(Puppet::Node::Facts.new("2010-10-15", {}), 
Time.parse("2010-10-15")),
+      },
+      {
+        '/path/to/2010-11-01.yaml' => 
apply_timestamp(Puppet::Node::Facts.new("2010-11-01", {}), 
Time.parse("2010-11-01")),
+        '/path/to/2010-11-10.yaml' => 
apply_timestamp(Puppet::Node::Facts.new("2010-11-10", {}), 
Time.parse("2010-11-10")),
+      },
+      {'meta.timestamp.le' => '2010-10-15'}
+    )
+  end
+
+  it "should be able to query based on meta.timestamp.lt" do
+    assert_search_matches({
+        '/path/to/2010-10-01.yaml' => 
apply_timestamp(Puppet::Node::Facts.new("2010-10-01", {}), 
Time.parse("2010-10-01")),
+        '/path/to/2010-10-10.yaml' => 
apply_timestamp(Puppet::Node::Facts.new("2010-10-10", {}), 
Time.parse("2010-10-10")),
+      },
+      {
+        '/path/to/2010-11-01.yaml' => 
apply_timestamp(Puppet::Node::Facts.new("2010-11-01", {}), 
Time.parse("2010-11-01")),
+        '/path/to/2010-11-10.yaml' => 
apply_timestamp(Puppet::Node::Facts.new("2010-11-10", {}), 
Time.parse("2010-11-10")),
+        '/path/to/2010-10-15.yaml' => 
apply_timestamp(Puppet::Node::Facts.new("2010-10-15", {}), 
Time.parse("2010-10-15")),
+      },
+      {'meta.timestamp.lt' => '2010-10-15'}
+    )
+  end
+
+  it "should be able to query based on meta.timestamp.ge" do
+    assert_search_matches({
+        '/path/to/2010-11-01.yaml' => 
apply_timestamp(Puppet::Node::Facts.new("2010-11-01", {}), 
Time.parse("2010-11-01")),
+        '/path/to/2010-11-10.yaml' => 
apply_timestamp(Puppet::Node::Facts.new("2010-11-10", {}), 
Time.parse("2010-11-10")),
+        '/path/to/2010-10-15.yaml' => 
apply_timestamp(Puppet::Node::Facts.new("2010-10-15", {}), 
Time.parse("2010-10-15")),
+      },
+      {
+        '/path/to/2010-10-01.yaml' => 
apply_timestamp(Puppet::Node::Facts.new("2010-10-01", {}), 
Time.parse("2010-10-01")),
+        '/path/to/2010-10-10.yaml' => 
apply_timestamp(Puppet::Node::Facts.new("2010-10-10", {}), 
Time.parse("2010-10-10")),
+      },
+      {'meta.timestamp.ge' => '2010-10-15'}
+    )
+  end
+
+  it "should be able to query based on meta.timestamp.eq" do
+    assert_search_matches({
+        '/path/to/2010-10-15.yaml' => 
apply_timestamp(Puppet::Node::Facts.new("2010-10-15", {}), 
Time.parse("2010-10-15")),
+      },
+      {
+        '/path/to/2010-11-01.yaml' => 
apply_timestamp(Puppet::Node::Facts.new("2010-11-01", {}), 
Time.parse("2010-11-01")),
+        '/path/to/2010-11-10.yaml' => 
apply_timestamp(Puppet::Node::Facts.new("2010-11-10", {}), 
Time.parse("2010-11-10")),
+        '/path/to/2010-10-01.yaml' => 
apply_timestamp(Puppet::Node::Facts.new("2010-10-01", {}), 
Time.parse("2010-10-01")),
+        '/path/to/2010-10-10.yaml' => 
apply_timestamp(Puppet::Node::Facts.new("2010-10-10", {}), 
Time.parse("2010-10-10")),
+      },
+      {'meta.timestamp.eq' => '2010-10-15'}
+    )
+  end
+
+  it "should be able to query based on meta.timestamp" do
+    assert_search_matches({
+        '/path/to/2010-10-15.yaml' => 
apply_timestamp(Puppet::Node::Facts.new("2010-10-15", {}), 
Time.parse("2010-10-15")),
+      },
+      {
+        '/path/to/2010-11-01.yaml' => 
apply_timestamp(Puppet::Node::Facts.new("2010-11-01", {}), 
Time.parse("2010-11-01")),
+        '/path/to/2010-11-10.yaml' => 
apply_timestamp(Puppet::Node::Facts.new("2010-11-10", {}), 
Time.parse("2010-11-10")),
+        '/path/to/2010-10-01.yaml' => 
apply_timestamp(Puppet::Node::Facts.new("2010-10-01", {}), 
Time.parse("2010-10-01")),
+        '/path/to/2010-10-10.yaml' => 
apply_timestamp(Puppet::Node::Facts.new("2010-10-10", {}), 
Time.parse("2010-10-10")),
+      },
+      {'meta.timestamp' => '2010-10-15'}
+    )
+  end
+
+  it "should be able to query based on meta.timestamp.ne" do
+    assert_search_matches({
+        '/path/to/2010-11-01.yaml' => 
apply_timestamp(Puppet::Node::Facts.new("2010-11-01", {}), 
Time.parse("2010-11-01")),
+        '/path/to/2010-11-10.yaml' => 
apply_timestamp(Puppet::Node::Facts.new("2010-11-10", {}), 
Time.parse("2010-11-10")),
+        '/path/to/2010-10-01.yaml' => 
apply_timestamp(Puppet::Node::Facts.new("2010-10-01", {}), 
Time.parse("2010-10-01")),
+        '/path/to/2010-10-10.yaml' => 
apply_timestamp(Puppet::Node::Facts.new("2010-10-10", {}), 
Time.parse("2010-10-10")),
+      },
+      {
+        '/path/to/2010-10-15.yaml' => 
apply_timestamp(Puppet::Node::Facts.new("2010-10-15", {}), 
Time.parse("2010-10-15")),
+      },
+      {'meta.timestamp.ne' => '2010-10-15'}
+    )
+  end
 end
-- 
1.7.2

-- 
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.

Reply via email to