summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLamont Granquist <lamont@scriptkiddie.org>2017-11-28 09:51:50 -0800
committerLamont Granquist <lamont@scriptkiddie.org>2017-11-28 09:51:50 -0800
commit260486f8e0d3ecd1d0e653f31e9241065d2d329d (patch)
treeed931d9bd5ab0e028232fa01a9a981c1ddc2055d
parent493947028e8560e86a014aced4273f509a678c31 (diff)
downloadchef-lcg/nodemap-platform-versions.tar.gz
fix NodeMap to not throw exceptions on platform_versionslcg/nodemap-platform-versions
Chef::Version and VersionConstraint are for x.y/x.y.z cookbook versions, and are always wrong for anything other than cookbooks. Signed-off-by: Lamont Granquist <lamont@scriptkiddie.org>
-rw-r--r--lib/chef/node_map.rb2
-rw-r--r--spec/unit/node_map_spec.rb18
2 files changed, 19 insertions, 1 deletions
diff --git a/lib/chef/node_map.rb b/lib/chef/node_map.rb
index 7a1a09ae24..25b1f57d44 100644
--- a/lib/chef/node_map.rb
+++ b/lib/chef/node_map.rb
@@ -143,7 +143,7 @@ class Chef
filter_values.empty? ||
Array(filter_values).any? do |v|
- Chef::VersionConstraint::Platform.new(v).include?(value)
+ Gem::Requirement.new(v).satisfied_by?(Gem::Version.new(value))
end
end
diff --git a/spec/unit/node_map_spec.rb b/spec/unit/node_map_spec.rb
index 822f689eab..64106323c2 100644
--- a/spec/unit/node_map_spec.rb
+++ b/spec/unit/node_map_spec.rb
@@ -101,6 +101,24 @@ describe Chef::NodeMap do
end
end
+ describe "platform version checks" do
+ before do
+ node_map.set(:thing, :foo, platform_family: "rhel", platform_version: ">= 7")
+ end
+
+ it "handles non-x.y.z platform versions without throwing an exception" do
+ allow(node).to receive(:[]).with(:platform_family).and_return("rhel")
+ allow(node).to receive(:[]).with(:platform_version).and_return("7.19.2.2F")
+ expect(node_map.get(node, :thing)).to eql(:foo)
+ end
+
+ it "handles non-x.y.z platform versions without throwing an exception when the match fails" do
+ allow(node).to receive(:[]).with(:platform_family).and_return("rhel")
+ allow(node).to receive(:[]).with(:platform_version).and_return("4.19.2.2F")
+ expect(node_map.get(node, :thing)).to eql(nil)
+ end
+ end
+
describe "with a block doing platform_version checks" do
before do
node_map.set(:thing, :foo, platform_family: "rhel") do |node|