summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorzhanghao <zhanghao2_yewu@cmss.chinamobile.com>2020-10-12 14:10:14 -0400
committerzhanghao <zhanghao2_yewu@cmss.chinamobile.com>2020-10-31 08:26:19 +0000
commit115fe350ad7156a82c9d50e5d39a61e549d2603d (patch)
tree7b534f136a8b3b0656998f1039bf1b04c4d0995b
parent61717ff9d2104c6c53bf80107d6c3edc85ca2d79 (diff)
downloadnova-115fe350ad7156a82c9d50e5d39a61e549d2603d.tar.gz
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 4a4f12678af76101afac0ca15cc36bfa64017818)
-rw-r--r--nova/tests/unit/virt/libvirt/test_designer.py13
-rw-r--r--nova/tests/unit/virt/libvirt/test_vif.py28
-rw-r--r--nova/virt/libvirt/designer.py4
-rw-r--r--nova/virt/libvirt/vif.py2
4 files changed, 27 insertions, 20 deletions
diff --git a/nova/tests/unit/virt/libvirt/test_designer.py b/nova/tests/unit/virt/libvirt/test_designer.py
index bb5b8e9f72..14a896eb17 100644
--- a/nova/tests/unit/virt/libvirt/test_designer.py
+++ b/nova/tests/unit/virt/libvirt/test_designer.py
@@ -207,6 +207,19 @@ class DesignerTestCase(test.NoDBTestCase):
self.assertEqual(512, conf.vhost_rx_queue_size)
self.assertIsNone(conf.vhost_tx_queue_size)
+ def test_set_vif_host_backend_vhostuser_config_tapname(self):
+ conf = config.LibvirtConfigGuestInterface()
+ designer.set_vif_host_backend_vhostuser_config(conf, 'fake-mode',
+ 'fake-path', None, None,
+ 'fake-tap')
+ self.assertEqual('vhostuser', conf.net_type)
+ self.assertEqual('unix', conf.vhostuser_type)
+ self.assertEqual('fake-mode', conf.vhostuser_mode)
+ self.assertEqual('fake-path', conf.vhostuser_path)
+ self.assertIsNone(conf.vhost_rx_queue_size)
+ self.assertIsNone(conf.vhost_tx_queue_size)
+ self.assertEqual('fake-tap', conf.target_dev)
+
def test_set_vif_mtu_config(self):
conf = config.LibvirtConfigGuestInterface()
designer.set_vif_mtu_config(conf, 9000)
diff --git a/nova/tests/unit/virt/libvirt/test_vif.py b/nova/tests/unit/virt/libvirt/test_vif.py
index 1bfc532da6..b77d704bab 100644
--- a/nova/tests/unit/virt/libvirt/test_vif.py
+++ b/nova/tests/unit/virt/libvirt/test_vif.py
@@ -556,6 +556,12 @@ class LibvirtVifTestCase(test.NoDBTestCase):
pci_slot_want = vif['profile']['pci_slot']
self.assertEqual(pci_slot, pci_slot_want)
+ def _assertQueueSizeEquals(self, node, rx_want, tx_want):
+ rx_queue_size = node.find("driver").get("rx_queue_size")
+ tx_queue_size = node.find("driver").get("tx_queue_size")
+ self.assertEqual(rx_queue_size, rx_want)
+ self.assertEqual(tx_queue_size, tx_want)
+
def _assertXmlEqual(self, expectedXmlstr, actualXmlstr):
if not isinstance(actualXmlstr, six.string_types):
actualXmlstr = etree.tostring(actualXmlstr, encoding='unicode',
@@ -1296,24 +1302,8 @@ class LibvirtVifTestCase(test.NoDBTestCase):
self.flags(tx_queue_size=1024, group='libvirt')
d = vif.LibvirtGenericVIFDriver()
xml = self._get_instance_xml(d, self.vif_vhostuser)
- self._assertXmlEqual("""
- <domain type="qemu">
- <uuid>fake-uuid</uuid>
- <name>fake-name</name>
- <memory>102400</memory>
- <vcpu>4</vcpu>
- <os>
- <type>None</type>
- </os>
- <devices>
- <interface type="vhostuser">
- <mac address="ca:fe:de:ad:be:ef"/>
- <model type="virtio"/>
- <driver rx_queue_size="512" tx_queue_size="1024"/>
- <source mode="client" path="/tmp/vif-xxx-yyy-zzz" type="unix"/>
- </interface>
- </devices>
- </domain>""", xml)
+ node = self._get_node(xml)
+ self._assertQueueSizeEquals(node, "512", "1024")
def test_vhostuser_driver_no_path(self):
d = vif.LibvirtGenericVIFDriver()
@@ -1554,6 +1544,7 @@ class LibvirtVifTestCase(test.NoDBTestCase):
<model type="virtio"/>
<source mode="client"
path="/var/run/openvswitch/vhudc065497-3c" type="unix"/>
+ <target dev="vhudc065497-3c"/>
</interface>"""
self._test_config_os_vif(os_vif_type, vif_type, expected_xml)
@@ -1591,6 +1582,7 @@ class LibvirtVifTestCase(test.NoDBTestCase):
<model type="virtio"/>
<source mode="client"
path="/var/run/openvswitch/vhudc065497-3c" type="unix"/>
+ <target dev="nicdc065497-3c"/>
</interface>"""
self._test_config_os_vif(os_vif_type, vif_type, expected_xml)
diff --git a/nova/virt/libvirt/designer.py b/nova/virt/libvirt/designer.py
index c18d104e6b..3677ed5280 100644
--- a/nova/virt/libvirt/designer.py
+++ b/nova/virt/libvirt/designer.py
@@ -133,7 +133,7 @@ def set_vif_host_backend_direct_config(conf, devname, mode="passthrough"):
def set_vif_host_backend_vhostuser_config(conf, mode, path, rx_queue_size,
- tx_queue_size):
+ tx_queue_size, tapname=None):
"""Populate a LibvirtConfigGuestInterface instance
with host backend details for vhostuser socket.
@@ -147,6 +147,8 @@ def set_vif_host_backend_vhostuser_config(conf, mode, path, rx_queue_size,
conf.vhost_rx_queue_size = rx_queue_size
if tx_queue_size:
conf.vhost_tx_queue_size = tx_queue_size
+ if tapname:
+ conf.target_dev = tapname
def set_vif_mtu_config(conf, mtu):
diff --git a/nova/virt/libvirt/vif.py b/nova/virt/libvirt/vif.py
index bf332a6b85..5c87223baf 100644
--- a/nova/virt/libvirt/vif.py
+++ b/nova/virt/libvirt/vif.py
@@ -462,7 +462,7 @@ class LibvirtGenericVIFDriver(object):
designer.set_vif_host_backend_vhostuser_config(
conf, vif.mode, vif.path, CONF.libvirt.rx_queue_size,
- CONF.libvirt.tx_queue_size)
+ CONF.libvirt.tx_queue_size, vif.vif_name)
def _set_config_VIFHostDevice(self, instance, vif, conf):
if vif.dev_type == osv_fields.VIFHostDeviceDevType.ETHERNET: