From 1831117c76e109ef5bbd273d102e250858510efa Mon Sep 17 00:00:00 2001 From: Andriy Kokhan Date: Wed, 6 Sep 2023 17:46:48 +0300 Subject: [PATCH] Updated PTF use-case. Enabled PTF TCs run from CI/CD (#189) Signed-off-by: Andriy Kokhan Signed-off-by: selldinesh --- .github/workflows/sc-standalone-deb10.yml | 3 ++ .github/workflows/sc-standalone-deb11.yml | 3 ++ usecases/sai-ptf/README.md | 20 +++---------- .../sai-ptf/{ptf-conftest.py => conftest.py} | 30 +++++++++++++++++-- 4 files changed, 37 insertions(+), 19 deletions(-) rename usecases/sai-ptf/{ptf-conftest.py => conftest.py} (55%) diff --git a/.github/workflows/sc-standalone-deb10.yml b/.github/workflows/sc-standalone-deb10.yml index e2b8774b..0e533969 100644 --- a/.github/workflows/sc-standalone-deb10.yml +++ b/.github/workflows/sc-standalone-deb10.yml @@ -102,3 +102,6 @@ jobs: run: ./exec.sh --no-tty -s thrift pytest --testbed=saivs_thrift_standalone -v -k "test_sairec" - name: Run thrift API tests run: ./exec.sh --no-tty -s thrift pytest --testbed=saivs_thrift_standalone -v -k "api/test" + + - name: Run PTF tests + run: ./exec.sh --no-tty -s thrift pytest --testbed=saivs_thrift_standalone -v ../usecases/sai-ptf/SAI/ptf/saifdb.py -k FdbAttributeTest diff --git a/.github/workflows/sc-standalone-deb11.yml b/.github/workflows/sc-standalone-deb11.yml index 5111de48..a8c1945d 100644 --- a/.github/workflows/sc-standalone-deb11.yml +++ b/.github/workflows/sc-standalone-deb11.yml @@ -102,3 +102,6 @@ jobs: run: ./exec.sh --no-tty -s thrift pytest --testbed=saivs_thrift_standalone -v -k "test_sairec" - name: Run thrift API tests run: ./exec.sh --no-tty -s thrift pytest --testbed=saivs_thrift_standalone -v -k "api/test" + + - name: Run PTF tests + run: ./exec.sh --no-tty -s thrift pytest --testbed=saivs_thrift_standalone -v ../usecases/sai-ptf/SAI/ptf/saifdb.py -k FdbAttributeTest diff --git a/usecases/sai-ptf/README.md b/usecases/sai-ptf/README.md index eebab1f9..a3693395 100644 --- a/usecases/sai-ptf/README.md +++ b/usecases/sai-ptf/README.md @@ -6,29 +6,22 @@ SAI Challenger has capability to run these tests by setting up proper test envir # Steps to run tests -0. Setup the environment +1. Setup the environment ``` git submodule update --init -cp usecases/sai-ptf/ptf-conftest.py usecases/sai-ptf/SAI/ptf/conftest.py -cp usecases/sai-ptf/patches/0001-sai-base-test.patch usecases/sai-ptf/SAI/ -cd usecases/sai-ptf/SAI/ && patch -p1 < 0001-sai-base-test.patch && cd - ``` -1. Build a Docker image with required test env +2. Build a Docker image with a required test environment. + This step is optional. The image can be implicitly pulled from DockerHub by `run.sh`. ``` ./build.sh -s thrift ``` -2. Start a container based on newly built image +3. Start a Docker container ``` ./run.sh -s thrift ``` -3. Login into the container -``` -docker exec -ti sc-thrift-trident2-saivs-run bash -``` - 4. Run a test @@ -39,11 +32,6 @@ To run PTF test case: pytest --testbed=saivs_thrift_standalone ../usecases/sai-ptf/SAI/ptf/saifdb.py -k FdbAttributeTest -v ``` -To clean-up `saiserver` for `saivs` target after test case execution: -``` -supervisorctl restart saiserver -``` - To run SAI Challenger test case using Thrift RPC: ``` pytest --testbed=saivs_thrift_standalone -k "access_to_access" -v diff --git a/usecases/sai-ptf/ptf-conftest.py b/usecases/sai-ptf/conftest.py similarity index 55% rename from usecases/sai-ptf/ptf-conftest.py rename to usecases/sai-ptf/conftest.py index 0af18404..be11ebec 100644 --- a/usecases/sai-ptf/ptf-conftest.py +++ b/usecases/sai-ptf/conftest.py @@ -1,18 +1,42 @@ import sys import pytest +import subprocess from saichallenger.common.sai_testbed import SaiTestbedMeta +sys.path.insert(0, '/sai-challenger/ptf/src') -def import_base_modules(): - sys.path.insert(0, '/sai-challenger/ptf/src') -import_base_modules() +@pytest.hookimpl(tryfirst=True) +def pytest_sessionstart(session): + patch_file = "/sai-challenger/usecases/sai-ptf/patches/0001-sai-base-test.patch" + target_directory = "/sai-challenger/usecases/sai-ptf/SAI/" + + try: + command = ["patch", "--dry-run", "--silent", "-N", "-p1", "-i", patch_file, "-d", target_directory] + result = subprocess.run(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True) + if result.returncode == 0: + subprocess.run(["patch", "-p1", "-i", patch_file, "-d", target_directory], check=True) + elif result.returncode == 1: + # The patch is already applied + return + else: + raise RuntimeError(f"Failed to check whether the patch is already applied: {result}") + except Exception as e: + raise RuntimeError(f"Failed to apply the patch: {e}") @pytest.fixture(scope="session", autouse=True) def set_ptf_params(request): if request.config.option.testbed: tb_params = SaiTestbedMeta("/sai-challenger", request.config.option.testbed) + if tb_params.config['npu'][0]['target'] == 'saivs' and \ + tb_params.config['npu'][0]['client']['config']['ip'] in ['localhost', '127.0.0.1']: + try: + # Clean-up saiserver after previous test session + subprocess.run(["supervisorctl", "restart", "saiserver"], check=True) + except Exception as e: + raise RuntimeError(f"Failed to apply the patch: {e}") + tb_params.generate_sai_ptf_config_files() ports = to_ptf_int_list(tb_params.config['dataplane'][0]['port_groups']) else: