[Concept,01/36] test: Fix LUKS device-name collision in CI environments

Message ID 20260120231814.2033069-2-sjg@u-boot.org
State New
Headers
Series video: Add multiple-context support to vidconsole (part F) |

Commit Message

Simon Glass Jan. 20, 2026, 11:17 p.m. UTC
  From: Simon Glass <simon.glass@canonical.com>

In CI environments where process IDs are reused quickly, the LUKS
device name (luks_test_<pid>) can collide with a stale device from a
previous test run. This causes cryptsetup to fail with "Device already
exists".

Add a timestamp component to the device name to ensure uniqueness even
when PIDs are reused.

Co-developed-by: Claude Opus 4.5 <noreply@anthropic.com>
Signed-off-by: Simon Glass <simon.glass@canonical.com>
---

 test/py/tests/fs_helper.py | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
  

Patch

diff --git a/test/py/tests/fs_helper.py b/test/py/tests/fs_helper.py
index ccde6683534..269b1c2d10f 100644
--- a/test/py/tests/fs_helper.py
+++ b/test/py/tests/fs_helper.py
@@ -11,6 +11,7 @@  import shutil
 from subprocess import call, check_call, check_output, CalledProcessError, run
 from subprocess import DEVNULL
 import tempfile
+import time
 
 
 class FsHelper:
@@ -269,9 +270,11 @@  class FsHelper:
                     'kernel module is loaded and you have permission to use '
                     'device-mapper. This is required for LUKS encryption tests.')
 
-        device_name = f'luks_test_{os.getpid()}'
+        # Use PID and timestamp for uniqueness in CI environments where PIDs
+        # get reused
+        device_name = f'luks_test_{os.getpid()}_{int(time.time() * 1000) % 100000}'
 
-        # Clean up any stale device with the same name
+        # Clean up any stale device with the same name (unlikely with timestamp)
         run(['sudo', 'cryptsetup', 'close', device_name],
             stdout=DEVNULL, stderr=DEVNULL, check=False)