diff mbox series

[v2,2/2] oeqa/utils/command: simplify tap detection

Message ID 20250712125103.3404739-3-adrian.freihofer@siemens.com
State New
Headers show
Series oe-selftest: devtool: split tap detection into function | expand

Commit Message

AdrianF July 12, 2025, 12:50 p.m. UTC
From: Adrian Freihofer <adrian.freihofer@siemens.com>

Simplify the code by removing the fallback to ifconfig if the ip command
is not available. ip commands are nowadays available on all host
machines. The transition from ifconfig to ip has taken place long time
ago e.g. for the runqemu-gen-tapdevs script.

This also fixes the detection of tap devices if the tap devices are not
named tap0, tap1, etc. but have a different name, e.g. foo0, foo1 which
is the case if the OE_TAP_NAME environment variable is set.

Some examples:

$ ip tuntap show mode tap
$ sudo ./scripts/runqemu-gen-tapdevs 1000 2
Creating 2 tap devices for GID: 1000...
Creating tap0
Creating tap1
...
$ ip tuntap show mode tap
tap0: tap persist group 1000
tap1: tap persist group 1000
$ sudo ./scripts/runqemu-gen-tapdevs 1000 0
Note: Destroying pre-existing tap interface tap0...
Note: Destroying pre-existing tap interface tap1...
$ ip tuntap show mode tap
$ sudo OE_TAP_NAME=foo ./scripts/runqemu-gen-tapdevs 1000 2
Creating 2 tap devices for GID: 1000...
Creating foo0
Creating foo1
...
$ ip tuntap show mode tap
foo0: tap persist group 1000
foo1: tap persist group 1000
$ sudo OE_TAP_NAME=foo ./scripts/runqemu-gen-tapdevs 1000 0
Note: Destroying pre-existing tap interface foo0...
Note: Destroying pre-existing tap interface foo1...
$ ip tuntap show mode tap

Signed-off-by: Adrian Freihofer <adrian.freihofer@siemens.com>
---
 meta/lib/oeqa/utils/commands.py | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)
diff mbox series

Patch

diff --git a/meta/lib/oeqa/utils/commands.py b/meta/lib/oeqa/utils/commands.py
index e049e1ee682..91542209685 100644
--- a/meta/lib/oeqa/utils/commands.py
+++ b/meta/lib/oeqa/utils/commands.py
@@ -405,13 +405,11 @@  def runqemu_check_taps():
     """Check if tap devices for runqemu are available"""
     if not os.path.exists('/etc/runqemu-nosudo'):
         return False
-    result = runCmd('PATH="$PATH:/sbin:/usr/sbin" ip tuntap show', ignore_status=True)
+    result = runCmd('PATH="$PATH:/sbin:/usr/sbin" ip tuntap show mode tap', ignore_status=True)
     if result.status != 0:
-        result = runCmd('PATH="$PATH:/sbin:/usr/sbin" ifconfig -a', ignore_status=True)
-        if result.status != 0:
-            return False
+        return False
     for line in result.output.splitlines():
-        if line.startswith('tap'):
+        if 'tap' in line:
             break
     else:
         return False