diff --git a/Makefile b/Makefile index cb982ae..20223a2 100644 --- a/Makefile +++ b/Makefile @@ -7,7 +7,9 @@ all: build build: poetry build -test: +test: + rm -rf ./Resources + cp -rp ./tests/Resources . python3 -m pytest tests/test_sunfishcore_library.py -vvvv clean: diff --git a/sunfish/lib/core.py b/sunfish/lib/core.py index 27d7f79..0701690 100644 --- a/sunfish/lib/core.py +++ b/sunfish/lib/core.py @@ -6,6 +6,7 @@ import string import uuid import logging +import pdb from sunfish.lib.exceptions import CollectionNotSupported, ResourceNotFound, AgentForwardingFailure, PropertyNotFound @@ -201,16 +202,18 @@ def create_object(self, path: string, payload: dict): raise CollectionNotSupported() payload_to_write = payload + #pdb.set_trace() try: # 1. check the path target of the operation exists # self.storage_backend.read(path) + # above done elsewhere, too soon to do here # 2. is needed first forward the request to the agent managing the object agent_response = self.objects_manager.forward_to_manager(SunfishRequestType.CREATE, path, payload=payload) if agent_response: payload_to_write = agent_response - # 3. Execute any custom handler for this object type - self.objects_handler.dispatch(object_type, path, SunfishRequestType.CREATE, payload=payload) + # 3. Execute any custom handler for this object type AFTER Agent mods, if any + self.objects_handler.dispatch(object_type, path, SunfishRequestType.CREATE, payload=payload_to_write) except ResourceNotFound: logger.error("The collection where the resource is to be created does not exist.") except AgentForwardingFailure as e: diff --git a/sunfish_plugins/events_handlers/redfish/redfish_event_handler.py b/sunfish_plugins/events_handlers/redfish/redfish_event_handler.py index 3cb258b..99b8623 100644 --- a/sunfish_plugins/events_handlers/redfish/redfish_event_handler.py +++ b/sunfish_plugins/events_handlers/redfish/redfish_event_handler.py @@ -132,7 +132,9 @@ def ResourceCreated(cls, event_handler: EventHandlerInterface, event: dict, cont # patch the aggregation_source object in storage with all the new resources found - event_handler.core.storage_backend.patch(id, aggregation_source) + #pdb.set_trace() + event_handler.core.storage_backend.patch(agg_src_path, aggregation_source) + logger.debug(f"\n{json.dumps(aggregation_source, indent=4)}") return 200 @classmethod diff --git a/sunfish_plugins/objects_managers/sunfish_agent/sunfish_agent_manager.py b/sunfish_plugins/objects_managers/sunfish_agent/sunfish_agent_manager.py index 3d86441..6ea9f0c 100644 --- a/sunfish_plugins/objects_managers/sunfish_agent/sunfish_agent_manager.py +++ b/sunfish_plugins/objects_managers/sunfish_agent/sunfish_agent_manager.py @@ -125,7 +125,8 @@ def findNestedURIs(self, URI_to_match, URI_to_sub, obj, path_to_nested_URI): data_json.close() else: print(f"alias file {uri_alias_file} not found") - raise Exception + #no alias file, so we are done, no modifications done + return False except: raise Exception @@ -208,7 +209,7 @@ def findNestedURIs(self, URI_to_match, URI_to_sub, obj, path_to_nested_URI): data_json.close() else: print(f"alias file {uri_alias_file} not found") - raise Exception + return False except: raise Exception diff --git a/tests/conf.json b/tests/conf.json index 4c895dd..57f09e8 100644 --- a/tests/conf.json +++ b/tests/conf.json @@ -6,6 +6,7 @@ }, "backend_conf" : { "fs_root": "Resources", + "fs_private": "SunfishPrivate", "subscribers_root": "EventService/Subscriptions" }, "events_handler": { @@ -20,4 +21,4 @@ "module_name": "objects_handlers.sunfish_server.redfish_object_handler", "class_name": "RedfishObjectHandler" } -} \ No newline at end of file +} diff --git a/tests/conf_broken_module.json b/tests/conf_broken_module.json index 17f3449..222d9f2 100644 --- a/tests/conf_broken_module.json +++ b/tests/conf_broken_module.json @@ -6,6 +6,7 @@ }, "backend_conf" : { "fs_root": "Resources", + "fs_private": "SunfishPrivate", "subscribers_root": "EventService/Subscriptions" }, "event_handler": { @@ -16,4 +17,4 @@ "subscription_handler": "redfish", "event_handler": "redfish" } -} \ No newline at end of file +} diff --git a/tests/test_sunfishcore_library.py b/tests/test_sunfishcore_library.py index 18c6c5a..5c986a3 100644 --- a/tests/test_sunfishcore_library.py +++ b/tests/test_sunfishcore_library.py @@ -137,6 +137,7 @@ def test_subscription(self): @pytest.fixture(scope="session") def httpserver_listen_address(self): return ("localhost", 8080) + #return ("127.0.0.1", 8080) def test_event_forwarding(self, httpserver: HTTPServer): httpserver.expect_request("/").respond_with_data("OK") @@ -163,12 +164,16 @@ def test_agent_create_forwarding(self, httpserver: HTTPServer): aggr_source_path = os.path.join(self.conf['redfish_root'], "AggregationService/AggregationSources") fabrics_path = os.path.join(self.conf['redfish_root'], "Fabrics") connection_path = os.path.join(self.conf['redfish_root'], "Fabrics/CXL/Connections") - httpserver.expect_request(connection_path, method="POST").respond_with_json( + connection_uri = os.path.join(self.conf['redfish_root'], "Fabrics/CXL/Connections/12") + httpserver.expect_request(connection_uri, method="POST").respond_with_json( tests_template.test_connection_cxl_fabric) resp = self.core.storage_backend.write(tests_template.aggregation_source) + print(f'resp1 = {resp}\n') resp = self.core.storage_backend.write(tests_template.test_fabric) + print(f'resp2 = {resp}\n') resp = self.core.create_object(connection_path, tests_template.test_connection_cxl_fabric) + print(f'resp3 = {resp}\n') assert resp == tests_template.test_response_connection_cxl_fabric