mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Fix problem with __virtual__ in win_snmp
Exposes the `_key_exists` function in the reg.py module as `key_exists` Fixes an issue where `key_exists` was throwing an error when the key didn't exist Fixes a problem with the `broadcast_change` function in the `win_functions` salt util. It was using `unicode_literals` and those aren't implemented until 2018.3. The ctypes.WinDLL function is expecting a string value, not unicode Have the __virtual__ function for win_snmp use the `key_exists` function to detect the presence of the SNMP key in the registry. This will fail gracefully if it doesn't exist
This commit is contained in:
parent
ca6a76e317
commit
8995a9b8de
3 changed files with 10 additions and 5 deletions
|
@ -155,9 +155,10 @@ class Registry(object): # pylint: disable=R0903
|
|||
raise CommandExecutionError(msg.format(k, hkeys))
|
||||
|
||||
|
||||
def _key_exists(hive, key, use_32bit_registry=False):
|
||||
def key_exists(hive, key, use_32bit_registry=False):
|
||||
'''
|
||||
Check that the key is found in the registry
|
||||
Check that the key is found in the registry. This refers to keys and not
|
||||
value/data pairs.
|
||||
|
||||
:param str hive: The hive to connect to.
|
||||
:param str key: The key to check
|
||||
|
@ -179,6 +180,10 @@ def _key_exists(hive, key, use_32bit_registry=False):
|
|||
return True
|
||||
except WindowsError: # pylint: disable=E0602
|
||||
return False
|
||||
except pywintypes.error as exc:
|
||||
if exc.winerror == 2:
|
||||
return False
|
||||
raise
|
||||
|
||||
|
||||
def broadcast_change():
|
||||
|
@ -603,7 +608,7 @@ def delete_key_recursive(hive, key, use_32bit_registry=False):
|
|||
key_path = local_key
|
||||
access_mask = registry.registry_32[use_32bit_registry] | win32con.KEY_ALL_ACCESS
|
||||
|
||||
if not _key_exists(local_hive, local_key, use_32bit_registry):
|
||||
if not key_exists(local_hive, local_key, use_32bit_registry):
|
||||
return False
|
||||
|
||||
if (len(key) > 1) and (key.count('\\', 1) < registry.subkey_slash_check[hkey]):
|
||||
|
|
|
@ -45,7 +45,7 @@ def __virtual__():
|
|||
if not salt.utils.is_windows():
|
||||
return False, 'Module win_snmp: Requires Windows'
|
||||
|
||||
if not __salt__['reg.read_value'](_HKEY, _SNMP_KEY)['success']:
|
||||
if not __salt__['reg.key_exists'](_HKEY, _SNMP_KEY):
|
||||
return False, 'Module win_snmp: SNMP not installed'
|
||||
|
||||
return __virtualname__
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
Various functions to be used by windows during start up and to monkey patch
|
||||
missing functions in other modules
|
||||
'''
|
||||
from __future__ import absolute_import, unicode_literals
|
||||
from __future__ import absolute_import
|
||||
import platform
|
||||
import re
|
||||
import ctypes
|
||||
|
|
Loading…
Add table
Reference in a new issue