summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorXabier de Zuazo <xabier@zuazo.org>2013-02-08 11:59:54 +0100
committerBryan McLellan <btm@opscode.com>2013-04-11 13:04:33 -0700
commit66d5485de8342a1e6f719547222c98dd6012908a (patch)
treef6b1487de8dce80f12bbc7c481a01a837cf81af7
parentdcfeebe24ab048d555fd70ff5f22fae868548ab4 (diff)
downloadchef-66d5485de8342a1e6f719547222c98dd6012908a.tar.gz
[CHEF-3919] Added support for setting ">", "<", "<=" ... versions in Chef::Platform
-rw-r--r--lib/chef/platform.rb17
-rw-r--r--lib/chef/version_class.rb2
2 files changed, 12 insertions, 7 deletions
diff --git a/lib/chef/platform.rb b/lib/chef/platform.rb
index b176e9c731..f7c94072a1 100644
--- a/lib/chef/platform.rb
+++ b/lib/chef/platform.rb
@@ -19,6 +19,7 @@
require 'chef/config'
require 'chef/log'
require 'chef/mixin/params_validate'
+require 'chef/version_constraint'
# This file depends on nearly every provider in chef, but requiring them
# directly causes circular requires resulting in uninitialized constant errors.
@@ -344,15 +345,17 @@ class Chef
end
if platforms.has_key?(name_sym)
- if platforms[name_sym].has_key?(version)
- Chef::Log.debug("Platform #{name.to_s} version #{version} found")
- if platforms[name_sym].has_key?(:default)
- provider_map.merge!(platforms[name_sym][:default])
- end
- provider_map.merge!(platforms[name_sym][version])
- elsif platforms[name_sym].has_key?(:default)
+ platform_versions = platforms[name_sym].select {|k, v| k != :default }
+ if platforms[name_sym].has_key?(:default)
provider_map.merge!(platforms[name_sym][:default])
end
+ platform_versions.each do |platform_version, provider|
+ version_constraint = Chef::VersionConstraint.new(platform_version)
+ if version_constraint.include?(version)
+ Chef::Log.debug("Platform #{name.to_s} version #{version} found")
+ provider_map.merge!(provider)
+ end
+ end
else
Chef::Log.debug("Platform #{name} not found, using all defaults. (Unsupported platform?)")
end
diff --git a/lib/chef/version_class.rb b/lib/chef/version_class.rb
index e9879274ad..36ff05a46d 100644
--- a/lib/chef/version_class.rb
+++ b/lib/chef/version_class.rb
@@ -60,6 +60,8 @@ class Chef
[ $1.to_i, $2.to_i, $3.to_i ]
when /^(\d+)\.(\d+)$/
[ $1.to_i, $2.to_i, 0 ]
+ when /^(\d+)$/
+ [ $1.to_i, 0, 0 ]
else
msg = "'#{str.to_s}' does not match 'x.y.z' or 'x.y'"
raise Chef::Exceptions::InvalidCookbookVersion.new( msg )