From a66777e6b68413e6b17860f85c8b0e3a0314aeb5 Mon Sep 17 00:00:00 2001 From: twangboy Date: Mon, 24 Oct 2016 12:32:18 -0600 Subject: [PATCH] Make needs_reboot not part of class --- salt/modules/win_wua.py | 23 +++++++---------------- salt/utils/win_update.py | 30 +++++++++++++++++------------- 2 files changed, 24 insertions(+), 29 deletions(-) diff --git a/salt/modules/win_wua.py b/salt/modules/win_wua.py index 0153f983a5..203d3546f6 100644 --- a/salt/modules/win_wua.py +++ b/salt/modules/win_wua.py @@ -162,10 +162,7 @@ def available(software=True, severities) # Return results as Summary or Details - if summary: - return updates.summary() - else: - return updates.list() + return updates.summary() if summary else updates.list() def list_update(name, download=False, install=False): @@ -249,10 +246,7 @@ def list_update(name, download=False, install=False): if install: ret['Install'] = wua.install(updates.updates) - if not ret: - return updates.list() - - return ret + return ret if ret else updates.list() def list_updates(software=True, @@ -393,10 +387,7 @@ def list_updates(software=True, ret['Install'] = wua.install(updates.updates) if not ret: - if summary: - return updates.summary() - else: - return updates.list() + return updates.summary() if summary else updates.list() return ret @@ -435,7 +426,7 @@ def download_update(name): raise CommandExecutionError('No updates found') if updates.count() > 1: - raise CommandExecutionError('More than one update found') + raise CommandExecutionError('Multiple updates found, narrow your search') return wua.download(updates.updates) @@ -507,7 +498,7 @@ def install_update(name): raise CommandExecutionError('No updates found') if updates.count() > 1: - raise CommandExecutionError('More than one update found') + raise CommandExecutionError('Multiple updates found, narrow your search') return wua.install(updates.updates) @@ -579,7 +570,7 @@ def uninstall(name): raise CommandExecutionError('No updates found') if updates.count() > 1: - raise CommandExecutionError('More than one update found') + raise CommandExecutionError('Multiple updates found, narrow your search') return wua.uninstall(updates.updates) @@ -943,4 +934,4 @@ def get_needs_reboot(): salt '*' win_wua.get_needs_reboot ''' - return salt.utils.win_update.WindowsUpdateAgent.needs_reboot() + return salt.utils.win_update.needs_reboot() diff --git a/salt/utils/win_update.py b/salt/utils/win_update.py index 6c07efd900..f685c7d41e 100644 --- a/salt/utils/win_update.py +++ b/salt/utils/win_update.py @@ -531,7 +531,7 @@ class WindowsUpdateAgent(object): # Populate the return dictionary ret['Success'] = True ret['Message'] = 'Uninstalled using WUSA' - ret['NeedsReboot'] = self.needs_reboot() + ret['NeedsReboot'] = needs_reboot() log.debug('NeedsReboot: {0}'.format(ret['NeedsReboot'])) # Refresh the Updates Table @@ -589,21 +589,25 @@ class WindowsUpdateAgent(object): return ret - def needs_reboot(): - ''' - Determines if the system needs to be rebooted. - Returns: +def needs_reboot(): + ''' + Determines if the system needs to be rebooted. - bool: True if the system requires a reboot, False if not + Returns: - CLI Examples: + bool: True if the system requires a reboot, False if not - .. code-block:: bash + CLI Examples: - salt '*' win_wua.get_needs_reboot + .. code-block:: bash - ''' - # Create an AutoUpdate object - obj_sys = win32com.client.Dispatch('Microsoft.Update.SystemInfo') - return salt.utils.is_true(obj_sys.RebootRequired) + salt '*' win_wua.get_needs_reboot + + ''' + # Initialize the PyCom system + pythoncom.CoInitialize() + + # Create an AutoUpdate object + obj_sys = win32com.client.Dispatch('Microsoft.Update.SystemInfo') + return salt.utils.is_true(obj_sys.RebootRequired)