Skip to content

Commit

Permalink
Add possibility to apply multiple patches to PTF tests (#225)
Browse files Browse the repository at this point in the history
Signed-off-by: Yurii Lisovskyi <[email protected]>
  • Loading branch information
yuriilisovskyi authored Oct 30, 2023
1 parent 7c0cfa7 commit 5d228e4
Showing 1 changed file with 16 additions and 13 deletions.
29 changes: 16 additions & 13 deletions usecases/sai-ptf/conftest.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
import paramiko
import pytest
import subprocess
Expand All @@ -11,21 +12,23 @@

@pytest.hookimpl(tryfirst=True)
def pytest_sessionstart(session):
patch_file = "/sai-challenger/usecases/sai-ptf/patches/0001-sai-base-test.patch"
patch_files = [p for p in os.listdir("/sai-challenger/usecases/sai-ptf/patches/") if p.endswith('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}")
for patch_file in patch_files:
patch_file = f"/sai-challenger/usecases/sai-ptf/patches/{patch_file}"
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)
Expand Down

0 comments on commit 5d228e4

Please sign in to comment.