Commit 048ba67f authored by Waleed Akbar's avatar Waleed Akbar
Browse files

fix: Update discover_link_details to handle network-level request

parent 9aa27391
Loading
Loading
Loading
Loading
+25 −15
Original line number Diff line number Diff line
@@ -62,24 +62,34 @@ def discover_link_details(restconf_client : RestConfClient, xpath_filter : str)
    network_id, link_id = link_xpath_match.groups()
    link_details = LinkDetails(Link(network_id, link_id))

    xpath_filter = link_details.link.get_xpath_filter(add_simap_telemetry=False)
    xpath_data = restconf_client.get(xpath_filter)
    # Workaround: RESTCONF server doesn't support namespace-prefixed child element paths
    # Query at network level and filter the link from response
    network_xpath = '/ietf-network:networks/network={:s}'.format(network_id)
    xpath_data = restconf_client.get(network_xpath)
    if not xpath_data:
        raise Exception('Resource({:s}) not found in SIMAP Server'.format(str(xpath_filter)))

    links = xpath_data.get('ietf-network-topology:link', list())
    if len(links) == 0:
        raise Exception('Link({:s}) not found'.format(str(xpath_filter)))
    if len(links) >  1:
        raise Exception('Multiple occurrences for Link({:s})'.format(str(xpath_filter)))
    link = links[0]
    if link['link-id'] != link_id:
        MSG = 'Retieved Link({:s}) does not match xpath_filter({:s})'
        raise Exception(MSG.format(str(link), str(xpath_filter)))
        raise Exception('Network({:s}) not found in SIMAP Server'.format(str(network_xpath)))

    # Extract network data from response
    networks = xpath_data.get('ietf-network:network', [])
    if len(networks) == 0:
        raise Exception('Network({:s}) not found in response'.format(network_id))
    network_data = networks[0]

    # Find the target link
    links = network_data.get('ietf-network-topology:link', list())
    link = None
    for l in links:
        if l['link-id'] == link_id:
            link = l
            break
    
    if link is None:
        raise Exception('Link({:s}) not found in network({:s})'.format(link_id, network_id))
    
    supporting_links = link.get('supporting-link', list())
    if len(supporting_links) == 0:
        MSG = 'No supporting links found for Resource({:s}, {:s})'
        raise Exception(MSG.format(str(xpath_filter), str(xpath_data)))
        MSG = 'No supporting links found for Link({:s}) in Network({:s})'
        raise Exception(MSG.format(str(link_id), str(network_id)))

    for sup_link in supporting_links:
        link_details.supporting_links.append(Link(