From ade627ee801032b2f4a751c896ae6b6e2676b677 Mon Sep 17 00:00:00 2001 From: Jean-Louis Dupond Date: Fri, 17 May 2024 15:13:27 +0200 Subject: [PATCH] virt: remove bandwidth limit on nic update This patch fixes some logic error in the update_bandwidth_xml function. If you have a running VM with a NIC that has a QoS, it will contain a bandwidth setting in the XML. Now if you change the NIC to a vNIC Profile without QoS, it will not contain the 'inbound' and 'outbound' specParams, and the old QoS will never get removed (only after stop/start). So we take the removal of the bandwidth out of the if so the limit gets cleared correctly. Also adds test for this case. Signed-off-by: Jean-Louis Dupond --- lib/vdsm/virt/vmdevices/network.py | 6 +++--- tests/virt/devicexml_test.py | 11 +++++++++++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/lib/vdsm/virt/vmdevices/network.py b/lib/vdsm/virt/vmdevices/network.py index 9e79365ea..6c5f34f44 100644 --- a/lib/vdsm/virt/vmdevices/network.py +++ b/lib/vdsm/virt/vmdevices/network.py @@ -482,12 +482,12 @@ def update_port_xml(vnicXML, port_isolated): def update_bandwidth_xml(iface, vnicXML, specParams=None): + oldBandwidth = vmxml.find_first(vnicXML, 'bandwidth', None) + if oldBandwidth is not None: + vmxml.remove_child(vnicXML, oldBandwidth) if (specParams and ('inbound' in specParams or 'outbound' in specParams)): - oldBandwidth = vmxml.find_first(vnicXML, 'bandwidth', None) newBandwidth = iface.get_bandwidth_xml(specParams, oldBandwidth) - if oldBandwidth is not None: - vmxml.remove_child(vnicXML, oldBandwidth) vmxml.append_child(vnicXML, newBandwidth) diff --git a/tests/virt/devicexml_test.py b/tests/virt/devicexml_test.py index 6649dfe40..169adcdec 100644 --- a/tests/virt/devicexml_test.py +++ b/tests/virt/devicexml_test.py @@ -162,6 +162,17 @@ def test_update_bandwidth_xml(self, base_spec_params): vmdevices.network.update_bandwidth_xml(dev, vnic_xml, specParams) self.assertXMLEqual(xmlutils.tostring(vnic_xml), XML) + specParams = {} + XML = u""" + + + + + + """ + vmdevices.network.update_bandwidth_xml(dev, vnic_xml, specParams) + self.assertXMLEqual(xmlutils.tostring(vnic_xml), XML) + @expandPermutations class ParsingHelperTests(XMLTestCase):