From d11fa50c877b5f24f34a2346f56aeb1760c22a3d Mon Sep 17 00:00:00 2001
From: Dmitry Tantsur <dtantsur@protonmail.com>
Date: Tue, 25 Feb 2025 14:26:10 +0100
Subject: [PATCH] Fix the way qemu-img is called with prlimits

Using prlimits is incompatible with passing arguments as a list:
oslo.concurrency ends up executing something like:

/opt/ironic-python-agent/bin/python3 -m oslo_concurrency.prlimit \
    --as=2147483648 -- ['env', 'LC_ALL=C', 'LANG=C', 'qemu-img', 'info', \
    '/tmp/cirros-0.6.2-x86_64-disk.img', '--output=json']

Which obviously fails. I don't understand how our CI has worked so far,
but the Metal3 BMO suite fails on this.

Change-Id: I46dbcb0f73bcbe09bb89b5c7195259570412698e
(cherry picked from commit fd8032b3601f79315eb683916fbd4a2a8d5cc74e)
---
 ironic_python_agent/qemu_img.py                 | 2 +-
 ironic_python_agent/tests/unit/test_qemu_img.py | 8 ++++----
 2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/ironic_python_agent/qemu_img.py b/ironic_python_agent/qemu_img.py
index 7ce38a09a..8c55df8c7 100644
--- a/ironic_python_agent/qemu_img.py
+++ b/ironic_python_agent/qemu_img.py
@@ -89,7 +89,7 @@ def image_info(path, source_format=None):
     if source_format:
         cmd += ['-f', source_format]
 
-    out, err = utils.execute(cmd, prlimit=_qemu_img_limits())
+    out, err = utils.execute(*cmd, prlimit=_qemu_img_limits())
     return imageutils.QemuImgInfo(out, format='json')
 
 
diff --git a/ironic_python_agent/tests/unit/test_qemu_img.py b/ironic_python_agent/tests/unit/test_qemu_img.py
index 8645eb8c6..37c40d6aa 100644
--- a/ironic_python_agent/tests/unit/test_qemu_img.py
+++ b/ironic_python_agent/tests/unit/test_qemu_img.py
@@ -44,8 +44,8 @@ class ImageInfoTestCase(base.IronicLibTestCase):
         qemu_img.image_info('img')
         path_exists_mock.assert_called_once_with('img')
         execute_mock.assert_called_once_with(
-            ['env', 'LC_ALL=C', 'LANG=C', 'qemu-img', 'info', 'img',
-             '--output=json'], prlimit=mock.ANY)
+            'env', 'LC_ALL=C', 'LANG=C', 'qemu-img', 'info', 'img',
+            '--output=json', prlimit=mock.ANY)
         image_info_mock.assert_called_once_with('out', format='json')
 
     @mock.patch.object(utils, 'execute', return_value=('out', 'err'),
@@ -57,8 +57,8 @@ class ImageInfoTestCase(base.IronicLibTestCase):
         qemu_img.image_info('img', source_format='qcow2')
         path_exists_mock.assert_called_once_with('img')
         execute_mock.assert_called_once_with(
-            ['env', 'LC_ALL=C', 'LANG=C', 'qemu-img', 'info', 'img',
-             '--output=json', '-f', 'qcow2'],
+            'env', 'LC_ALL=C', 'LANG=C', 'qemu-img', 'info', 'img',
+            '--output=json', '-f', 'qcow2',
             prlimit=mock.ANY
         )
         image_info_mock.assert_called_once_with('out', format='json')