Merge pull request #46429 from twangboy/win_fix_snmp

Fix problem with __virtual__ in win_snmp
This commit is contained in:
Nicole Thomas 2018-03-07 18:26:45 -05:00 committed by GitHub
commit 2bad0a21c0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 10 additions and 5 deletions

View file

@ -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]):

View file

@ -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__

View file

@ -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