From e9bc7871e519285cd1f5a82837cc5d2ff6c7af8b Mon Sep 17 00:00:00 2001 From: Tim Smith Date: Fri, 28 Feb 2020 16:06:46 -0800 Subject: Deprecate the older_than_win_2012_or_8? helper Within Chef this is only used in the windows_feature_powershell resource which I've cleaned up. Signed-off-by: Tim Smith --- lib/chef/dsl/platform_introspection.rb | 3 ++- lib/chef/resource/windows_feature_powershell.rb | 11 +++-------- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/lib/chef/dsl/platform_introspection.rb b/lib/chef/dsl/platform_introspection.rb index 8cb625d9c9..9ce3aa3513 100644 --- a/lib/chef/dsl/platform_introspection.rb +++ b/lib/chef/dsl/platform_introspection.rb @@ -248,6 +248,8 @@ class Chef end # a simple helper to determine if we're on a windows release pre-2012 / 8 + # + # @deprecated Windows releases before Windows 2012 and 8 are no longer supported # @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 @@ -256,7 +258,6 @@ class Chef # ^^^^^^ NOTE: PLEASE DO NOT CONTINUE TO ADD THESE KINDS OF PLATFORM_VERSION APIS WITHOUT ^^^^^^^ # ^^^^^^ GOING THROUGH THE DESIGN REVIEW PROCESS AND ADDRESS THE EXISTING CHEF-SUGAR ONES ^^^^^^^ # ^^^^^^ DO "THE HARD RIGHT THING" AND ADDRESS THE BROADER PROBLEM AND FIX IT ALL. ^^^^^^^ - end end end diff --git a/lib/chef/resource/windows_feature_powershell.rb b/lib/chef/resource/windows_feature_powershell.rb index 8f9abb002b..e848df0ec1 100644 --- a/lib/chef/resource/windows_feature_powershell.rb +++ b/lib/chef/resource/windows_feature_powershell.rb @@ -190,13 +190,8 @@ class Chef # fetch the list of available feature names and state in JSON and parse the JSON 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 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 - end + # Grab raw feature information from WindowsFeature + raw_list_of_features = powershell_out!("Get-WindowsFeature | Select-Object -Property Name,InstallState | ConvertTo-Json -Compress", timeout: new_resource.timeout).stdout Chef::JSONCompat.from_json(raw_list_of_features) end @@ -205,7 +200,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] << (older_than_win_2012_or_8? ? feature_details : feature_details.downcase) + node.override["powershell_features_cache"][feature_type] << feature_details.downcase end # Fail if any of the packages are in a removed state -- cgit v1.2.1