git: a1eb150ce215 - main - atf_python: vnet: Use absolute paths within helpers

From: Mark Johnston <markj_at_FreeBSD.org>
Date: Fri, 13 Oct 2023 19:31:38 UTC
The branch main has been updated by markj:

URL: https://cgit.FreeBSD.org/src/commit/?id=a1eb150ce215f51abbbb34aed0533bced93e5502

commit a1eb150ce215f51abbbb34aed0533bced93e5502
Author:     Jose Luis Duran <jlduran@gmail.com>
AuthorDate: 2023-10-12 15:14:44 +0000
Commit:     Mark Johnston <markj@FreeBSD.org>
CommitDate: 2023-10-13 19:31:30 +0000

    atf_python: vnet: Use absolute paths within helpers
    
    Usually tests are run in sterile environments; however, there is a
    slight chance that the PATH overrides the utilities used for testing.
    
    Pedantically use absolute paths, even inside VNETs, to avoid ambiguity.
    
    Chiefly, jexec -> /usr/sbin/jexec, and ifconfig -> /sbin/ifconfig.
    
    Reviewed by:    markj
    MFC after:      1 week
    Pull Request:   https://github.com/freebsd/freebsd-src/pull/865
---
 tests/atf_python/sys/net/vnet.py | 16 ++++++----------
 1 file changed, 6 insertions(+), 10 deletions(-)

diff --git a/tests/atf_python/sys/net/vnet.py b/tests/atf_python/sys/net/vnet.py
index bfe7984b440b..7c855b19f2c0 100644
--- a/tests/atf_python/sys/net/vnet.py
+++ b/tests/atf_python/sys/net/vnet.py
@@ -82,13 +82,9 @@ class VnetInterface(object):
     def set_jailed(self, jailed: bool):
         self.jailed = jailed
 
-    def run_cmd(
-        self,
-        cmd,
-        verbose=False,
-    ):
+    def run_cmd(self, cmd, verbose=False):
         if self.vnet_name and not self.jailed:
-            cmd = "jexec {} {}".format(self.vnet_name, cmd)
+            cmd = "/usr/sbin/jexec {} {}".format(self.vnet_name, cmd)
         return run_cmd(cmd, verbose)
 
     @classmethod
@@ -189,7 +185,7 @@ class IfaceFactory(object):
     def cleanup_vnet_interfaces(self, vnet_name: str) -> List[str]:
         """Destroys"""
         ifaces_lst = ToolsHelper.get_output(
-            "/usr/sbin/jexec {} ifconfig -l".format(vnet_name)
+            "/usr/sbin/jexec {} /sbin/ifconfig -l".format(vnet_name)
         )
         for iface_name in ifaces_lst.split():
             if not self.is_autodeleted(iface_name):
@@ -197,7 +193,7 @@ class IfaceFactory(object):
                     print("Skipping interface {}:{}".format(vnet_name, iface_name))
                     continue
             run_cmd(
-                "/usr/sbin/jexec {} ifconfig {} destroy".format(vnet_name, iface_name)
+                "/usr/sbin/jexec {} /sbin/ifconfig {} destroy".format(vnet_name, iface_name)
             )
 
     def cleanup(self):
@@ -231,7 +227,7 @@ class VnetInstance(object):
 
     def run_vnet_cmd(self, cmd):
         if not self.attached:
-            cmd = "jexec {} {}".format(self.name, cmd)
+            cmd = "/usr/sbin/jexec {} {}".format(self.name, cmd)
         return run_cmd(cmd)
 
     def disable_dad(self):
@@ -269,7 +265,7 @@ class VnetFactory(object):
 
     @staticmethod
     def _wait_interfaces(vnet_name: str, ifaces: List[str]) -> List[str]:
-        cmd = "jexec {} /sbin/ifconfig -l".format(vnet_name)
+        cmd = "/usr/sbin/jexec {} /sbin/ifconfig -l".format(vnet_name)
         not_matched: List[str] = []
         for i in range(50):
             vnet_ifaces = run_cmd(cmd).strip().split(" ")