Skip to content

Commit 576c950

Browse files
committed
virt: fix partial QoS removal
Since commit 50cd770, vdsm uses the old bandwidth value when updating (the QoS) on the NIC. Now lets say we have the following active on a VM NIC: <bandwidth> <inbound average="128000" peak="384000" burst="1024000" /> <outbound average="128000" burst="1024000" peak="384000" /> </bandwidth> And we pass the following update from the engine: <bandwidth> <outbound average="128000" burst="1024000" peak="384000"/> </bandwidth> Then it will preserve the inbound QoS, which is not something we want. This is a leftover from pre 'libvirt XML' oVirt era. Cause before it needed an empty 'inbound' tag to remove the inbound QoS. See the notes in the above commit: 'It is deleted if it is in specParams but empty ({'inbound':{}}).' But as the complete XML is now passed to vdsm, we can just rely on the data coming from the engine, without the need to parse the old bandwidth data. Signed-off-by: Jean-Louis Dupond <jean-louis@dupond.be>
1 parent d0edfe6 commit 576c950

File tree

3 files changed

+25
-12
lines changed

3 files changed

+25
-12
lines changed

lib/vdsm/virt/vmdevices/network.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -302,18 +302,12 @@ def _filter_parameter_map(self):
302302
yield parameter['name'], parameter['value']
303303

304304
@staticmethod
305-
def get_bandwidth_xml(specParams, oldBandwidth=None):
305+
def get_bandwidth_xml(specParams):
306306
"""Returns a valid libvirt xml dom element object."""
307307
bandwidth = vmxml.Element('bandwidth')
308-
old = {} if oldBandwidth is None else dict(
309-
(vmxml.tag(elem), elem)
310-
for elem in vmxml.children(oldBandwidth))
311308
for key in ('inbound', 'outbound'):
312309
elem = specParams.get(key)
313-
if elem is None: # Use the old setting if present
314-
if key in old:
315-
bandwidth.appendChild(etree_element=old[key])
316-
elif elem:
310+
if elem:
317311
# Convert the values to string for adding them to the XML def
318312
attrs = dict((key, str(value)) for key, value in elem.items())
319313
bandwidth.appendChildWithArgs(key, **attrs)
@@ -487,7 +481,7 @@ def update_bandwidth_xml(iface, vnicXML, specParams=None):
487481
vmxml.remove_child(vnicXML, oldBandwidth)
488482
if (specParams and
489483
('inbound' in specParams or 'outbound' in specParams)):
490-
newBandwidth = iface.get_bandwidth_xml(specParams, oldBandwidth)
484+
newBandwidth = iface.get_bandwidth_xml(specParams)
491485
vmxml.append_child(vnicXML, newBandwidth)
492486

493487

tests/virt/device_test.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,13 +105,14 @@ def testInterfaceXMLBandwidthUpdate(self):
105105
<inbound average="1000" burst="1024" peak="5000"/>
106106
<outbound average="128" burst="256"/>
107107
</bandwidth>"""
108-
NEW_OUT = {'outbound': {'average': 1042, 'burst': 128, 'peak': 500}}
108+
NEW_BW = {'inbound': {'average': 1000, 'burst': 1024, 'peak': 5000},
109+
'outbound': {'average': 1042, 'burst': 128, 'peak': 500}}
109110
updatedBwidthXML = """
110111
<bandwidth>
111112
<inbound average="1000" burst="1024" peak="5000"/>
112113
<outbound average="%(average)s" burst="%(burst)s"
113114
peak="%(peak)s"/>
114-
</bandwidth>""" % NEW_OUT['outbound']
115+
</bandwidth>""" % NEW_BW['outbound']
115116

116117
dev = {'nicModel': 'virtio', 'macAddr': '52:54:00:59:F5:3F',
117118
'network': 'ovirtmgmt', 'address': self.PCI_ADDR_DICT,
@@ -126,7 +127,7 @@ def testInterfaceXMLBandwidthUpdate(self):
126127
iface = vmdevices.network.Interface(self.log, **dev)
127128
orig_bandwidth = iface.getXML().findall('bandwidth')[0]
128129
self.assert_dom_xml_equal(orig_bandwidth, originalBwidthXML)
129-
bandwith = iface.get_bandwidth_xml(NEW_OUT, orig_bandwidth)
130+
bandwith = iface.get_bandwidth_xml(NEW_BW)
130131
self.assert_dom_xml_equal(bandwith, updatedBwidthXML)
131132

132133
def testInterfaceFilterUpdate(self):

tests/virt/devicexml_test.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,22 @@ def test_update_bandwidth_xml(self, base_spec_params):
162162
vmdevices.network.update_bandwidth_xml(dev, vnic_xml, specParams)
163163
self.assertXMLEqual(xmlutils.tostring(vnic_xml), XML)
164164

165+
specParams = {}
166+
XML = u"""
167+
<interface type='network'>
168+
<mac address="fake" />
169+
<source bridge='default'/>
170+
<link state="up"/>
171+
<bandwidth>
172+
<outbound average='128' peak='256' burst='256'/>
173+
</bandwidth>
174+
</interface>
175+
"""
176+
dev = vmdevices.network.Interface(self.log, **conf)
177+
vnic_xml = dev.getXML()
178+
vmdevices.network.update_bandwidth_xml(dev, vnic_xml, specParams)
179+
self.assertXMLEqual(xmlutils.tostring(vnic_xml), XML)
180+
165181
specParams = {}
166182
XML = u"""
167183
<interface type='network'>
@@ -170,6 +186,8 @@ def test_update_bandwidth_xml(self, base_spec_params):
170186
<link state="up"/>
171187
</interface>
172188
"""
189+
dev = vmdevices.network.Interface(self.log, **conf)
190+
vnic_xml = dev.getXML()
173191
vmdevices.network.update_bandwidth_xml(dev, vnic_xml, specParams)
174192
self.assertXMLEqual(xmlutils.tostring(vnic_xml), XML)
175193

0 commit comments

Comments
 (0)