Skip to content

Make test_script() idempotent (startup routine) #139

@phip1611

Description

@phip1611

It would be convenient if one can run test_script() multiple times, without having to restart the whole interactive driver.

I think something like this should fix it:

commit d6d703f5c7e14b75010febf646c46a5ccc4e8734
Author: Philipp Schuster <philipp.schuster@cyberus-technology.de>
Date:   Wed Jan 21 11:17:28 2026 +0100

    testscript: make test_script() idempotent
    
    This enables to run test_script() multiple times when using
    the interactive driver.
    
    On-behalf-of: SAP philipp.schuster@sap.com
    Signed-off-by: Philipp Schuster <philipp.schuster@cyberus-technology.de>

diff --git a/tests/testscript.py b/tests/testscript.py
index f4e31f6..f9d47b4 100644
--- a/tests/testscript.py
+++ b/tests/testscript.py
@@ -114,18 +114,23 @@ class LibvirtTests(SaveLogsOnErrorTestCase):
         controllerVM.succeed("ssh -o StrictHostKeyChecking=no computeVM echo")
         computeVM.succeed("ssh -o StrictHostKeyChecking=no controllerVM echo")
 
-        controllerVM.succeed(
-            'virsh pool-define-as --name "nfs-share" --type netfs --source-host "localhost" --source-path "nfs-root" --source-format "nfs" --target "/var/lib/libvirt/storage-pools/nfs-share"'
-        )
-        controllerVM.succeed("virsh pool-start nfs-share")
-
-        computeVM.succeed(
-            'virsh pool-define-as --name "nfs-share" --type netfs --source-host "controllerVM" --source-path "nfs-root" --source-format "nfs" --target "/var/lib/libvirt/storage-pools/nfs-share"'
-        )
-        computeVM.succeed("virsh pool-start nfs-share")
+        out = controllerVM.succeed("virsh pool-list")
+        if "nfs-share" not in out:
+            controllerVM.succeed(
+                'virsh pool-define-as --name "nfs-share" --type netfs --source-host "localhost" --source-path "nfs-root" --source-format "nfs" --target "/var/lib/libvirt/storage-pools/nfs-share"'
+            )
+            controllerVM.succeed("virsh pool-start nfs-share")
+        out = computeVM.succeed("virsh pool-list")
+        if "nfs-share" not in out:
+            computeVM.succeed(
+                'virsh pool-define-as --name "nfs-share" --type netfs --source-host "controllerVM" --source-path "nfs-root" --source-format "nfs" --target "/var/lib/libvirt/storage-pools/nfs-share"'
+            )
+            computeVM.succeed("virsh pool-start nfs-share")
 
-        # Define a libvirt network and automatically starts it
-        controllerVM.succeed("virsh net-create /etc/libvirt_test_network.xml")
+        out = controllerVM.succeed("virsh net-list")
+        if "libvirt-testnetwork" not in out:
+            # Define a libvirt network and automatically starts it
+            controllerVM.succeed("virsh net-create /etc/libvirt_test_network.xml")
 
     def setUp(self):
         # A restart of the libvirt daemon resets the logging configuration, so

Metadata

Metadata

Assignees

No one assigned

    Labels

    quality-of-lifeQualitfy of Life (QoL) improvements for developers.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions