Fixed error when attempted to GET config data containing state data subnodes

parent f7355834
...@@ -384,6 +384,7 @@ class BaseDatastore: ...@@ -384,6 +384,7 @@ class BaseDatastore:
if state_roots and not yl_data: if state_roots and not yl_data:
debug_data("State roots: {}".format(state_roots)) debug_data("State roots: {}".format(state_roots))
for state_root_sch_pth in state_roots: for state_root_sch_pth in state_roots:
state_root_sn = self._dm.get_data_node(state_root_sch_pth) state_root_sn = self._dm.get_data_node(state_root_sch_pth)
...@@ -414,6 +415,11 @@ class BaseDatastore: ...@@ -414,6 +415,11 @@ class BaseDatastore:
# Select desired subnode from handler-generated content # Select desired subnode from handler-generated content
ii_prefix, ii_rel = sdh.schema_node.split_instance_route(ii) ii_prefix, ii_rel = sdh.schema_node.split_instance_route(ii)
n = state_root_n.goto(ii_rel) n = state_root_n.goto(ii_rel)
# There should be only one state root, no need to continue
if len(state_roots) != 1:
warn("URI points to directly to state data, but more state roots found")
break
else: else:
raise NoHandlerForStateDataError(rpc.path) raise NoHandlerForStateDataError(rpc.path)
else: else:
...@@ -425,16 +431,25 @@ class BaseDatastore: ...@@ -425,16 +431,25 @@ class BaseDatastore:
if node.schema_node is state_root_sn.parent: if node.schema_node is state_root_sn.parent:
ii_gen = DataHelpers.node_get_ii(node) ii_gen = DataHelpers.node_get_ii(node)
sdh = STATE_DATA_HANDLES.get_handler(state_root_sch_pth) sdh = STATE_DATA_HANDLES.get_handler(state_root_sch_pth)
# print(state_root_sch_pth)
if sdh is not None: if sdh is not None:
if isinstance(sdh, ContainerNodeHandlerBase): try:
state_handler_val = sdh.generate_node(ii_gen, rpc.username, staging) if isinstance(sdh, ContainerNodeHandlerBase):
elif isinstance(sdh, ListNodeHandlerBase): state_handler_val = sdh.generate_node(ii_gen, rpc.username, staging)
print("node={}".format(node)) elif isinstance(sdh, ListNodeHandlerBase):
print("iigen={}".format(ii_gen)) state_handler_val = sdh.generate_list(ii_gen, rpc.username, staging)
state_handler_val = sdh.generate_item(ii_gen, rpc.username, staging) except Exception as e:
error("Error occured in state data generator (sn: {})".format(state_root_sch_pth))
nm_name = state_root_sn.qual_name[0] error(epretty(e))
node = node.put_member(nm_name, state_handler_val, raw=True).up() error("This state node will be omitted.")
else:
if state_root_sn.ns == state_root_sn.parent.ns:
nm_name = state_root_sn.qual_name[0]
else:
nm_name = state_root_sn.qual_name[1] + ":" + state_root_sn.qual_name[0]
# print("nm={}".format(nm_name))
node = node.put_member(nm_name, state_handler_val, raw=True).up()
else: else:
for key in node: for key in node:
member = node[key] member = node[key]
...@@ -449,6 +464,7 @@ class BaseDatastore: ...@@ -449,6 +464,7 @@ class BaseDatastore:
return node return node
n = _fill_state_roots(n) n = _fill_state_roots(n)
root = n.top()
else: else:
n = root.goto(ii) n = root.goto(ii)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment