Skip to content

Commit 7abc36f

Browse files
authored
Rwh cxl agent fabric merge (#44)
fixed the last of the pytest failures, removed some debug and print statements. --------- Signed-off-by: rherrell <russ.herrell@hpe.com>
1 parent cef26b7 commit 7abc36f

File tree

9 files changed

+36
-19
lines changed

9 files changed

+36
-19
lines changed

Makefile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ all: build
77
build:
88
poetry build
99

10-
test:
10+
test:
11+
rm -rf ./Resources
12+
cp -rp ./tests/Resources .
1113
python3 -m pytest tests/test_sunfishcore_library.py -vvvv
1214

1315
clean:

Resources/Systems/index.json

100644100755
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
{
2+
"@Redfish.Copyright": "Copyright 2014-2021 DMTF. For the full DMTF copyright policy, see http://www.dmtf.org/about/policies/copyright.",
23
"@odata.id": "/redfish/v1/Systems",
3-
"@odata.type": "#SystemsCollection.SystemsCollection",
4+
"@odata.type": "#ComputerSystemCollection.ComputerSystemCollection",
45
"Members": [],
56
"Members@odata.count": 0,
6-
"Name": "Systems Collection"
7+
"Name": "Computer System Collection"
78
}

sunfish/lib/core.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import string
77
import uuid
88
import logging
9+
import pdb
910

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

@@ -201,16 +202,18 @@ def create_object(self, path: string, payload: dict):
201202
raise CollectionNotSupported()
202203

203204
payload_to_write = payload
205+
#pdb.set_trace()
204206

205207
try:
206208
# 1. check the path target of the operation exists
207209
# self.storage_backend.read(path)
210+
# above done elsewhere, too soon to do here
208211
# 2. is needed first forward the request to the agent managing the object
209212
agent_response = self.objects_manager.forward_to_manager(SunfishRequestType.CREATE, path, payload=payload)
210213
if agent_response:
211214
payload_to_write = agent_response
212-
# 3. Execute any custom handler for this object type
213-
self.objects_handler.dispatch(object_type, path, SunfishRequestType.CREATE, payload=payload)
215+
# 3. Execute any custom handler for this object type AFTER Agent mods, if any
216+
self.objects_handler.dispatch(object_type, path, SunfishRequestType.CREATE, payload=payload_to_write)
214217
except ResourceNotFound:
215218
logger.error("The collection where the resource is to be created does not exist.")
216219
except AgentForwardingFailure as e:

sunfish_plugins/events_handlers/redfish/redfish_event_handler.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,9 @@ def ResourceCreated(cls, event_handler: EventHandlerInterface, event: dict, cont
132132

133133

134134
# patch the aggregation_source object in storage with all the new resources found
135-
event_handler.core.storage_backend.patch(id, aggregation_source)
135+
#pdb.set_trace()
136+
event_handler.core.storage_backend.patch(agg_src_path, aggregation_source)
137+
logger.debug(f"\n{json.dumps(aggregation_source, indent=4)}")
136138
return 200
137139

138140
@classmethod

sunfish_plugins/objects_managers/sunfish_agent/agents_management.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from sunfish.lib.exceptions import AgentForwardingFailure
1313
from sunfish.models.types import *
1414
import sunfish
15+
import pdb
1516

1617
logger = logging.getLogger(__name__)
1718

@@ -82,8 +83,8 @@ def _forward_get_request(self, path: string) -> dict:
8283
raise e
8384

8485
def _forward_create_request(self, path: string, payload: dict) -> dict:
86+
#pdb.set_trace()
8587
resource_uri = str(self.aggregation_source["HostName"]) + "/" + path
86-
#resource_uri = agent_uri+ "/" + path
8788

8889
logger.debug(f"Forwarding resource CREATE request {resource_uri}")
8990
try:

sunfish_plugins/objects_managers/sunfish_agent/sunfish_agent_manager.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,15 @@ def forward_to_manager(self, request_type: 'sunfish.models.types.SunfishRequestT
4848
# get the parent path
4949
logger.debug(f"Checking managing agent for path: {path_to_check}")
5050
agent = Agent.is_agent_managed(self.core, path_to_check)
51-
print(f"managing agent is {agent}")
5251
if agent:
5352
logger.debug(f"{path} is managed by an agent, forwarding the request")
54-
obj_modified = self.xlateToAgentURIs(payload)
55-
# extract restored name from payload
56-
restored_path = payload["@odata.id"]
53+
# if no payload, cannot xlateToAgent
54+
if payload is not None:
55+
obj_modified = self.xlateToAgentURIs(payload)
56+
# extract restored name from payload
57+
restored_path = payload["@odata.id"]
58+
else:
59+
restored_path = path
5760
try:
5861
agent_response = agent.forward_request(request_type, restored_path, payload=payload)
5962
except AgentForwardingFailure as e:
@@ -119,13 +122,14 @@ def findNestedURIs(self, URI_to_match, URI_to_sub, obj, path_to_nested_URI):
119122
try:
120123
uri_alias_file = os.path.join(os.getcwd(), self.core.conf["backend_conf"]["fs_private"], 'URI_aliases.json')
121124
if os.path.exists(uri_alias_file):
122-
print(f"reading alias file {uri_alias_file}")
125+
logging.debug(f"reading alias file {uri_alias_file}")
123126
with open(uri_alias_file, 'r') as data_json:
124127
uri_aliasDB = json.load(data_json)
125128
data_json.close()
126129
else:
127-
print(f"alias file {uri_alias_file} not found")
128-
raise Exception
130+
logging.debug(f"alias file {uri_alias_file} not found")
131+
#no alias file, so we are done, no modifications done
132+
return False
129133

130134
except:
131135
raise Exception
@@ -208,7 +212,7 @@ def findNestedURIs(self, URI_to_match, URI_to_sub, obj, path_to_nested_URI):
208212
data_json.close()
209213
else:
210214
print(f"alias file {uri_alias_file} not found")
211-
raise Exception
215+
return False
212216

213217
except:
214218
raise Exception

tests/conf.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
},
77
"backend_conf" : {
88
"fs_root": "Resources",
9+
"fs_private": "SunfishPrivate",
910
"subscribers_root": "EventService/Subscriptions"
1011
},
1112
"events_handler": {
@@ -20,4 +21,4 @@
2021
"module_name": "objects_handlers.sunfish_server.redfish_object_handler",
2122
"class_name": "RedfishObjectHandler"
2223
}
23-
}
24+
}

tests/conf_broken_module.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
},
77
"backend_conf" : {
88
"fs_root": "Resources",
9+
"fs_private": "SunfishPrivate",
910
"subscribers_root": "EventService/Subscriptions"
1011
},
1112
"event_handler": {
@@ -16,4 +17,4 @@
1617
"subscription_handler": "redfish",
1718
"event_handler": "redfish"
1819
}
19-
}
20+
}

tests/test_sunfishcore_library.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ def test_subscription(self):
137137
@pytest.fixture(scope="session")
138138
def httpserver_listen_address(self):
139139
return ("localhost", 8080)
140+
#return ("127.0.0.1", 8080)
140141

141142
def test_event_forwarding(self, httpserver: HTTPServer):
142143
httpserver.expect_request("/").respond_with_data("OK")
@@ -152,7 +153,7 @@ def test_event_forwarding_exception(self, httpserver: HTTPServer):
152153
def test_event_forwarding_2(self, httpserver: HTTPServer):
153154
httpserver.expect_request("/").respond_with_data("OK")
154155
resp = self.core.handle_event(tests_template.event_resource_type_system)
155-
print('RESP ', resp)
156+
#print('RESP ', resp)
156157
assert len(resp) == 1
157158

158159
def test_resource_created_event_no_context_exception(self):
@@ -163,7 +164,8 @@ def test_agent_create_forwarding(self, httpserver: HTTPServer):
163164
aggr_source_path = os.path.join(self.conf['redfish_root'], "AggregationService/AggregationSources")
164165
fabrics_path = os.path.join(self.conf['redfish_root'], "Fabrics")
165166
connection_path = os.path.join(self.conf['redfish_root'], "Fabrics/CXL/Connections")
166-
httpserver.expect_request(connection_path, method="POST").respond_with_json(
167+
connection_uri = os.path.join(self.conf['redfish_root'], "Fabrics/CXL/Connections/12")
168+
httpserver.expect_request(connection_uri, method="POST").respond_with_json(
167169
tests_template.test_connection_cxl_fabric)
168170

169171
resp = self.core.storage_backend.write(tests_template.aggregation_source)

0 commit comments

Comments
 (0)