mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Fix win_wua to handle empty CDispatch objects
This commit is contained in:
parent
3cd7a62f3f
commit
0d78611767
3 changed files with 50 additions and 6 deletions
2
changelog/66718.fixed.md
Normal file
2
changelog/66718.fixed.md
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
Fixed ``win_wua.available`` when some of the update objects are empty CDispatch
|
||||||
|
objects. The ``available`` function no longer crashes
|
|
@ -528,14 +528,18 @@ class WindowsUpdateAgent:
|
||||||
found = updates.updates
|
found = updates.updates
|
||||||
|
|
||||||
for update in self._updates:
|
for update in self._updates:
|
||||||
|
# Some update objects seem to be empty or undefined. Those will be
|
||||||
|
# exposed here if they are missing these attributes
|
||||||
|
try:
|
||||||
|
if salt.utils.data.is_true(update.IsHidden) and skip_hidden:
|
||||||
|
continue
|
||||||
|
|
||||||
if salt.utils.data.is_true(update.IsHidden) and skip_hidden:
|
if salt.utils.data.is_true(update.IsInstalled) and skip_installed:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if salt.utils.data.is_true(update.IsInstalled) and skip_installed:
|
if salt.utils.data.is_true(update.IsMandatory) and skip_mandatory:
|
||||||
continue
|
continue
|
||||||
|
except AttributeError:
|
||||||
if salt.utils.data.is_true(update.IsMandatory) and skip_mandatory:
|
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# Windows 10 build 2004 introduced some problems with the
|
# Windows 10 build 2004 introduced some problems with the
|
||||||
|
|
|
@ -1,14 +1,52 @@
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
|
try:
|
||||||
|
import win32com.client
|
||||||
|
|
||||||
|
HAS_WIN32 = True
|
||||||
|
except ImportError:
|
||||||
|
HAS_WIN32 = False
|
||||||
|
|
||||||
import salt.utils.win_update as win_update
|
import salt.utils.win_update as win_update
|
||||||
from tests.support.mock import MagicMock, patch
|
from tests.support.mock import MagicMock, patch
|
||||||
|
|
||||||
pytestmark = [
|
pytestmark = [
|
||||||
pytest.mark.windows_whitelisted,
|
pytest.mark.windows_whitelisted,
|
||||||
pytest.mark.skip_unless_on_windows,
|
pytest.mark.skip_unless_on_windows,
|
||||||
|
pytest.mark.skipif(not HAS_WIN32, reason="Requires Win32 libraries"),
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
def test_available_no_updates():
|
||||||
|
"""
|
||||||
|
Test installed when there are no updates on the system
|
||||||
|
"""
|
||||||
|
with patch("salt.utils.winapi.Com", autospec=True), patch(
|
||||||
|
"win32com.client.Dispatch", autospec=True
|
||||||
|
), patch.object(win_update.WindowsUpdateAgent, "refresh", autospec=True):
|
||||||
|
wua = win_update.WindowsUpdateAgent(online=False)
|
||||||
|
wua._updates = []
|
||||||
|
|
||||||
|
available_updates = wua.available()
|
||||||
|
|
||||||
|
assert available_updates.updates.Add.call_count == 0
|
||||||
|
|
||||||
|
|
||||||
|
def test_available_no_updates_empty_objects():
|
||||||
|
"""
|
||||||
|
Test installed when there are no updates on the system
|
||||||
|
"""
|
||||||
|
with patch("salt.utils.winapi.Com", autospec=True), patch(
|
||||||
|
"win32com.client.Dispatch", autospec=True
|
||||||
|
), patch.object(win_update.WindowsUpdateAgent, "refresh", autospec=True):
|
||||||
|
wua = win_update.WindowsUpdateAgent(online=False)
|
||||||
|
wua._updates = [win32com.client.CDispatch, win32com.client.CDispatch]
|
||||||
|
|
||||||
|
available_updates = wua.available()
|
||||||
|
|
||||||
|
assert available_updates.updates.Add.call_count == 0
|
||||||
|
|
||||||
|
|
||||||
def test_installed_no_updates():
|
def test_installed_no_updates():
|
||||||
"""
|
"""
|
||||||
Test installed when there are no updates on the system
|
Test installed when there are no updates on the system
|
||||||
|
|
Loading…
Add table
Reference in a new issue