diff options
author | Tim Smith <tsmith@chef.io> | 2018-03-28 15:42:58 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-03-28 15:42:58 -0700 |
commit | eb509e6714922d1653b106bbfc7d0a7b7b2f0c5a (patch) | |
tree | 400c1738c6b080416a1df542645b0efcb7d498c8 | |
parent | 2151d6d435f6169ca41dc1f96324a3585ff22e06 (diff) | |
parent | b77f792abb7753208b0f1c23af3a84b024a6ccf8 (diff) | |
download | chef-eb509e6714922d1653b106bbfc7d0a7b7b2f0c5a.tar.gz |
Merge pull request #7079 from chef/case_insensitve_dism
windows_feature_dism: Be case insensitive with feature names
-rw-r--r-- | lib/chef/resource/windows_feature_dism.rb | 19 | ||||
-rw-r--r-- | spec/unit/resource/windows_feature_dism.rb | 10 |
2 files changed, 21 insertions, 8 deletions
diff --git a/lib/chef/resource/windows_feature_dism.rb b/lib/chef/resource/windows_feature_dism.rb index 03cb5019ad..2ba71a8186 100644 --- a/lib/chef/resource/windows_feature_dism.rb +++ b/lib/chef/resource/windows_feature_dism.rb @@ -30,7 +30,7 @@ class Chef property :feature_name, [Array, String], description: "The name of the feature/role(s) to install if it differs from the resource name.", - coerce: proc { |x| x.is_a?(String) ? x.split(/\s*,\s*/) : x }, + coerce: proc { |x| to_lowercase_array(x) }, name_property: true property :source, String, @@ -44,6 +44,14 @@ class Chef description: "Specifies a timeout (in seconds) for feature install.", default: 600 + def to_lowercase_array(x) + x = x.split(/\s*,\s*/) if x.is_a?(String) # split multiple forms of a comma separated list + + # dism on windows < 2012 is case sensitive so only downcase when on 2012+ + # @todo when we're really ready to remove support for Windows 2008 R2 this check can go away + node["platform_version"].to_f < 6.2 ? x : x.map(&:downcase) + end + action :install do description "Install a Windows role/feature using DISM" @@ -187,8 +195,13 @@ class Chef # + | + n number of spaces # @return [void] def add_to_feature_mash(feature_type, feature_string) - feature_details = feature_string.strip.split(/\s+[|]\s+/) - node.override["dism_features_cache"][feature_type] << feature_details.first + feature_details = feature_string.strip.split(/\s+[|]\s+/).first + + # dism on windows 2012+ isn't case sensitive so it's best to compare + # lowercase lists so the user input doesn't need to be case sensitive + # @todo when we're ready to remove windows 2008R2 the gating here can go away + feature_details.downcase! unless node["platform_version"].to_f < 6.2 + node.override["dism_features_cache"][feature_type] << feature_details end # Fail if any of the packages are in a removed state diff --git a/spec/unit/resource/windows_feature_dism.rb b/spec/unit/resource/windows_feature_dism.rb index 1004b75ba9..4f973f7e82 100644 --- a/spec/unit/resource/windows_feature_dism.rb +++ b/spec/unit/resource/windows_feature_dism.rb @@ -29,17 +29,17 @@ describe Chef::Resource::WindowsFeatureDism do end it "sets the feature_name property as its name property" do - expect(resource.feature_name).to eql(%w{SNMP DHCP}) + expect(resource.feature_name).to eql(%w{snmp dhcp}) end - it "coerces comma separated lists of features to arrays" do + it "coerces comma separated lists of features to a lowercase array" do resource.feature_name "SNMP, DHCP" - expect(resource.feature_name).to eql(%w{SNMP DHCP}) + expect(resource.feature_name).to eql(%w{snmp dhcp}) end - it "coerces a single feature as a String into an array" do + it "coerces a single feature as a String to a lowercase array" do resource.feature_name "SNMP" - expect(resource.feature_name).to eql(["SNMP"]) + expect(resource.feature_name).to eql(["snmp"]) end it "supports :install, :remove, and :delete actions" do |