diff options
author | Matej Klotton <mklotton@cisco.com> | 2016-03-11 13:56:39 +0100 |
---|---|---|
committer | Stefan Kobza <skobza@cisco.com> | 2016-04-13 16:09:31 +0000 |
commit | 6d9fe9bb4bd353b1d4fec3b2569bcd743f87fc4a (patch) | |
tree | 7a21e9072114ba6670fab95421ded8796335c1c4 /resources/libraries/python | |
parent | 5a2fd159dce96a70f2e5157314391aceb6d80197 (diff) |
VXLAN test with dot1q tagging.
Change-Id: I3dbd12983736e338d757c580570d91680aedd83f
Signed-off-by: Matej Klotton <mklotton@cisco.com>
Diffstat (limited to 'resources/libraries/python')
-rw-r--r-- | resources/libraries/python/InterfaceUtil.py | 32 | ||||
-rw-r--r-- | resources/libraries/python/VatExecutor.py | 21 | ||||
-rw-r--r-- | resources/libraries/python/topology.py | 24 |
3 files changed, 61 insertions, 16 deletions
diff --git a/resources/libraries/python/InterfaceUtil.py b/resources/libraries/python/InterfaceUtil.py index 4631ccce7a..6526fe83ca 100644 --- a/resources/libraries/python/InterfaceUtil.py +++ b/resources/libraries/python/InterfaceUtil.py @@ -400,6 +400,38 @@ class InterfaceUtil(object): InterfaceUtil.update_tg_interface_data_on_node(node_data) @staticmethod + def create_vlan_subinterface(node, interface, vlan): + """Create VLAN subinterface on node. + + :param node: Node to add VLAN subinterface on. + :param interface: Interface name on which create VLAN subinterface. + :param vlan: VLAN ID of the subinterface to be created. + :type node: dict + :type interface: str + :type vlan: int + :return: Name and index of created subinterface. + :rtype: tuple + """ + sw_if_index = Topology.get_interface_sw_index(node, interface) + + output = VatExecutor.cmd_from_template(node, "create_vlan_subif.vat", + sw_if_index=sw_if_index, + vlan=vlan) + if output[0]["retval"] == 0: + sw_subif_index = output[0]["sw_if_index"] + logger.trace('VLAN subinterface with sw_if_index {} and VLAN ID {} ' + 'created on node {}'.format(sw_subif_index, + vlan, node['host'])) + else: + raise RuntimeError('Unable to create VLAN subinterface on node {}' + .format(node['host'])) + + with VatTerminal(node, False) as vat: + vat.vat_terminal_exec_cmd('exec show interfaces') + + return '{}.{}'.format(interface, vlan), sw_subif_index + + @staticmethod def create_vxlan_interface(node, vni, source_ip, destination_ip): """Create VXLAN interface and return sw if index of created interface. diff --git a/resources/libraries/python/VatExecutor.py b/resources/libraries/python/VatExecutor.py index 136b7cc0ef..9851d93edd 100644 --- a/resources/libraries/python/VatExecutor.py +++ b/resources/libraries/python/VatExecutor.py @@ -142,18 +142,25 @@ class VatTerminal(object): """VAT interactive terminal :param node: Node to open VAT terminal on. + :param json_param: Defines if outputs from VAT are in JSON format. + Default is True. + :type node: dict + :type json_param: bool + """ __VAT_PROMPT = "vat# " __LINUX_PROMPT = ":~$ " - def __init__(self, node): + def __init__(self, node, json_param=True): + json_text = ' json' if json_param else '' + self.json = json_param self._ssh = SSH() self._ssh.connect(node) self._tty = self._ssh.interactive_terminal_open() self._ssh.interactive_terminal_exec_command( self._tty, - 'sudo -S {vat} json'.format(vat=Constants.VAT_BIN_NAME), + 'sudo -S {}{}'.format(Constants.VAT_BIN_NAME, json_text), self.__VAT_PROMPT) def __enter__(self): @@ -167,15 +174,19 @@ class VatTerminal(object): :param cmd: Command to be executed. - :return: Command output in python representation of JSON format. + :return: Command output in python representation of JSON format or + None if not in JSON mode. """ logger.debug("Executing command in VAT terminal: {}".format(cmd)) out = self._ssh.interactive_terminal_exec_command(self._tty, cmd, self.__VAT_PROMPT) logger.debug("VAT output: {}".format(out)) - json_out = json.loads(out) - return json_out + if self.json: + json_out = json.loads(out) + return json_out + else: + return None def vat_terminal_close(self): """Close VAT terminal.""" diff --git a/resources/libraries/python/topology.py b/resources/libraries/python/topology.py index d04d584623..0f26d2c6e9 100644 --- a/resources/libraries/python/topology.py +++ b/resources/libraries/python/topology.py @@ -164,20 +164,22 @@ class Topology(object): @staticmethod def get_interface_sw_index(node, interface): - """Get VPP sw_index for the interface. + """Get VPP sw_if_index for the interface. - :param node: Node to get interface sw_index on. - :param interface: Interface name. + :param node: Node to get interface sw_if_index on. + :param interface: Interface identifier. :type node: dict - :type interface: str - :return: Return sw_index or None if not found. + :type interface: str or int + :return: Return sw_if_index or None if not found. """ - for port in node['interfaces'].values(): - port_name = port.get('name') - if port_name == interface: - return port.get('vpp_sw_index') - - return None + try: + return int(interface) + except ValueError: + for port in node['interfaces'].values(): + port_name = port.get('name') + if port_name == interface: + return port.get('vpp_sw_index') + return None @staticmethod def get_interface_mtu(node, interface): |