Skip to content

Commit

Permalink
Merge pull request #56730 from twangboy/backport_52992
Browse files Browse the repository at this point in the history
Backport #52992
  • Loading branch information
dwoz authored Apr 23, 2020
2 parents 044ad33 + eda3757 commit ff3b690
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ Versions are `MAJOR.PATCH`.
### Deprecated

### Changed
- [#56730](https://github.com/saltstack/salt/pull/56730) - Backport #52992

### Fixed

Expand Down
10 changes: 5 additions & 5 deletions salt/modules/win_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ def get_pending_computer_name():
salt 'minion-id' system.get_pending_computer_name
"""
current = get_computer_name()
pending = __salt__["reg.read_value"](
pending = __utils__["reg.read_value"](
"HKLM", r"SYSTEM\CurrentControlSet\Services\Tcpip\Parameters", "NV Hostname"
)["vdata"]
if pending:
Expand Down Expand Up @@ -1405,7 +1405,7 @@ def get_pending_file_rename():
# then a reboot is pending.

for vname in vnames:
reg_ret = __salt__["reg.read_value"]("HKLM", key, vname)
reg_ret = __utils__["reg.read_value"]("HKLM", key, vname)

if reg_ret["success"]:
log.debug("Found key: %s", key)
Expand Down Expand Up @@ -1441,7 +1441,7 @@ def get_pending_servermanager():
# the value data, and since an actual reboot won't be pending in that
# instance, just catch instances where we try unsuccessfully to cast as int.

reg_ret = __salt__["reg.read_value"]("HKLM", key, vname)
reg_ret = __utils__["reg.read_value"]("HKLM", key, vname)

if reg_ret["success"]:
log.debug("Found key: %s", key)
Expand Down Expand Up @@ -1516,7 +1516,7 @@ def set_reboot_required_witnessed():
salt '*' system.set_reboot_required_witnessed
"""
return __salt__["reg.set_value"](
return __utils__["reg.set_value"](
hive="HKLM",
key=MINION_VOLATILE_KEY,
volatile=True,
Expand Down Expand Up @@ -1548,7 +1548,7 @@ def get_reboot_required_witnessed():
salt '*' system.get_reboot_required_witnessed
"""
value_dict = __salt__["reg.read_value"](
value_dict = __utils__["reg.read_value"](
hive="HKLM", key=MINION_VOLATILE_KEY, vname=REBOOT_REQUIRED_NAME
)
return value_dict["vdata"] == 1
Expand Down
99 changes: 97 additions & 2 deletions tests/unit/modules/test_win_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,13 +317,108 @@ def test_get_pending_computer_name(self):
win_system, "get_computer_name", MagicMock(return_value="salt")
):
reg_mock = MagicMock(return_value={"vdata": "salt"})
with patch.dict(win_system.__salt__, {"reg.read_value": reg_mock}):
with patch.dict(win_system.__utils__, {"reg.read_value": reg_mock}):
self.assertFalse(win_system.get_pending_computer_name())

reg_mock = MagicMock(return_value={"vdata": "salt_pending"})
with patch.dict(win_system.__salt__, {"reg.read_value": reg_mock}):
with patch.dict(win_system.__utils__, {"reg.read_value": reg_mock}):
self.assertEqual(win_system.get_pending_computer_name(), "salt_pending")

@skipIf(not win_system.HAS_WIN32NET_MODS, "Missing win32 libraries")
def test_get_pending_file_rename_no_key(self):
"""
Test to get a pending file rename, keys don't exist. Should return False
"""
reg_mock = MagicMock(return_value={"success": False})
with patch.dict(win_system.__utils__, {"reg.read_value": reg_mock}):
self.assertFalse(win_system.get_pending_file_rename())

@skipIf(not win_system.HAS_WIN32NET_MODS, "Missing win32 libraries")
def test_get_pending_file_rename_key_no_value(self):
"""
Test to get a pending file rename, keys exist but not set. Should return
False
"""
reg_mock = MagicMock(return_value={"success": True, "vdata": "(value not set)"})
with patch.dict(win_system.__utils__, {"reg.read_value": reg_mock}):
self.assertFalse(win_system.get_pending_file_rename())

@skipIf(not win_system.HAS_WIN32NET_MODS, "Missing win32 libraries")
def test_get_pending_file_rename_key_present_value_set(self):
"""
Test to get a pending file rename, keys exist and value set. Should
return True
"""
reg_mock = MagicMock(return_value={"success": True, "vdata": "something"})
with patch.dict(win_system.__utils__, {"reg.read_value": reg_mock}):
self.assertTrue(win_system.get_pending_file_rename())

@skipIf(not win_system.HAS_WIN32NET_MODS, "Missing win32 libraries")
def test_get_pending_servermanager_key_not_present(self):
"""
Test to get pending servermanager, key not present. Should return False
"""
reg_mock = MagicMock(return_value={"success": False})
with patch.dict(win_system.__utils__, {"reg.read_value": reg_mock}):
self.assertFalse(win_system.get_pending_servermanager())

@skipIf(not win_system.HAS_WIN32NET_MODS, "Missing win32 libraries")
def test_get_pending_servermanager_key_present_not_int(self):
"""
Test to get pending servermanager, key present, value not int. Should
return False
"""
reg_mock = MagicMock(return_value={"success": True, "vdata": "(value not set)"})
with patch.dict(win_system.__utils__, {"reg.read_value": reg_mock}):
self.assertFalse(win_system.get_pending_servermanager())

@skipIf(not win_system.HAS_WIN32NET_MODS, "Missing win32 libraries")
def test_get_pending_servermanager_key_present_int_0(self):
"""
Test to get pending servermanager, key present, value is int 0. Should
return False
"""
reg_mock = MagicMock(return_value={"success": True, "vdata": 0})
with patch.dict(win_system.__utils__, {"reg.read_value": reg_mock}):
self.assertFalse(win_system.get_pending_servermanager())

@skipIf(not win_system.HAS_WIN32NET_MODS, "Missing win32 libraries")
def test_get_pending_servermanager_key_present_int_1(self):
"""
Test to get pending servermanager, key present, value is int 1. Should
return True
"""
reg_mock = MagicMock(return_value={"success": True, "vdata": 1})
with patch.dict(win_system.__utils__, {"reg.read_value": reg_mock}):
self.assertTrue(win_system.get_pending_servermanager())

@skipIf(not win_system.HAS_WIN32NET_MODS, "Missing win32 libraries")
def test_set_reboot_required_witnessed(self):
"""
Test set_reboot_required_witnessed, Should return True
"""
reg_mock = MagicMock(return_value=True)
with patch.dict(win_system.__utils__, {"reg.set_value": reg_mock}):
self.assertTrue(win_system.set_reboot_required_witnessed())

@skipIf(not win_system.HAS_WIN32NET_MODS, "Missing win32 libraries")
def test_get_reboot_required_witnessed_false(self):
"""
Test get_reboot_required_witnessed, not witnessed. Should return False
"""
reg_mock = MagicMock(return_value={"success": False, "vdata": None})
with patch.dict(win_system.__utils__, {"reg.read_value": reg_mock}):
self.assertFalse(win_system.get_reboot_required_witnessed())

@skipIf(not win_system.HAS_WIN32NET_MODS, "Missing win32 libraries")
def test_get_reboot_required_witnessed_true(self):
"""
Test get_reboot_required_witnessed, witnessed. Should return True
"""
reg_mock = MagicMock(return_value={"success": True, "vdata": 1})
with patch.dict(win_system.__utils__, {"reg.read_value": reg_mock}):
self.assertTrue(win_system.get_reboot_required_witnessed())

@skipIf(not win_system.HAS_WIN32NET_MODS, "Missing win32 libraries")
def test_get_computer_name(self):
"""
Expand Down

0 comments on commit ff3b690

Please sign in to comment.