summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Smith <tsmith@chef.io>2018-07-07 13:38:44 -0700
committerGitHub <noreply@github.com>2018-07-07 13:38:44 -0700
commitd5b4159e11f86f34075687d34e96354099ed129e (patch)
tree3d815d52e01391278828faaf520f4d939e6ac6e0
parent2b663939d4dd0b7985ef89a3f30ca94c2064772b (diff)
parent554d87ecd4b770c7f54c68f339f836aa03a48c89 (diff)
downloadchef-d5b4159e11f86f34075687d34e96354099ed129e.tar.gz
Merge pull request #7433 from chef/fix_windows_feature
Prevent failures using windows_feature due to the platform helper
-rw-r--r--lib/chef/dsl/platform_introspection.rb5
-rw-r--r--lib/chef/platform/query_helpers.rb6
-rw-r--r--lib/chef/resource/windows_feature_dism.rb6
-rw-r--r--lib/chef/resource/windows_feature_powershell.rb14
4 files changed, 15 insertions, 16 deletions
diff --git a/lib/chef/dsl/platform_introspection.rb b/lib/chef/dsl/platform_introspection.rb
index ac36dbd1dd..e7f0c60f0d 100644
--- a/lib/chef/dsl/platform_introspection.rb
+++ b/lib/chef/dsl/platform_introspection.rb
@@ -259,6 +259,11 @@ class Chef
node[:virtualization][:systems][:docker] && node[:virtualization][:systems][:docker] == "guest")
end
+ # a simple helper to determine if we're on a windows release pre-2012 / 8
+ # @return [Boolean] Is the system older than Windows 8 / 2012
+ def older_than_win_2012_or_8?(node = run_context.nil? ? nil : run_context.node)
+ node["platform_version"].to_f < 6.2
+ end
end
end
end
diff --git a/lib/chef/platform/query_helpers.rb b/lib/chef/platform/query_helpers.rb
index 448885dfbc..b49010efc0 100644
--- a/lib/chef/platform/query_helpers.rb
+++ b/lib/chef/platform/query_helpers.rb
@@ -20,12 +20,6 @@ class Chef
class Platform
class << self
- # a simple helper to determine if we're on a windows release pre-2012 / 8
- # @return [Boolean] Is the system older than Windows 8 / 2012
- def older_than_win_2012_or_8?
- node["platform_version"].to_f < 6.2
- end
-
def windows?
ChefConfig.windows?
end
diff --git a/lib/chef/resource/windows_feature_dism.rb b/lib/chef/resource/windows_feature_dism.rb
index fd076ffad3..c5bdc6fdfa 100644
--- a/lib/chef/resource/windows_feature_dism.rb
+++ b/lib/chef/resource/windows_feature_dism.rb
@@ -50,7 +50,7 @@ class Chef
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+
- Chef::Platform.older_than_win_2012_or_8? ? x : x.map(&:downcase)
+ older_than_win_2012_or_8? ? x : x.map(&:downcase)
end
action :install do
@@ -201,7 +201,7 @@ class Chef
# 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 Chef::Platform.older_than_win_2012_or_8?
+ feature_details.downcase! unless older_than_win_2012_or_8?
node.override["dism_features_cache"][feature_type] << feature_details
end
@@ -219,7 +219,7 @@ class Chef
# 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 Chef::Platform.older_than_win_2012_or_8?
+ 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
diff --git a/lib/chef/resource/windows_feature_powershell.rb b/lib/chef/resource/windows_feature_powershell.rb
index c06e380675..6141ff40ba 100644
--- a/lib/chef/resource/windows_feature_powershell.rb
+++ b/lib/chef/resource/windows_feature_powershell.rb
@@ -61,7 +61,7 @@ class Chef
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+
- Chef::Platform.older_than_win_2012_or_8? ? x : x.map(&:downcase)
+ older_than_win_2012_or_8? ? x : x.map(&:downcase)
end
include Chef::Mixin::PowershellOut
@@ -78,7 +78,7 @@ class Chef
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 Chef::Platform.older_than_win_2012_or_8? && (new_resource.source || new_resource.management_tools)
+ 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
@@ -156,13 +156,13 @@ class Chef
# The appropriate cmdlet to install a windows feature based on windows release
# @return [String]
def install_feature_cmdlet
- Chef::Platform.older_than_win_2012_or_8? ? "Add-WindowsFeature" : "Install-WindowsFeature"
+ 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
- Chef::Platform.older_than_win_2012_or_8? ? "Remove-WindowsFeature" : "Uninstall-WindowsFeature"
+ older_than_win_2012_or_8? ? "Remove-WindowsFeature" : "Uninstall-WindowsFeature"
end
# @return [Array] features the user has requested to install which need installation
@@ -230,7 +230,7 @@ class Chef
def parsed_feature_list
# Grab raw feature information from dism command line
# Windows < 2012 doesn't present a state value so we have to check if the feature is installed or not
- raw_list_of_features = if Chef::Platform.older_than_win_2012_or_8? # make the older format look like the new format, warts and all
+ raw_list_of_features = if older_than_win_2012_or_8? # make the older format look like the new format, warts and all
powershell_out!('Get-WindowsFeature | Select-Object -Property Name, @{Name=\"InstallState\"; Expression = {If ($_.Installed) { 1 } Else { 0 }}} | ConvertTo-Json -Compress', timeout: new_resource.timeout).stdout
else
powershell_out!("Get-WindowsFeature | Select-Object -Property Name,InstallState | ConvertTo-Json -Compress", timeout: new_resource.timeout).stdout
@@ -243,7 +243,7 @@ class Chef
# @return [void]
def add_to_feature_mash(feature_type, feature_details)
# add the lowercase feature name to the mash unless we're on < 2012 where they're case sensitive
- node.override["powershell_features_cache"][feature_type] << (Chef::Platform.older_than_win_2012_or_8? ? feature_details : feature_details.downcase)
+ node.override["powershell_features_cache"][feature_type] << (older_than_win_2012_or_8? ? feature_details : feature_details.downcase)
end
# Fail if any of the packages are in a removed state
@@ -259,7 +259,7 @@ class Chef
# 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 Chef::Platform.older_than_win_2012_or_8?
+ 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