summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Smith <tsmith@chef.io>2020-01-21 10:10:58 -0800
committerGitHub <noreply@github.com>2020-01-21 10:10:58 -0800
commitca32c4b96b1b881f21d7c501b137ec20db8cb6c1 (patch)
tree1711ff0814bdb3f4e37c33c595a9d04fb51d47dd
parent88444e0beddedc5d66b0cebc844e68e5a39524ee (diff)
parent20470f104db79864b5aa871eb17e72f4884d25b5 (diff)
downloadchef-ca32c4b96b1b881f21d7c501b137ec20db8cb6c1.tar.gz
Merge pull request #9205 from chef/remove_2008_feature
Remove support for Windows 7 / 2008 from windows_feature
-rw-r--r--lib/chef/resource/windows_feature_dism.rb29
-rw-r--r--lib/chef/resource/windows_feature_powershell.rb57
-rw-r--r--spec/unit/resource/windows_feature_dism_spec.rb21
-rw-r--r--spec/unit/resource/windows_feature_powershell_spec.rb21
4 files changed, 23 insertions, 105 deletions
diff --git a/lib/chef/resource/windows_feature_dism.rb b/lib/chef/resource/windows_feature_dism.rb
index faeb0b0762..53275b062e 100644
--- a/lib/chef/resource/windows_feature_dism.rb
+++ b/lib/chef/resource/windows_feature_dism.rb
@@ -1,7 +1,7 @@
#
# Author:: Seth Chisamore (<schisamo@chef.io>)
#
-# Copyright:: 2011-2018, Chef Software, Inc.
+# Copyright:: 2011-2020, Chef Software, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -44,12 +44,10 @@ class Chef
description: "Specifies a timeout (in seconds) for the feature installation.",
default: 600
- # @return [Array] lowercase the array unless we're on < Windows 2012
+ # @return [Array] lowercase the array
def to_formatted_array(x)
x = x.split(/\s*,\s*/) if x.is_a?(String) # split multiple forms of a comma separated list
-
- # feature installs on windows < 2012 are case sensitive so only downcase when on 2012+
- older_than_win_2012_or_8? ? x : x.map(&:downcase)
+ x.map(&:downcase)
end
action :install do
@@ -98,8 +96,6 @@ class Chef
action :delete do
description "Remove a Windows role/feature from the image using DISM"
- raise_if_delete_unsupported
-
reload_cached_dism_data unless node["dism_features_cache"]
fail_if_unavailable # fail if the features don't exist
@@ -193,27 +189,18 @@ class Chef
logger.trace("The cache contains\n#{node["dism_features_cache"]}")
end
- # parse the feature string and add the values to the appropriate array
- # in the
- # strips trailing whitespace characters then split on n number of spaces
- # + | + n number of spaces
+ # parse the feature string and add the values to the appropriate array in the strips
+ # trailing whitespace characters then split on n number of spaces + | + n number of spaces
# @return [void]
def add_to_feature_mash(feature_type, feature_string)
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 older_than_win_2012_or_8?
+ # dism isn't case sensitive so it's best to compare lowercase lists so the
+ # user input doesn't need to be case sensitive
+ feature_details.downcase!
node.override["dism_features_cache"][feature_type] << feature_details
end
- # Fail unless we're on windows 8+ / 2012+ where deleting a feature is supported
- # @return [void]
- def raise_if_delete_unsupported
- raise Chef::Exceptions::UnsupportedAction, "#{self} :delete action not supported on Windows releases before Windows 8/2012. Cannot continue!" if older_than_win_2012_or_8?
- end
-
def required_parent_feature?(error_message)
error_message.include?("Error: 50") && error_message.include?("required parent feature")
end
diff --git a/lib/chef/resource/windows_feature_powershell.rb b/lib/chef/resource/windows_feature_powershell.rb
index 7d454a23bb..8f9abb002b 100644
--- a/lib/chef/resource/windows_feature_powershell.rb
+++ b/lib/chef/resource/windows_feature_powershell.rb
@@ -1,7 +1,7 @@
#
# Author:: Greg Zapp (<greg.zapp@gmail.com>)
#
-# Copyright:: 2015-2018, Chef Software, Inc
+# Copyright:: 2015-2020, Chef Software, Inc
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -50,20 +50,18 @@ class Chef
description: "Install all applicable management tools for the roles, role services, or features.",
default: false
- # Converts strings of features into an Array. Array objects are lowercased unless we're on < 8/2k12+.
+ # Converts strings of features into an Array. Array objects are lowercased
# @return [Array] array of features
def to_formatted_array(x)
x = x.split(/\s*,\s*/) if x.is_a?(String) # split multiple forms of a comma separated list
- # feature installs on windows < 8/2012 are case sensitive so only downcase when on 2012+
- older_than_win_2012_or_8? ? x : x.map(&:downcase)
+ # features aren't case sensitive so let's compare in lowercase
+ x.map(&:downcase)
end
include Chef::Mixin::PowershellOut
action :install do
- raise_on_old_powershell
-
reload_cached_powershell_data unless node["powershell_features_cache"]
fail_if_unavailable # fail if the features don't exist
fail_if_removed # fail if the features are in removed state
@@ -71,14 +69,10 @@ class Chef
Chef::Log.debug("Windows features needing installation: #{features_to_install.empty? ? "none" : features_to_install.join(",")}")
unless features_to_install.empty?
converge_by("install Windows feature#{"s" if features_to_install.count > 1} #{features_to_install.join(",")}") do
- install_command = "#{install_feature_cmdlet} #{features_to_install.join(",")}"
- install_command << " -IncludeAllSubFeature" if new_resource.all
- if older_than_win_2012_or_8? && (new_resource.source || new_resource.management_tools)
- Chef::Log.warn("The 'source' and 'management_tools' properties are only available on Windows 8/2012 or greater. Skipping these properties!")
- else
- install_command << " -Source \"#{new_resource.source}\"" if new_resource.source
- install_command << " -IncludeManagementTools" if new_resource.management_tools
- end
+ install_command = "Install-WindowsFeature #{features_to_install.join(",")}"
+ install_command << " -IncludeAllSubFeature" if new_resource.all
+ install_command << " -Source \"#{new_resource.source}\"" if new_resource.source
+ install_command << " -IncludeManagementTools" if new_resource.management_tools
cmd = powershell_out!(install_command, timeout: new_resource.timeout)
Chef::Log.info(cmd.stdout)
@@ -89,15 +83,13 @@ class Chef
end
action :remove do
- raise_on_old_powershell
-
reload_cached_powershell_data unless node["powershell_features_cache"]
Chef::Log.debug("Windows features needing removal: #{features_to_remove.empty? ? "none" : features_to_remove.join(",")}")
unless features_to_remove.empty?
converge_by("remove Windows feature#{"s" if features_to_remove.count > 1} #{features_to_remove.join(",")}") do
- cmd = powershell_out!("#{remove_feature_cmdlet} #{features_to_remove.join(",")}", timeout: new_resource.timeout)
+ cmd = powershell_out!("Uninstall-WindowsFeature #{features_to_remove.join(",")}", timeout: new_resource.timeout)
Chef::Log.info(cmd.stdout)
reload_cached_powershell_data # Reload cached powershell feature state
@@ -106,9 +98,6 @@ class Chef
end
action :delete do
- raise_on_old_powershell
- raise_if_delete_unsupported
-
reload_cached_powershell_data unless node["powershell_features_cache"]
fail_if_unavailable # fail if the features don't exist
@@ -138,29 +127,6 @@ class Chef
0 # zero as in nothing is installed
end
- # raise if we're running powershell less than 3.0 since we need convertto-json
- # check the powershell version via ohai data and if we're < 3.0 also shellout to make sure as
- # a newer version could be installed post ohai run. Yes we're double checking. It's fine.
- # @todo this can go away when we fully remove support for Windows 2008 R2
- # @raise [RuntimeError] Raise if powershell is < 3.0
- def raise_on_old_powershell
- # be super defensive about the powershell lang plugin not being there
- return if node["languages"] && node["languages"]["powershell"] && node["languages"]["powershell"]["version"].to_i >= 3
- raise "The windows_feature_powershell resource requires PowerShell 3.0 or later. Please install PowerShell 3.0+ before running this resource." if powershell_version < 3
- end
-
- # The appropriate cmdlet to install a windows feature based on windows release
- # @return [String]
- def install_feature_cmdlet
- older_than_win_2012_or_8? ? "Add-WindowsFeature" : "Install-WindowsFeature"
- end
-
- # The appropriate cmdlet to remove a windows feature based on windows release
- # @return [String]
- def remove_feature_cmdlet
- older_than_win_2012_or_8? ? "Remove-WindowsFeature" : "Uninstall-WindowsFeature"
- end
-
# @return [Array] features the user has requested to install which need installation
def features_to_install
# the intersection of the features to install & disabled features are what needs installing
@@ -253,11 +219,6 @@ class Chef
removed = new_resource.feature_name & node["powershell_features_cache"]["removed"]
raise "The Windows feature#{"s" if removed.count > 1} #{removed.join(",")} #{removed.count > 1 ? "are" : "is"} removed from the host and cannot be installed." unless removed.empty?
end
-
- # Fail unless we're on windows 8+ / 2012+ where deleting a feature is supported
- def raise_if_delete_unsupported
- raise Chef::Exceptions::UnsupportedAction, "#{self} :delete action not supported on Windows releases before Windows 8/2012. Cannot continue!" if older_than_win_2012_or_8?
- end
end
end
end
diff --git a/spec/unit/resource/windows_feature_dism_spec.rb b/spec/unit/resource/windows_feature_dism_spec.rb
index 87d99ecbaf..bc6ca3adeb 100644
--- a/spec/unit/resource/windows_feature_dism_spec.rb
+++ b/spec/unit/resource/windows_feature_dism_spec.rb
@@ -1,5 +1,5 @@
#
-# Copyright:: Copyright 2018, Chef Software, Inc.
+# Copyright:: Copyright 2018-2020, Chef Software, Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -32,7 +32,6 @@ describe Chef::Resource::WindowsFeatureDism do
end
it "the feature_name property is the name_property" do
- node.automatic[:platform_version] = "6.2.9200"
expect(resource.feature_name).to eql(%w{snmp dhcp})
end
@@ -46,27 +45,13 @@ describe Chef::Resource::WindowsFeatureDism do
expect { resource.action :remove }.not_to raise_error
end
- it "coerces comma separated lists of features to a lowercase array on 2012+" do
- node.automatic[:platform_version] = "6.2.9200"
+ 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})
end
- it "coerces a single feature as a String to a lowercase array on 2012+" do
- node.automatic[:platform_version] = "6.2.9200"
+ it "coerces a single feature as a String to a lowercase array" do
resource.feature_name "SNMP"
expect(resource.feature_name).to eql(["snmp"])
end
-
- it "coerces comma separated lists of features to an array, but preserves case on < 2012" do
- node.automatic[:platform_version] = "6.1.7601"
- resource.feature_name "SNMP, DHCP"
- expect(resource.feature_name).to eql(%w{SNMP DHCP})
- end
-
- it "coerces a single feature as a String to an array, but preserves case on < 2012" do
- node.automatic[:platform_version] = "6.1.7601"
- resource.feature_name "SNMP"
- expect(resource.feature_name).to eql(["SNMP"])
- end
end
diff --git a/spec/unit/resource/windows_feature_powershell_spec.rb b/spec/unit/resource/windows_feature_powershell_spec.rb
index 3dc1604361..2d199ea809 100644
--- a/spec/unit/resource/windows_feature_powershell_spec.rb
+++ b/spec/unit/resource/windows_feature_powershell_spec.rb
@@ -1,5 +1,5 @@
#
-# Copyright:: Copyright 2018, Chef Software, Inc.
+# Copyright:: Copyright 2018-2020, Chef Software, Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -32,7 +32,6 @@ describe Chef::Resource::WindowsFeaturePowershell do
end
it "the feature_name property is the name_property" do
- node.automatic[:platform_version] = "6.2.9200"
expect(resource.feature_name).to eql(%w{snmp dhcp})
end
@@ -46,27 +45,13 @@ describe Chef::Resource::WindowsFeaturePowershell do
expect { resource.action :remove }.not_to raise_error
end
- it "coerces comma separated lists of features to a lowercase array on 2012+" do
- node.automatic[:platform_version] = "6.2.9200"
+ 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})
end
- it "coerces a single feature as a String to a lowercase array on 2012+" do
- node.automatic[:platform_version] = "6.2.9200"
+ it "coerces a single feature as a String to a lowercase array" do
resource.feature_name "SNMP"
expect(resource.feature_name).to eql(["snmp"])
end
-
- it "coerces comma separated lists of features to an array, but preserves case on < 2012" do
- node.automatic[:platform_version] = "6.1.7601"
- resource.feature_name "SNMP, DHCP"
- expect(resource.feature_name).to eql(%w{SNMP DHCP})
- end
-
- it "coerces a single feature as a String to an array, but preserves case on < 2012" do
- node.automatic[:platform_version] = "6.1.7601"
- resource.feature_name "SNMP"
- expect(resource.feature_name).to eql(["SNMP"])
- end
end