Skip to content

Commit

Permalink
Updated PTF use-case. Enabled PTF TCs run from CI/CD (opencomputeproj…
Browse files Browse the repository at this point in the history
…ect#189)

Signed-off-by: Andriy Kokhan <andriy.kokhan@gmail.com>
Signed-off-by: selldinesh <dinesh.sellappan@keysight.com>
  • Loading branch information
andriy-kokhan authored and selldinesh committed Oct 16, 2023
1 parent 126c1b5 commit 1831117
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 19 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/sc-standalone-deb10.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 3 additions & 0 deletions .github/workflows/sc-standalone-deb11.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
20 changes: 4 additions & 16 deletions usecases/sai-ptf/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand All @@ -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
Expand Down
30 changes: 27 additions & 3 deletions usecases/sai-ptf/ptf-conftest.py → usecases/sai-ptf/conftest.py
Original file line number Diff line number Diff line change
@@ -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:
Expand Down

0 comments on commit 1831117

Please sign in to comment.