Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 65 additions & 2 deletions tests/test_pretest.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import os
import pytest
import random
import re
import time

from tests.common.helpers.multi_thread_utils import SafeThreadPoolExecutor
Expand Down Expand Up @@ -374,15 +375,77 @@ def test_collect_pfc_pause_delay_params(duthosts, tbinfo):
logger.warning('Unable to create file {}: {}'.format(filepath, e))


def test_update_saithrift_ptf(request, ptfhost):
def test_update_saithrift_ptf(request, ptfhost, duthosts, enum_dut_hostname):
'''
Install the correct python saithrift package on the ptf
'''
py_saithrift_url = request.config.getoption("--py_saithrift_url")
if not py_saithrift_url:
pytest.skip("No URL specified for python saithrift package")

duthost = duthosts[enum_dut_hostname]
output = duthost.shell("show version", module_ignore_errors=True)['stdout']
version_reg = re.compile(r"sonic software version: +([^\s]+)\s", re.IGNORECASE)
asic_reg = re.compile(r"asic: +([^\s]+)\s", re.IGNORECASE)
# sample value: SONiC.20240510.33, SONiC.20250505.07, SONiC.internal.129741107-8524154c2d,
# SONiC.master.882522-695c23859
version = version_reg.findall(output)[0] if version_reg.search(output) else ""
# only broadcom, cisco-8000, mellanox support qos sai tests
asic = asic_reg.findall(output)[0] if asic_reg.search(output) else ""

if "master" in version:
branch_name = "master"
elif "internal" in version:
branch_name = "internal"
else:
# Extract year/month from version string to determine branch
date_match = re.search(r'(\d{4})(\d{2})', version)
if date_match:
year, month = date_match.groups()
branch_name = f"internal-{year}{month}"
else:
pytest.fail("Unable to parse or recognize version format: {}".format(version))

# Apply special codename overrides for specific internal branches
if branch_name == "internal-202411":
# internal-202411 has saithrift URL hardcoded to bullseye
debian_codename = "bullseye"
elif (branch_name.startswith("internal-") and branch_name < "internal-202405"):
# For internal branches older than 202405, use the original URL without modification
# No need to get debian_codename as URL won't be modified
debian_codename = None
else:
# Get debian codename from syncd container (not host OS)
# This applies to: master branch and internal branches >= 202405 (except 202411)
try:
# Try to get codename from syncd container
syncd_codename_cmd = ("docker exec syncd grep VERSION_CODENAME /etc/os-release | "
"cut -d= -f2 | tr -d '\"'")
syncd_codename_result = duthost.shell(syncd_codename_cmd, module_ignore_errors=True)
if syncd_codename_result['rc'] == 0 and syncd_codename_result['stdout'].strip():
debian_codename = syncd_codename_result['stdout'].strip()
else:
pytest.fail("Failed to get debian codename from syncd container. RC: {}, Output: '{}'".format(
syncd_codename_result['rc'], syncd_codename_result['stdout']))
except Exception as e:
pytest.fail("Exception while getting debian codename from syncd container: {}".format(str(e)))

pkg_name = py_saithrift_url.split("/")[-1]
ip_addr = py_saithrift_url.split("/")[2]
ptfhost.shell("rm -f {}".format(pkg_name))

if branch_name.startswith("internal-") and branch_name < "internal-202405":
# For internal branches older than 202405, use the original URL without modification
pass
elif branch_name == "master":
py_saithrift_url = (f"http://{ip_addr}/mssonic-public-pipelines/"
f"Azure.sonic-buildimage.official.{asic}/master/{asic}/"
f"latest/target/debs/{debian_codename}/{pkg_name}")
else:
# For internal branches newer than 202405 and other branches
py_saithrift_url = (f"http://{ip_addr}/pipelines/Networking-acs-buildimage-Official/"
f"{asic}/{branch_name}/latest/target/debs/{debian_codename}/{pkg_name}")

# Retry download of saithrift library
retry_count = 5
while retry_count > 0:
Expand All @@ -393,7 +456,7 @@ def test_update_saithrift_ptf(request, ptfhost):
retry_count -= 1

if result["failed"] or "OK" not in result["msg"]:
pytest.skip("Download failed/error while installing python saithrift package")
pytest.fail("Download failed/error while installing python saithrift package: {}".format(py_saithrift_url))
ptfhost.shell("dpkg -i {}".format(os.path.join("/root", pkg_name)))
# In 202405 branch, the switch_sai_thrift package is inside saithrift-0.9-py3.11.egg
# We need to move it out to the correct location
Expand Down
Loading