Skip to content
Merged
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
5 changes: 3 additions & 2 deletions Resources/Systems/index.json
100644 → 100755
Original file line number Diff line number Diff line change
@@ -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"
}
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 @@ -12,6 +12,7 @@
from sunfish.lib.exceptions import AgentForwardingFailure
from sunfish.models.types import *
import sunfish
import pdb

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -119,13 +122,14 @@ 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")
raise Exception
logging.debug(f"alias file {uri_alias_file} not found")
#no alias file, so we are done, no modifications done
return False

except:
raise Exception
Expand Down Expand Up @@ -208,7 +212,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"
}
}
}
6 changes: 4 additions & 2 deletions 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 @@ -152,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):
Expand All @@ -163,7 +164,8 @@ 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)
Expand Down