[Pkg-puppet-devel] [SCM] Puppet packaging for Debian branch, experimental, updated. debian/2.6.8-1-844-g7ec39d5
Paul Berry
paul at puppetlabs.com
Tue May 10 07:59:48 UTC 2011
The following commit has been merged in the experimental branch:
commit 3d32fe836eefac1974e00b2763322c998b452ddb
Author: Paul Berry <paul at puppetlabs.com>
Date: Mon Nov 1 13:46:21 2010 -0700
(#5166) Inventory service is now searchable by timestamp.
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.
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
--
Puppet packaging for Debian
More information about the Pkg-puppet-devel
mailing list