X-Git-Url: https://gerrit.fd.io/r/gitweb?p=csit.git;a=blobdiff_plain;f=resources%2Flibraries%2Fpython%2Ftopology.py;h=8a591dfd140a3b7d6564e15094344934dc1a1e4e;hp=0b40967ef239a4943d899f43bd716af02e32ca37;hb=1813672eb9f6988046bc65167235ae37b088298c;hpb=99519a54811a70b4ff2579baf46294507a8adfcb diff --git a/resources/libraries/python/topology.py b/resources/libraries/python/topology.py index 0b40967ef2..8a591dfd14 100644 --- a/resources/libraries/python/topology.py +++ b/resources/libraries/python/topology.py @@ -18,7 +18,7 @@ from collections import Counter from yaml import load from robot.api import logger -from robot.libraries.BuiltIn import BuiltIn +from robot.libraries.BuiltIn import BuiltIn, RobotNotRunningError from robot.api.deco import keyword __all__ = ["DICT__nodes", 'Topology'] @@ -27,9 +27,12 @@ __all__ = ["DICT__nodes", 'Topology'] def load_topo_from_yaml(): """Load topology from file defined in "${TOPOLOGY_PATH}" variable. - :return: Nodes from loaded topology. + :returns: Nodes from loaded topology. """ - topo_path = BuiltIn().get_variable_value("${TOPOLOGY_PATH}") + try: + topo_path = BuiltIn().get_variable_value("${TOPOLOGY_PATH}") + except RobotNotRunningError: + return '' with open(topo_path) as work_file: return load(work_file.read())['nodes'] @@ -122,6 +125,19 @@ class Topology(object): """ node['interfaces'][iface_key]['vpp_sw_index'] = int(sw_if_index) + @staticmethod + def update_interface_name(node, iface_key, name): + """Update name on the interface from the node. + + :param node: Node to update name on. + :param iface_key: Topology key of the interface. + :param name: Interface name to store. + :type node: dict + :type iface_key: str + :type name: str + """ + node['interfaces'][iface_key]['name'] = str(name) + @staticmethod def update_interface_mac_address(node, iface_key, mac_address): """Update mac_address on the interface from the node. @@ -296,7 +312,7 @@ class Topology(object): try: if isinstance(iface_key, basestring): return node['interfaces'][iface_key].get('vpp_sw_index') - #FIXME: use only iface_key, do not use integer + # TODO: use only iface_key, do not use integer else: return int(iface_key) except (KeyError, ValueError): @@ -372,7 +388,7 @@ class Topology(object): :return: Interface key. :rtype: str - :raises TypeError: If provided with invalid arguments. + :raises TypeError: If provided with invalid interface argument. :raises RuntimeError: If the interface does not exist in topology. """