From a217a59d95de95dcc434173028ea40459bc38ee6 Mon Sep 17 00:00:00 2001
From: Sebastian Mitterle <smitterl@redhat.com>
Date: Thu, 5 Sep 2024 06:19:44 -0400
Subject: [PATCH] attach_interface_with_model: don't attach incompatible
 controller

On s390x, pcie-to-pci-bridge is not available. Don't attach this.

Signed-off-by: Sebastian Mitterle <smitterl@redhat.com>
---
 .../attach_interface_with_model.cfg             |  1 +
 .../attach_interface_with_model.py              | 17 ++++++++++-------
 2 files changed, 11 insertions(+), 7 deletions(-)

diff --git a/libvirt/tests/cfg/virtual_network/hotplug/attach_detach_interface/attach_interface_with_model.cfg b/libvirt/tests/cfg/virtual_network/hotplug/attach_detach_interface/attach_interface_with_model.cfg
index 271d3ffe5f..7535c6dc3c 100644
--- a/libvirt/tests/cfg/virtual_network/hotplug/attach_detach_interface/attach_interface_with_model.cfg
+++ b/libvirt/tests/cfg/virtual_network/hotplug/attach_detach_interface/attach_interface_with_model.cfg
@@ -11,6 +11,7 @@
             pci_model = pcie-root-port
             s390-virtio:
                 check_pci_model = no
+                bridge_controller_needed = no
         - e1000e:
             only x86_64
             iface_driver = e1000e
diff --git a/libvirt/tests/src/virtual_network/hotplug/attach_detach_interface/attach_interface_with_model.py b/libvirt/tests/src/virtual_network/hotplug/attach_detach_interface/attach_interface_with_model.py
index 72f574cd1f..b249c2392b 100644
--- a/libvirt/tests/src/virtual_network/hotplug/attach_detach_interface/attach_interface_with_model.py
+++ b/libvirt/tests/src/virtual_network/hotplug/attach_detach_interface/attach_interface_with_model.py
@@ -52,18 +52,21 @@ def run(test, params, env):
     iface_driver = params.get("iface_driver")
     model_type = params.get("model_type")
     check_pci_model = params.get("check_pci_model", "yes") == "yes"
+    bridge_controller_needed = params.get("bridge_controller_needed", "yes") == "yes"
 
     vmxml = vm_xml.VMXML.new_from_inactive_dumpxml(vm_name)
     bkxml = vmxml.copy()
 
     try:
-        pci_controllers = vmxml.get_controllers("pci")
-        for controller in pci_controllers:
-            if controller.get("model") == "pcie-to-pci-bridge":
-                break
-        else:
-            controller_dict = {"model": "pcie-to-pci-bridge"}
-            libvirt_vmxml.modify_vm_device(vmxml, "controller", controller_dict, 50)
+        if bridge_controller_needed:
+            pci_controllers = vmxml.get_controllers("pci")
+            for controller in pci_controllers:
+                if controller.get("model") == "pcie-to-pci-bridge":
+                    break
+            else:
+                controller_dict = {"model": "pcie-to-pci-bridge"}
+                libvirt_vmxml.modify_vm_device(vmxml, "controller", controller_dict, 50)
+
         libvirt_vmxml.remove_vm_devices_by_type(vm, "interface")
         test.log.debug(f"VMXML of {vm_name}:\n{virsh.dumpxml(vm_name).stdout_text}")