Skip to content

Commit

Permalink
added plugin loading test
Browse files Browse the repository at this point in the history
Signed-off-by: Christian Pinto <christian.pinto@ibm.com>
  • Loading branch information
christian-pinto committed Jun 25, 2024
1 parent c1d1a8c commit 8c08af2
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
6 changes: 5 additions & 1 deletion sunfish/models/plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@
def load_plugin(plugin: dict):
module_name = f"{plugins_namespace_name}.{plugin['module_name']}"
logger.info(f"Loading plugin {module_name}...")
plugin_module = importlib.import_module(module_name)
try:
plugin_module = importlib.import_module(module_name)
except ModuleNotFoundError as e:
logger.error(f"Plugin module {module_name} does not exist")
raise e
logger.info("Plugin loaded")
return getattr(plugin_module, plugin["class_name"])

19 changes: 19 additions & 0 deletions tests/conf_broken_module.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"redfish_root": "/redfish/v1/",
"storage_backend": {
"module_name": "wrong.module.for.test",
"class_name": "BackendFS"
},
"backend_conf" : {
"fs_root": "Resources",
"subscribers_root": "EventService/Subscriptions"
},
"event_handler": {
"module_name": "event_handlers.redfish.redfish_event_handler",
"class_name": "RedfishEventHandler"
},
"handlers": {
"subscription_handler": "redfish",
"event_handler": "redfish"
}
}
12 changes: 12 additions & 0 deletions tests/test_sunfishcore_library.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,18 @@ def test_init_core(self):

core = Core(conf)

@pytest.mark.order("second")
def test_init_core_wrong_plugin(self):
path = os.path.join(os.getcwd(), 'tests', 'conf_broken_module.json')
try:
json_data = open(path)
conf = json.load(json_data)
except FileNotFoundError as e:
raise ResourceNotFound('conf.json')
with pytest.raises(ModuleNotFoundError):
core = Core(conf)


# TEST REST
# Delete
@pytest.mark.order("last")
Expand Down

0 comments on commit 8c08af2

Please sign in to comment.