summaryrefslogtreecommitdiffstats
path: root/test/vpp_gre_interface.py
diff options
context:
space:
mode:
authorOle Troan <ot@cisco.com>2018-06-22 22:33:41 +0200
committerOle Troan <ot@cisco.com>2018-06-22 22:34:56 +0200
commitc8efa29b6f9a91381897b54f1147daf922ed7164 (patch)
tree405258dffbc11e9c29ca10fc8c734ec311a374b4 /test/vpp_gre_interface.py
parentd5c60b96a3fd93916fc4af5c8d6d25625c28242e (diff)
Revert "make test: fix broken interfaces"
This reverts commit d5c60b96a3fd93916fc4af5c8d6d25625c28242e. Change-Id: I3632b9c3f76c615aee897f28f76d094e7031e689 Signed-off-by: Ole Troan <ot@cisco.com>
Diffstat (limited to 'test/vpp_gre_interface.py')
-rw-r--r--test/vpp_gre_interface.py10
1 files changed, 6 insertions, 4 deletions
diff --git a/test/vpp_gre_interface.py b/test/vpp_gre_interface.py
index d5a40eeb03d..3de3e5c4559 100644
--- a/test/vpp_gre_interface.py
+++ b/test/vpp_gre_interface.py
@@ -11,7 +11,7 @@ class VppGreInterface(VppInterface):
def __init__(self, test, src_ip, dst_ip, outer_fib_id=0, type=0,
session=0):
""" Create VPP GRE interface """
- super(VppGreInterface, self).__init__(test)
+ self._test = test
self.t_src = src_ip
self.t_dst = dst_ip
self.t_outer_fib = outer_fib_id
@@ -25,9 +25,10 @@ class VppGreInterface(VppInterface):
outer_fib_id=self.t_outer_fib,
tunnel_type=self.t_type,
session_id=self.t_session)
- self.set_sw_if_index(r.sw_if_index)
+ self._sw_if_index = r.sw_if_index
self.generate_remote_hosts()
self.test.registry.register(self, self.test.logger)
+ super(VppGreInterface, self).__init__(self.test)
def remove_vpp_config(self):
s = socket.inet_pton(socket.AF_INET, self.t_src)
@@ -54,7 +55,7 @@ class VppGre6Interface(VppInterface):
def __init__(self, test, src_ip, dst_ip, outer_fib_id=0, type=0,
session=0):
""" Create VPP GRE interface """
- super(VppGre6Interface, self).__init__(test)
+ self._test = test
self.t_src = src_ip
self.t_dst = dst_ip
self.t_outer_fib = outer_fib_id
@@ -69,9 +70,10 @@ class VppGre6Interface(VppInterface):
tunnel_type=self.t_type,
session_id=self.t_session,
is_ip6=1)
- self.set_sw_if_index(r.sw_if_index)
+ self._sw_if_index = r.sw_if_index
self.generate_remote_hosts()
self.test.registry.register(self, self.test.logger)
+ super(VppGre6Interface, self).__init__(self.test)
def remove_vpp_config(self):
s = socket.inet_pton(socket.AF_INET6, self.t_src)
a id='n58' href='#n58'>58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
# Copyright (c) 2016 Cisco and/or its affiliates.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at:
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""Traffic script executor library."""

from robot.api import logger

from resources.libraries.python.constants import Constants
from resources.libraries.python.ssh import SSH

__all__ = ['TrafficScriptExecutor']


class TrafficScriptExecutor(object):
    """Traffic script executor utilities."""

    @staticmethod
    def _escape(string):
        """Escape quotation mark and dollar mark for shell command.

        :param string: String to escape.
        :type string: str
        :return: Escaped string.
        :rtype: str
        """
        return string.replace('"', '\\"').replace("$", "\\$")

    @staticmethod
    def run_traffic_script_on_node(script_file_name, node, script_args,
                                   timeout=10):
        """Run traffic script on the TG node.

        :param script_file_name: Traffic script name.
        :param node: Node to run traffic script on.
        :param script_args: Traffic scripts arguments.
        :param timeout: Timeout (optional).
        :type script_file_name: str
        :type node: dict
        :type script_args: str
        :type timeout: int
        """
        logger.trace("{}".format(timeout))
        ssh = SSH()
        ssh.connect(node)
        cmd = ("cd {}; virtualenv env && " +
               "export PYTHONPATH=${{PWD}}; " +
               ". ${{PWD}}/env/bin/activate; " +
               "resources/traffic_scripts/{} {}") \
                  .format(Constants.REMOTE_FW_DIR, script_file_name,
                          script_args)
        (ret_code, stdout, stderr) = ssh.exec_command_sudo(
            'sh -c "{}"'.format(TrafficScriptExecutor._escape(cmd)),
            timeout=timeout)
        logger.debug("stdout: {}".format(stdout))
        logger.debug("stderr: {}".format(stderr))
        logger.debug("ret_code: {}".format(ret_code))
        if ret_code != 0:
            if "RuntimeError: ICMP echo Rx timeout" in stderr:
                raise Exception("ICMP echo Rx timeout")
            else:
                raise Exception("Traffic script execution failed")

    @staticmethod
    def traffic_script_gen_arg(rx_if, tx_if, src_mac, dst_mac, src_ip, dst_ip):
        """Generate traffic script basic arguments string.

        :param rx_if: Interface that receives traffic.
        :param tx_if: Interface that sends traffic.
        :param src_mac: Source MAC address.
        :param dst_mac: Destination MAC address.
        :param src_ip: Source IP address.
        :param dst_ip: Destination IP address.
        :type rx_if: str
        :type tx_if: str
        :type src_mac: str
        :type dst_mac: str
        :type src_ip: str
        :type dst_ip: str
        :return: Traffic script arguments string.
        :rtype: str
        """
        args = ('--rx_if {0} --tx_if {1} --src_mac {2} --dst_mac {3} --src_ip'
                ' {4} --dst_ip {5}').format(rx_if, tx_if, src_mac, dst_mac,
                                            src_ip, dst_ip)
        return args