From a3416200b821f5b02218d865b8061b885aa0ba34 Mon Sep 17 00:00:00 2001 From: Sai Kiran <110003254+opcoder0@users.noreply.github.com> Date: Fri, 23 Aug 2024 11:56:15 +1000 Subject: [PATCH] [docker-ptf] create symlinks for py3-only image (#19813) Why I did it The mix of docker-ptf with Python 2 + Python 3 (in virtual-env) and Python 3 images only across branches (with possibly some test scripts in sonic-mgmt not migrated to Python 3 in older branches) causes different path references to Python and PTF binaries. This can cause backporting a hassle. To prevent this the PR creates virtual environment (/root/env-python3) path to the real python 3 and PTF binaries. This keeps the paths same across docker-ptf images. How I did it Created symlinks for python and PTF from /root/env-python3/bin to /usr/bin. How to verify it Image built successfully and manually verified the existence of the links. --- dockers/docker-ptf/Dockerfile.j2 | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/dockers/docker-ptf/Dockerfile.j2 b/dockers/docker-ptf/Dockerfile.j2 index 45aaec8ecd13..d19c1441825b 100644 --- a/dockers/docker-ptf/Dockerfile.j2 +++ b/dockers/docker-ptf/Dockerfile.j2 @@ -18,6 +18,7 @@ LABEL maintainer="Pavel Shirshov" COPY ["sources.list.{{ CONFIGURED_ARCH }}", "/etc/apt/sources.list"] COPY ["no-check-valid-until", "/etc/apt/apt.conf.d"] +COPY ["apt-retries-count", "/etc/apt/apt.conf.d"] ## Make apt-get non-interactive ENV DEBIAN_FRONTEND=noninteractive @@ -266,6 +267,18 @@ RUN dpkg -i \ debs/{{ deb }}{{' '}} {%- endfor %} +{% if PTF_ENV_PY_VER == "py3" %} +# Create symlink so that test scripts and ptf_runner invocation path +# is same across python 2 and python 3 envs. Note that for virtual-env +# ptf is under /root/env-python3/bin. +# TODO - cleanup when the supported PTF image is py3only across all branches +RUN mkdir -p /root/env-python3/bin \ + && ln -s /usr/local/bin/ptf /usr/bin/ptf \ + && ln -s /usr/bin/python /root/env-python3/bin/python3 \ + && ln -s /usr/bin/python /root/env-python3/bin/python \ + && ln -s /usr/local/bin/ptf /root/env-python3/bin/ptf +{% endif %} + COPY ["*.ini", "/etc/ptf/"] EXPOSE 22 8009