-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CP-29955: Log failures in key lookup plugins
- Previously we did not log anything in the plugin manager when key lookup plugins were invoked or when they failed with an exception. So now I have added debug logs to the plugin manager that are written to SMlog. - Fixed how modules in the plugins directory are loaded. To avoid loading itself, the plugin manager compared each filename in its directory to the __file__ variable. However, sometimes this variable was __init__.pyc, not __init__.py, so the comparison returned false, and the key manager loaded itself recursively, which in turn tried to load the plugins again, but failed. - I've also removed some pylint warnings: I've converted the Logger class into a function, fixed indentation, and removed trailing whitespace. Signed-off-by: Gabor Igloi <gabor.igloi@citrix.com>
- Loading branch information
1 parent
68e087a
commit dbc9e54
Showing
2 changed files
with
49 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,54 @@ | ||
import glob | ||
import importlib | ||
import logging | ||
import logging.handlers | ||
import os | ||
import re | ||
import sys | ||
import traceback | ||
|
||
import util | ||
|
||
plugindir = os.path.dirname(__file__) | ||
|
||
plugins = [] | ||
|
||
def _log_exn_backtrace(): | ||
for line in traceback.format_exc().splitlines(): | ||
util.SMlog(line) | ||
|
||
for file_name in glob.glob(os.path.join(plugindir, '*.py')): | ||
if file_name == __file__: | ||
# Avoid recursively loading this module again. The __file__ variable might | ||
# have a .pyc extension, so we have to compare the filenames without | ||
# extension: | ||
if os.path.splitext(file_name)[0] == os.path.splitext(__file__)[0]: | ||
continue | ||
module_name = os.path.splitext(os.path.split(file_name)[-1])[0] | ||
try: | ||
module = importlib.import_module('{}.{}'.format(__name__, module_name)) | ||
plugins.append(module) | ||
util.SMlog('Loaded key lookup plugin {}'.format(module_name)) | ||
except: | ||
# ignore module import errors | ||
pass | ||
# ignore and log module import errors | ||
util.SMlog('Failed to load key lookup plugin {}'.format(module_name)) | ||
_log_exn_backtrace() | ||
|
||
def load_key(key_hash, vdi_uuid): | ||
for plugin in plugins: | ||
try: | ||
key = plugin.load_key(key_hash, vdi_uuid) | ||
if key: | ||
util.SMlog('Loaded key with hash {} for VDI {} using plugin {}'.format( | ||
key_hash, vdi_uuid, plugin.__name__)) | ||
return key | ||
else: | ||
util.SMlog('Plugin {} did not return a key for key hash {} and VDI {}'.format( | ||
plugin.__name__, key_hash, vdi_uuid)) | ||
except: | ||
# ignore plugin failures | ||
pass | ||
# ignore and log plugin failures | ||
util.SMlog('Key lookup plugin {} failed while loading key' | ||
' with hash {} for VDI {}'.format( | ||
plugin.__name__, key_hash, vdi_uuid)) | ||
_log_exn_backtrace() | ||
|
||
return None |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters