Skip to content

Commit 115fe35

Browse files
author
zhanghao
committed
Fix virsh domifstat to get vhostuser vif statistics
When a DPDK VM attaches an interface, libvirt can not automatically generate "<target dev='vhuXXX'/>" in XML file, which causes virsh domifstat query to fail. Change-Id: Id4e5b52af521b5f3a206e87bf024fd1e47fc4824 Closes-Bug: #1899431 (cherry picked from commit 4a4f126)
1 parent 61717ff commit 115fe35

File tree

4 files changed

+27
-20
lines changed

4 files changed

+27
-20
lines changed

nova/tests/unit/virt/libvirt/test_designer.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,19 @@ def test_set_vif_host_backend_vhostuser_config_rx_queue_size(self):
207207
self.assertEqual(512, conf.vhost_rx_queue_size)
208208
self.assertIsNone(conf.vhost_tx_queue_size)
209209

210+
def test_set_vif_host_backend_vhostuser_config_tapname(self):
211+
conf = config.LibvirtConfigGuestInterface()
212+
designer.set_vif_host_backend_vhostuser_config(conf, 'fake-mode',
213+
'fake-path', None, None,
214+
'fake-tap')
215+
self.assertEqual('vhostuser', conf.net_type)
216+
self.assertEqual('unix', conf.vhostuser_type)
217+
self.assertEqual('fake-mode', conf.vhostuser_mode)
218+
self.assertEqual('fake-path', conf.vhostuser_path)
219+
self.assertIsNone(conf.vhost_rx_queue_size)
220+
self.assertIsNone(conf.vhost_tx_queue_size)
221+
self.assertEqual('fake-tap', conf.target_dev)
222+
210223
def test_set_vif_mtu_config(self):
211224
conf = config.LibvirtConfigGuestInterface()
212225
designer.set_vif_mtu_config(conf, 9000)

nova/tests/unit/virt/libvirt/test_vif.py

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -556,6 +556,12 @@ def _assertPciEqual(self, node, vif, type=None):
556556
pci_slot_want = vif['profile']['pci_slot']
557557
self.assertEqual(pci_slot, pci_slot_want)
558558

559+
def _assertQueueSizeEquals(self, node, rx_want, tx_want):
560+
rx_queue_size = node.find("driver").get("rx_queue_size")
561+
tx_queue_size = node.find("driver").get("tx_queue_size")
562+
self.assertEqual(rx_queue_size, rx_want)
563+
self.assertEqual(tx_queue_size, tx_want)
564+
559565
def _assertXmlEqual(self, expectedXmlstr, actualXmlstr):
560566
if not isinstance(actualXmlstr, six.string_types):
561567
actualXmlstr = etree.tostring(actualXmlstr, encoding='unicode',
@@ -1296,24 +1302,8 @@ def test_vhostuser_driver_queue_sizes(self):
12961302
self.flags(tx_queue_size=1024, group='libvirt')
12971303
d = vif.LibvirtGenericVIFDriver()
12981304
xml = self._get_instance_xml(d, self.vif_vhostuser)
1299-
self._assertXmlEqual("""
1300-
<domain type="qemu">
1301-
<uuid>fake-uuid</uuid>
1302-
<name>fake-name</name>
1303-
<memory>102400</memory>
1304-
<vcpu>4</vcpu>
1305-
<os>
1306-
<type>None</type>
1307-
</os>
1308-
<devices>
1309-
<interface type="vhostuser">
1310-
<mac address="ca:fe:de:ad:be:ef"/>
1311-
<model type="virtio"/>
1312-
<driver rx_queue_size="512" tx_queue_size="1024"/>
1313-
<source mode="client" path="/tmp/vif-xxx-yyy-zzz" type="unix"/>
1314-
</interface>
1315-
</devices>
1316-
</domain>""", xml)
1305+
node = self._get_node(xml)
1306+
self._assertQueueSizeEquals(node, "512", "1024")
13171307

13181308
def test_vhostuser_driver_no_path(self):
13191309
d = vif.LibvirtGenericVIFDriver()
@@ -1554,6 +1544,7 @@ def test_config_os_vif_vhostuser(self):
15541544
<model type="virtio"/>
15551545
<source mode="client"
15561546
path="/var/run/openvswitch/vhudc065497-3c" type="unix"/>
1547+
<target dev="vhudc065497-3c"/>
15571548
</interface>"""
15581549

15591550
self._test_config_os_vif(os_vif_type, vif_type, expected_xml)
@@ -1591,6 +1582,7 @@ def test_config_os_vif_agilio_ovs_forwarder(self):
15911582
<model type="virtio"/>
15921583
<source mode="client"
15931584
path="/var/run/openvswitch/vhudc065497-3c" type="unix"/>
1585+
<target dev="nicdc065497-3c"/>
15941586
</interface>"""
15951587

15961588
self._test_config_os_vif(os_vif_type, vif_type, expected_xml)

nova/virt/libvirt/designer.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ def set_vif_host_backend_direct_config(conf, devname, mode="passthrough"):
133133

134134

135135
def set_vif_host_backend_vhostuser_config(conf, mode, path, rx_queue_size,
136-
tx_queue_size):
136+
tx_queue_size, tapname=None):
137137
"""Populate a LibvirtConfigGuestInterface instance
138138
with host backend details for vhostuser socket.
139139
@@ -147,6 +147,8 @@ def set_vif_host_backend_vhostuser_config(conf, mode, path, rx_queue_size,
147147
conf.vhost_rx_queue_size = rx_queue_size
148148
if tx_queue_size:
149149
conf.vhost_tx_queue_size = tx_queue_size
150+
if tapname:
151+
conf.target_dev = tapname
150152

151153

152154
def set_vif_mtu_config(conf, mtu):

nova/virt/libvirt/vif.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,7 @@ def _set_config_VIFVHostUser(self, instance, vif, conf):
462462

463463
designer.set_vif_host_backend_vhostuser_config(
464464
conf, vif.mode, vif.path, CONF.libvirt.rx_queue_size,
465-
CONF.libvirt.tx_queue_size)
465+
CONF.libvirt.tx_queue_size, vif.vif_name)
466466

467467
def _set_config_VIFHostDevice(self, instance, vif, conf):
468468
if vif.dev_type == osv_fields.VIFHostDeviceDevType.ETHERNET:

0 commit comments

Comments
 (0)