summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLamont Granquist <lamont@scriptkiddie.org>2017-11-29 10:22:34 -0800
committerGitHub <noreply@github.com>2017-11-29 10:22:34 -0800
commit635f665d036c5e3bcdb13f5fd8ebe56e696f6259 (patch)
treea024fec4de50aad3630758687904e1d23b0be10a
parent87b1a41d8372b3761f53e801ac4d3f0fb7c7ecd5 (diff)
parent260486f8e0d3ecd1d0e653f31e9241065d2d329d (diff)
downloadchef-635f665d036c5e3bcdb13f5fd8ebe56e696f6259.tar.gz
Merge pull request #6608 from chef/lcg/nodemap-platform-versions
fix NodeMap to not throw exceptions on platform_versions
-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|