summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Vinciguerra <pvinci@vinciconsulting.com>2019-03-12 17:41:27 -0700
committerPaul Vinciguerra <pvinci@vinciconsulting.com>2019-03-12 17:48:49 -0700
commitc599c6f001bc28e1023fb5e74a27db37b1aae847 (patch)
tree9e70680448f07c542cfaee4c4730482ec71004fb
parent6459315569f49bcc2b3572f169192ded7323598f (diff)
Tests: Raise exception, don't raise string.
This was deprecated ~ python 2.4, and causes a TypeError as sideEffect. >>> raise "foo" Traceback (most recent call last): File "<input>", line 1, in <module> TypeError: exceptions must derive from BaseException Change-Id: I4117b6d60ae896eaa1ef2a73a323d8d241f8c3a7 Signed-off-by: Paul Vinciguerra <pvinci@vinciconsulting.com>
-rw-r--r--test/test_geneve.py2
-rw-r--r--test/test_gtpu.py2
-rw-r--r--test/test_vxlan.py2
-rw-r--r--test/test_vxlan_gpe.py2
4 files changed, 4 insertions, 4 deletions
diff --git a/test/test_geneve.py b/test/test_geneve.py
index ebe95a0f1a0..4d6e3f5932a 100644
--- a/test/test_geneve.py
+++ b/test/test_geneve.py
@@ -113,7 +113,7 @@ class TestGeneve(BridgeDomain, VppTestCase):
remote_address=cls.mcast_ip4n, mcast_sw_if_index=1,
is_add=is_add, vni=vni)
if r.sw_if_index == 0xffffffff:
- raise "bad sw_if_index"
+ raise ValueError("bad sw_if_index: ~0")
@classmethod
def add_shared_mcast_dst_load(cls):
diff --git a/test/test_gtpu.py b/test/test_gtpu.py
index f5b1089757e..4b776285766 100644
--- a/test/test_gtpu.py
+++ b/test/test_gtpu.py
@@ -168,7 +168,7 @@ class TestGtpu(BridgeDomain, VppTestCase):
teid=teid,
is_add=is_add)
if r.sw_if_index == 0xffffffff:
- raise "bad sw_if_index"
+ raise ValueError("bad sw_if_index: ~0")
@classmethod
def add_shared_mcast_dst_load(cls):
diff --git a/test/test_vxlan.py b/test/test_vxlan.py
index 7e3ea50c2e4..5ded725abf6 100644
--- a/test/test_vxlan.py
+++ b/test/test_vxlan.py
@@ -111,7 +111,7 @@ class TestVxlan(BridgeDomain, VppTestCase):
mcast_sw_if_index=1,
is_add=is_add, vni=vni)
if r.sw_if_index == 0xffffffff:
- raise "bad sw_if_index"
+ raise ValueError("bad sw_if_index: ~0")
@classmethod
def add_shared_mcast_dst_load(cls):
diff --git a/test/test_vxlan_gpe.py b/test/test_vxlan_gpe.py
index 6ee33d59c9e..36661a9c1fa 100644
--- a/test/test_vxlan_gpe.py
+++ b/test/test_vxlan_gpe.py
@@ -114,7 +114,7 @@ class TestVxlanGpe(BridgeDomain, VppTestCase):
vni=vni,
is_add=is_add)
if r.sw_if_index == 0xffffffff:
- raise "bad sw_if_index"
+ raise ValueError("bad sw_if_index: ~0")
@classmethod
def add_shared_mcast_dst_load(cls):
='#n101'>101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139
# Copyright (c) 2022 Intel 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.


"""This module implements initialization and cleanup of NGINX framework."""

from robot.api import logger

from resources.libraries.python.Constants import Constants
from resources.libraries.python.ssh import exec_cmd_no_error, exec_cmd
from resources.libraries.python.topology import NodeType
from resources.libraries.python.NginxUtil import NginxUtil


class NGINXTools:
    """This class implements:
    - Initialization of NGINX environment,
    - Cleanup of NGINX environment.
    """

    @staticmethod
    def cleanup_nginx_framework(node, nginx_ins_path):
        """
        Cleanup the NGINX framework on the DUT node.

        :param node: Will cleanup the nginx on this nodes.
        :param nginx_ins_path: NGINX install path.
        :type node: dict
        :type nginx_ins_path: str
        :raises RuntimeError: If it fails to cleanup the nginx.
        """
        check_path_cmd = NginxUtil.get_cmd_options(path=nginx_ins_path)
        exec_cmd_no_error(node, check_path_cmd, timeout=180,
                          message=u"Check NGINX install path failed!")
        command = f"rm -rf {nginx_ins_path}"
        message = u"Cleanup the NGINX failed!"
        exec_cmd_no_error(node, command, timeout=180, message=message)

    @staticmethod
    def cleanup_nginx_framework_on_all_duts(nodes, nginx_ins_path):
        """
        Cleanup the NGINX framework on all DUT nodes.

        :param nodes: Will cleanup the nginx on this nodes.
        :param nginx_ins_path: NGINX install path.
        :type nodes: dict
        :type nginx_ins_path: str
        :raises RuntimeError: If it fails to cleanup the nginx.
        """
        for node in nodes.values():
            if node[u"type"] == NodeType.DUT:
                NGINXTools.cleanup_nginx_framework(node, nginx_ins_path)

    @staticmethod
    def install_original_nginx_framework(node, pkg_dir, nginx_version):
        """
        Prepare the NGINX framework on the DUT node.

        :param node: Node from topology file.
        :param pkg_dir: Ldp NGINX install dir.
        :param nginx_version: NGINX Version.
        :type node: dict
        :type pkg_dir: str
        :type nginx_version: str
        :raises RuntimeError: If command returns nonzero return code.
        """
        cmd = f"test -f {pkg_dir}/nginx-{nginx_version}/sbin/nginx"
        ret_code, _, _ = exec_cmd(node, cmd, sudo=True)
        if ret_code == 0:
            return
        command = f"{Constants.REMOTE_FW_DIR}/{Constants.RESOURCES_LIB_SH}" \
                  f"/entry/install_nginx.sh nginx-{nginx_version}"
        message = u"Install the NGINX failed!"
        exec_cmd_no_error(node, command, sudo=True, timeout=600,
                          message=message)

    @staticmethod
    def install_vsap_nginx_on_dut(node, pkg_dir):
        """
         Prepare the VSAP NGINX framework on all DUT

        :param node: Node from topology file.
        :param pkg_dir: Path to directory where packages are stored.
        :type node: dict
        :type pkg_dir: str
        :raises RuntimeError: If command returns nonzero return code.
        """
        command = u". /etc/lsb-release; echo \"${DISTRIB_ID}\""
        stdout, _ = exec_cmd_no_error(node, command)

        if stdout.strip() == u"Ubuntu":
            logger.console(u"NGINX install on DUT... ")
            exec_cmd_no_error(
                node, u"apt-get purge -y 'vsap*' || true", timeout=120,
                sudo=True
            )
            exec_cmd_no_error(
                node, f"dpkg -i --force-all {pkg_dir}vsap-nginx*.deb",
                timeout=120, sudo=True,
                message=u"Installation of vsap-nginx failed!"
            )

            exec_cmd_no_error(node, u"dpkg -l | grep vsap*",
                              sudo=True)

            logger.console(u"Completed!\n")
        else:
            logger.console(u"Ubuntu need!\n")

    @staticmethod
    def install_nginx_framework_on_all_duts(nodes, pkg_dir, nginx_version=None):
        """
        Prepare the NGINX framework on all DUTs.

        :param nodes: Nodes from topology file.
        :param pkg_dir: Path to directory where packages are stored.
        :param nginx_version: NGINX version.
        :type nodes: dict
        :type pkg_dir: str
        :type nginx_version: str
        """

        for node in list(nodes.values()):
            if node[u"type"] == NodeType.DUT:
                if nginx_version:
                    NGINXTools.install_original_nginx_framework(node, pkg_dir,
                                                                nginx_version)
                else:
                    NGINXTools.install_vsap_nginx_on_dut(node, pkg_dir)