Coverage for libs/sm/plugins/__init__.py: 51%
31 statements
« prev ^ index » next coverage.py v7.3.2, created at 2026-07-10 07:59 +0000
« prev ^ index » next coverage.py v7.3.2, created at 2026-07-10 07:59 +0000
1import glob
2import importlib
3import os
4import sys
5import traceback
7from sm.core import util
9plugindir = os.path.dirname(__file__)
11plugins = []
14def _log_exn_backtrace():
15 for line in traceback.format_exc().splitlines():
16 util.SMlog(line)
18for file_name in glob.glob(os.path.join(plugindir, '*.py')):
19 # Avoid recursively loading this module again. The __file__ variable might
20 # have a .pyc extension, so we have to compare the filenames without
21 # extension:
22 if os.path.splitext(file_name)[0] == os.path.splitext(__file__)[0]:
23 continue
24 module_name = os.path.splitext(os.path.split(file_name)[-1])[0]
25 try:
26 module = importlib.import_module('{}.{}'.format(__name__, module_name))
27 plugins.append(module)
28 except:
29 # ignore and log module import errors
30 util.SMlog('Failed to load key lookup plugin {}'.format(module_name))
31 _log_exn_backtrace()
33def load_key(key_hash, vdi_uuid):
34 for plugin in plugins:
35 try:
36 key = plugin.load_key(key_hash, vdi_uuid)
37 if key:
38 return key
39 except:
40 # ignore and log plugin failures
41 util.SMlog('Key lookup plugin {} failed while loading key'
42 ' with hash {} for VDI {}'.format(
43 plugin.__name__, key_hash, vdi_uuid))
44 _log_exn_backtrace()
46 return None