From 67b8e86e5052085890c737d06caf6c2aa05dd412 Mon Sep 17 00:00:00 2001 From: Baptiste Courtois Date: Fri, 28 Apr 2017 20:54:02 +0200 Subject: [PATCH] Use not_if guards for QFE prerequisites --- README.md | 3 +++ libraries/package_helper.rb | 14 ++++++------- resources/framework.rb | 20 ++++++++++--------- .../framework_spec.rb | 0 4 files changed, 21 insertions(+), 16 deletions(-) rename spec/{providers => resources}/framework_spec.rb (100%) diff --git a/README.md b/README.md index 7d5be8f..dfee7e1 100644 --- a/README.md +++ b/README.md @@ -158,6 +158,9 @@ References all official .NET setup & patches packages supported by this cookbook #### packages Retrieve a Hash containing .NET setup packages info - `name`, `checksum`, `url` & `not_if` guard. +A string `not_if` guard represents a custom command to determine whether the package should be installed. +A string Array `not_if` guard represents the list of QFE representing or superseding the package. + #### core? Determine whether the current node is running on a Core version of Windows. diff --git a/libraries/package_helper.rb b/libraries/package_helper.rb index c644dcc..ec6d703 100644 --- a/libraries/package_helper.rb +++ b/libraries/package_helper.rb @@ -75,25 +75,25 @@ def packages name: 'Microsoft .NET Framework 4.5.2', url: 'https://download.microsoft.com/download/E/2/1/E21644B5-2DF2-47C2-91BD-63C560427900/NDP452-KB2901907-x86-x64-AllOS-ENU.exe', checksum: '6c2c589132e830a185c5f40f82042bee3022e721a216680bd9b3995ba86f3781', - qfe: %w(KB2901982 KB2934520), + not_if: %w(KB2901982 KB2934520), }, '4.6' => { name: 'Microsoft .NET Framework 4.6', url: 'https://download.microsoft.com/download/C/3/A/C3A5200B-D33C-47E9-9D70-2F7C65DAAD94/NDP46-KB3045557-x86-x64-AllOS-ENU.exe', checksum: 'b21d33135e67e3486b154b11f7961d8e1cfd7a603267fb60febb4a6feab5cf87', - qfe: %w(KB3045562 KB3045563), + not_if: %w(KB3045562 KB3045563), }, '4.6.1' => { name: 'Microsoft .NET Framework 4.6.1', url: 'https://download.microsoft.com/download/E/4/1/E4173890-A24A-4936-9FC9-AF930FE3FA40/NDP461-KB3102436-x86-x64-AllOS-ENU.exe', checksum: 'beaa901e07347d056efe04e8961d5546c7518fab9246892178505a7ba631c301', - qfe: %w(KB3102439 KB3102467 KB3102495), + not_if: %w(KB3102439 KB3102467 KB3102495), }, '4.6.2' => { name: 'Microsoft .NET Framework 4.6.2', url: 'https://download.microsoft.com/download/F/9/4/F942F07D-F26F-4F30-B4E3-EBD54FABA377/NDP462-KB3151800-x86-x64-AllOS-ENU.exe', checksum: '28886593e3b32f018241a4c0b745e564526dbb3295cb2635944e3a393f4278d4', - qfe: %w(KB3151804 KB3151864 KB3151900), + not_if: %w(KB3151804 KB3151864 KB3151900), }, ########### # Patches @@ -123,7 +123,7 @@ def packages end, options: '/norestart /quiet', checksum: x64? ? 'c10787e669b484674584a990e069295e8b81b5366f98508010a3ae181b729482' : '3368c3a329f402fd982b15b399368627b96973f008a5456b5286bdfc10c1169b', - qfe: %w(KB2919442 KB3173424 KB3021910 KB3012199 KB2989647 KB2975061 KB2969339 KB2904440), + not_if: %w(KB2919442 KB3173424 KB3021910 KB3012199 KB2989647 KB2975061 KB2969339 KB2904440), }, 'KB3173424' => { name: 'Update for Microsoft Windows (KB3173424)', @@ -134,7 +134,7 @@ def packages end, options: '/norestart /quiet', checksum: x64? ? '2c6c577e4e231ce6b020e5b9a2766154f474c6ecae82735ba5ec03875d64895b' : '91bf481343be03cc310c50167be8ea1af92113048c99b7b91f1b2b03628b0dcd', - qfe: %w(KB3173424), + not_if: %w(KB3173424), }, 'KB2919355' => { name: 'Update for Microsoft Windows (KB2919355)', @@ -145,7 +145,7 @@ def packages end, options: '/norestart /quiet', checksum: x64? ? 'b0c9ada530f5ee90bb962afa9ed26218c582362315e13b1ba97e59767cb7825d' : 'f8beca5b463a36e1fef45ad0dca6a0de7606930380514ac1852df5ca6e3f6c1d', - qfe: %w(KB2919355), + not_if: %w(KB2919355), }, ) end diff --git a/resources/framework.rb b/resources/framework.rb index e1b7366..3a18221 100644 --- a/resources/framework.rb +++ b/resources/framework.rb @@ -84,11 +84,17 @@ def install_packages # Package specific info checksum pkg[:checksum] source new_resource.package_sources[pkg[:checksum]] || pkg[:url] - not_if pkg[:not_if] unless pkg[:not_if].nil? - # Some packages are installed as QFE updates on 2012, 2012R2 & 10 or may have been superseded by other updates - # TODO: perform a single wmi-lite query in ruby - Array(pkg[:qfe]).each do |kb| - not_if "C:\\Windows\\System32\\wbem\\wmic.exe QFE where HotFixID='#{kb}' | FindStr #{kb}" + # Handle not_if guards + case pkg[:not_if] + when String # Execute the given string guard + not_if pkg[:not_if] + when Array # Ensure given array of QFE KB is not installed + # Some packages are installed as QFE updates on 2012, 2012R2 & 10 or may have been superseded by other updates + not_if do + require 'wmi-lite' + filter = pkg[:not_if].map { |kb| " HotFixID='#{kb}'" }.join(' OR') + !filter.empty? && ::WmiLite::Wmi.new.query("SELECT HotFixID FROM Win32_QuickFixEngineering WHERE #{filter}").any? + end end end @@ -105,10 +111,6 @@ def should_reboot? new_resource.perform_reboot && reboot_pending? end - def version - @version ||= new_resource.version - end - def major_version @major_version ||= new_resource.version.to_i end diff --git a/spec/providers/framework_spec.rb b/spec/resources/framework_spec.rb similarity index 100% rename from spec/providers/framework_spec.rb rename to spec/resources/framework_spec.rb