Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
7 changes: 5 additions & 2 deletions sunfish/lib/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import string
import uuid
import logging
import pdb

from sunfish.lib.exceptions import CollectionNotSupported, ResourceNotFound, AgentForwardingFailure, PropertyNotFound

Expand Down Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion tests/conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
},
"backend_conf" : {
"fs_root": "Resources",
"fs_private": "SunfishPrivate",
"subscribers_root": "EventService/Subscriptions"
},
"events_handler": {
Expand All @@ -20,4 +21,4 @@
"module_name": "objects_handlers.sunfish_server.redfish_object_handler",
"class_name": "RedfishObjectHandler"
}
}
}
3 changes: 2 additions & 1 deletion tests/conf_broken_module.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
},
"backend_conf" : {
"fs_root": "Resources",
"fs_private": "SunfishPrivate",
"subscribers_root": "EventService/Subscriptions"
},
"event_handler": {
Expand All @@ -16,4 +17,4 @@
"subscription_handler": "redfish",
"event_handler": "redfish"
}
}
}
7 changes: 6 additions & 1 deletion tests/test_sunfishcore_library.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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

Expand Down
Loading