From 29db9b6e22f079e638b80032ce0d8f59c8987d5a Mon Sep 17 00:00:00 2001 From: rherrell Date: Sun, 3 Aug 2025 17:16:06 -0600 Subject: [PATCH 1/3] fixed several pytest failures Signed-off-by: rherrell --- Makefile | 4 +++- sunfish/lib/core.py | 7 +++++-- .../events_handlers/redfish/redfish_event_handler.py | 4 +++- .../sunfish_agent/sunfish_agent_manager.py | 5 +++-- tests/conf.json | 3 ++- tests/conf_broken_module.json | 3 ++- tests/test_sunfishcore_library.py | 7 ++++++- 7 files changed, 24 insertions(+), 9 deletions(-) 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 From d7f22dd8c4d2cf3d0b758cd9677f1d418ec89c64 Mon Sep 17 00:00:00 2001 From: rherrell Date: Thu, 7 Aug 2025 12:51:07 -0600 Subject: [PATCH 2/3] fixed last two tests, updated to latest Main changes Signed-off-by: rherrell --- Resources/Systems/index.json | 5 +++-- .../sunfish_agent/agents_management.py | 3 ++- .../sunfish_agent/sunfish_agent_manager.py | 15 +++++++++------ 3 files changed, 14 insertions(+), 9 deletions(-) mode change 100644 => 100755 Resources/Systems/index.json diff --git a/Resources/Systems/index.json b/Resources/Systems/index.json old mode 100644 new mode 100755 index 5020a95..35ee9cd --- a/Resources/Systems/index.json +++ b/Resources/Systems/index.json @@ -1,7 +1,8 @@ { + "@Redfish.Copyright": "Copyright 2014-2021 DMTF. For the full DMTF copyright policy, see http://www.dmtf.org/about/policies/copyright.", "@odata.id": "/redfish/v1/Systems", - "@odata.type": "#SystemsCollection.SystemsCollection", + "@odata.type": "#ComputerSystemCollection.ComputerSystemCollection", "Members": [], "Members@odata.count": 0, - "Name": "Systems Collection" + "Name": "Computer System Collection" } \ No newline at end of file diff --git a/sunfish_plugins/objects_managers/sunfish_agent/agents_management.py b/sunfish_plugins/objects_managers/sunfish_agent/agents_management.py index 3dd21a1..c8e3c28 100644 --- a/sunfish_plugins/objects_managers/sunfish_agent/agents_management.py +++ b/sunfish_plugins/objects_managers/sunfish_agent/agents_management.py @@ -12,6 +12,7 @@ from sunfish.lib.exceptions import AgentForwardingFailure from sunfish.models.types import * import sunfish +import pdb logger = logging.getLogger(__name__) @@ -82,8 +83,8 @@ def _forward_get_request(self, path: string) -> dict: raise e def _forward_create_request(self, path: string, payload: dict) -> dict: + #pdb.set_trace() resource_uri = str(self.aggregation_source["HostName"]) + "/" + path - #resource_uri = agent_uri+ "/" + path logger.debug(f"Forwarding resource CREATE request {resource_uri}") try: 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 6ea9f0c..070f353 100644 --- a/sunfish_plugins/objects_managers/sunfish_agent/sunfish_agent_manager.py +++ b/sunfish_plugins/objects_managers/sunfish_agent/sunfish_agent_manager.py @@ -48,12 +48,15 @@ def forward_to_manager(self, request_type: 'sunfish.models.types.SunfishRequestT # get the parent path logger.debug(f"Checking managing agent for path: {path_to_check}") agent = Agent.is_agent_managed(self.core, path_to_check) - print(f"managing agent is {agent}") if agent: logger.debug(f"{path} is managed by an agent, forwarding the request") - obj_modified = self.xlateToAgentURIs(payload) - # extract restored name from payload - restored_path = payload["@odata.id"] + # if no payload, cannot xlateToAgent + if payload is not None: + obj_modified = self.xlateToAgentURIs(payload) + # extract restored name from payload + restored_path = payload["@odata.id"] + else: + restored_path = path try: agent_response = agent.forward_request(request_type, restored_path, payload=payload) except AgentForwardingFailure as e: @@ -119,12 +122,12 @@ def findNestedURIs(self, URI_to_match, URI_to_sub, obj, path_to_nested_URI): try: uri_alias_file = os.path.join(os.getcwd(), self.core.conf["backend_conf"]["fs_private"], 'URI_aliases.json') if os.path.exists(uri_alias_file): - print(f"reading alias file {uri_alias_file}") + logging.debug(f"reading alias file {uri_alias_file}") with open(uri_alias_file, 'r') as data_json: uri_aliasDB = json.load(data_json) data_json.close() else: - print(f"alias file {uri_alias_file} not found") + logging.debug(f"alias file {uri_alias_file} not found") #no alias file, so we are done, no modifications done return False From 1ae8343b01057a416ccc3eaf4ca06029cf26c882 Mon Sep 17 00:00:00 2001 From: rherrell Date: Fri, 8 Aug 2025 08:39:58 -0600 Subject: [PATCH 3/3] removed print statements Signed-off-by: rherrell --- tests/test_sunfishcore_library.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/tests/test_sunfishcore_library.py b/tests/test_sunfishcore_library.py index 5c986a3..ae2b453 100644 --- a/tests/test_sunfishcore_library.py +++ b/tests/test_sunfishcore_library.py @@ -153,7 +153,7 @@ def test_event_forwarding_exception(self, httpserver: HTTPServer): def test_event_forwarding_2(self, httpserver: HTTPServer): httpserver.expect_request("/").respond_with_data("OK") resp = self.core.handle_event(tests_template.event_resource_type_system) - print('RESP ', resp) + #print('RESP ', resp) assert len(resp) == 1 def test_resource_created_event_no_context_exception(self): @@ -169,11 +169,8 @@ def test_agent_create_forwarding(self, httpserver: HTTPServer): 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