[elbe-devel] [PATCH] test_xml: manage initvm

Thomas Weißschuh thomas.weissschuh at linutronix.de
Mon Jun 17 16:06:43 CEST 2024


Enable test_xml to manage its own initvm instead of relying on a
preexisting initvm.
Add CLI option to fall back to an existing initvm during development.

Signed-off-by: Thomas Weißschuh <thomas.weissschuh at linutronix.de>
---
Signed-off-by: Thomas Weißschuh <--global>
---
 conftest.py                |  4 ++++
 elbepack/tests/test_xml.py | 22 +++++++++++++++++++++-
 2 files changed, 25 insertions(+), 1 deletion(-)

diff --git a/conftest.py b/conftest.py
index 0706e6ac093e..c96af018da4b 100644
--- a/conftest.py
+++ b/conftest.py
@@ -6,6 +6,10 @@ def pytest_addoption(parser):
     parser.addoption(
         '--runslow', action='store_true', default=False, help='run slow tests'
     )
+    parser.addoption(
+        '--elbe-use-existing-initvm', action='store_true', default=False,
+        help='reuse existing elbe initvm',
+    )
 
 
 def pytest_configure(config):
diff --git a/elbepack/tests/test_xml.py b/elbepack/tests/test_xml.py
index 012d8aa00f06..c52aed7626d3 100644
--- a/elbepack/tests/test_xml.py
+++ b/elbepack/tests/test_xml.py
@@ -10,12 +10,32 @@ from elbepack.directories import run_elbe
 from elbepack.tests import parametrize_xml_test_files, xml_test_files
 
 
+ at pytest.fixture(scope='module')
+def initvm(tmp_path_factory, request):
+    if request.config.getoption('--elbe-use-existing-initvm'):
+        yield
+        return
+
+    initvm_dir = tmp_path_factory.mktemp('initvm-') / 'initvm'
+
+    run_elbe(['initvm', 'create', '--directory', initvm_dir], check=True)
+
+    yield
+
+    subprocess.run([
+        'virsh', '--connect', 'qemu:///system', 'undefine', 'initvm',
+    ])
+    subprocess.run([
+        'virsh', '--connect', 'qemu:///system', 'destroy', 'initvm',
+    ])
+
+
 def _delete_project(uuid):
     run_elbe(['control', 'del_project', uuid])
 
 
 @pytest.fixture(scope='module', params=xml_test_files('simple'), ids=lambda f: f.name)
-def simple_build(request, tmp_path_factory):
+def simple_build(request, initvm, tmp_path_factory):
     build_dir = tmp_path_factory.mktemp('build_dir')
     prj = build_dir / 'uuid.prj'
 

---
base-commit: 57e78fd9799390ee5ac56d14a37980415ab11c7c
change-id: 20240617-test_xml-initvm-b7485e362dfd

Best regards,
-- 
Thomas Weißschuh <thomas.weissschuh at linutronix.de>



More information about the elbe-devel mailing list