Commit 46b973bd authored by Lluis Gifre Renom's avatar Lluis Gifre Renom
Browse files

Tests - Tools - Mock NCE-T Controller

- Corrected xPath=>restconf paths
parent 74384a73
Loading
Loading
Loading
Loading
+7 −19
Original line number Diff line number Diff line
@@ -64,19 +64,19 @@ class YangHandler:
        data = self._datastore.find_path(path)
        if data is None: return None
        json_data = data.print_mem(
            fmt='json', with_siblings=True, pretty=True,
            keep_empty_containers=True, include_implicit_defaults=True
            fmt='json', with_siblings=False, pretty=True,
            keep_empty_containers=False, include_implicit_defaults=True
        )
        return json_data

    def get_xpath(self, xpath : str) -> List[str]:
        if not xpath.startswith('/'): xpath = '/' + xpath
        nodes = self._datastore.find_all(xpath)
        items = self._datastore.find_all(xpath)
        result = list()
        for node in nodes:
            result.append(node.print_mem(
                fmt='json', with_siblings=True, pretty=True,
                keep_empty_containers=True, include_implicit_defaults=True
        for item in items:
            result.append(item.print_mem(
                fmt='json', with_siblings=False, pretty=True,
                keep_empty_containers=False, include_implicit_defaults=True
            ))
        return result

@@ -88,7 +88,6 @@ class YangHandler:
            validate_present=True, validate_multi_error=True
        )
        if dnode_parsed is None: raise Exception('Unable to parse Data({:s})'.format(str(payload)))
        #LOGGER.info('parsed = {:s}'.format(json.dumps(dnode.print_dict())))

        dnode : Optional[libyang.DNode] = self._yang_context.create_data_path(
            path, parent=self._datastore, value=dnode_parsed, update=False
@@ -109,7 +108,6 @@ class YangHandler:
            validate_present=True, validate_multi_error=True
        )
        if dnode_parsed is None: raise Exception('Unable to parse Data({:s})'.format(str(payload)))
        #LOGGER.info('parsed = {:s}'.format(json.dumps(dnode.print_dict())))

        dnode = self._yang_context.create_data_path(
            path, parent=self._datastore, value=dnode_parsed, update=True
@@ -166,7 +164,6 @@ class YangHandler:
                # use local name (without module prefix) to lookup schema
                local_name = name.split(':', 1)[1] if ':' in name else name
                schema_path = schema_path + '/' + local_name if schema_path else '/' + local_name
                LOGGER.info('[_normalize_path] schema_path={:s}'.format(str(schema_path)))
                schema_nodes = list(self._yang_context.find_path(schema_path))
                if len(schema_nodes) != 1:
                    MSG = 'No/Multiple SchemaNodes({:s}) for SchemaPath({:s})'
@@ -174,7 +171,6 @@ class YangHandler:
                        str([repr(sn) for sn in schema_nodes]), schema_path
                    ))
                schema_node = schema_nodes[0]
                LOGGER.info('[_normalize_path] schema_node={:s}'.format(str(repr(schema_node))))

                # parse values splitting on commas outside quotes
                values = []
@@ -196,30 +192,22 @@ class YangHandler:
                key_names = None
                if isinstance(schema_node, libyang.SList):
                    key_names = [k.name() for k in schema_node.keys()]
                    LOGGER.info('[_normalize_path] [SList] key_names={:s}'.format(str(key_names)))
                    #if isinstance(keys, (list, tuple)):
                    #    key_names = keys
                    #    LOGGER.info('[_normalize_path] key_names={:s}'.format(str(key_names)))
                    #elif isinstance(keys, str):
                    #    key_names = [kn for kn in k.split() if kn]
                    #    LOGGER.info('[_normalize_path] 1 key_names={:s}'.format(str(key_names)))
                #else:
                #    MSG = 'Unsupported keys format: {:s} / {:s}'
                #    raise Exception(MSG.format(str(type(keys)), str(keys)))
                #elif hasattr(schema_node, 'key'):
                #    LOGGER.info('[_normalize_path] has key')
                #    k = schema_node.key()
                #    LOGGER.info('[_normalize_path] k={:s}'.format(str(k)))
                #    if isinstance(k, str):
                #        key_names = [kn for kn in k.split() if kn]
                #        LOGGER.info('[_normalize_path] 3 key_names={:s}'.format(str(key_names)))

                if not key_names:
                    # fallback: use the local list name as the single key
                    key_names = [local_name]

                LOGGER.info('[_normalize_path] 5 key_names={:s}'.format(str(key_names)))

                # build predicate(s)
                preds = []
                for idx, kn in enumerate(key_names):