summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCole Robinson <crobinso@redhat.com>2019-06-05 15:29:10 -0400
committerCole Robinson <crobinso@redhat.com>2019-06-05 16:35:34 -0400
commita0881bc6f21525ed636a0cec91249e6eec00ebe9 (patch)
tree92d5cebdf9d1393b18e87df556cbcb30a3fe3c14
parentca804c5b5e9ee3a6b5fdaa46360d714602f889e2 (diff)
downloadvirt-manager-a0881bc6f21525ed636a0cec91249e6eec00ebe9.tar.gz
nodedev: Fold PCIDevice into NodeDevice
-rw-r--r--tests/nodedev.py41
-rw-r--r--virtManager/addhardware.py3
-rw-r--r--virtManager/createnet.py2
-rw-r--r--virtinst/nodedev.py61
4 files changed, 47 insertions, 60 deletions
diff --git a/tests/nodedev.py b/tests/nodedev.py
index 0a15b38f..4985cd96 100644
--- a/tests/nodedev.py
+++ b/tests/nodedev.py
@@ -78,25 +78,24 @@ class TestNodeDev(unittest.TestCase):
self.assertEqual(dev.interface, "eth0")
self.assertEqual(dev.pretty_name(), "Interface eth0")
- def testPCIDevice1(self):
+ def testPCIDevice(self):
devname = "pci_1180_592"
- vals = {"name": "pci_1180_592", "parent": "pci_8086_2448",
- "device_type": NodeDevice.CAPABILITY_TYPE_PCI,
- "domain": "0", "bus": "21", "slot": "0", "function": "4",
- "product_id": "0x0592", "vendor_id": "0x1180",
- "product_name": "R5C592 Memory Stick Bus Host Adapter",
- "vendor_name": "Ricoh Co Ltd"}
- self._testCompare(devname, vals)
+ dev = self._nodeDevFromName(devname)
+ self.assertEqual(dev.pretty_name(),
+ "0000:15:00:4 Ricoh Co Ltd R5C592 Memory Stick Bus Host Adapter")
- def testPCIDevice2(self):
devname = "pci_8086_1049"
- vals = {"name": "pci_8086_1049", "parent": "computer",
- "device_type": NodeDevice.CAPABILITY_TYPE_PCI,
- "domain": "0", "bus": "0", "slot": "25", "function": "0",
- "product_id": "0x1049", "vendor_id": "0x8086",
- "product_name": "82566MM Gigabit Network Connection",
- "vendor_name": "Intel Corporation"}
- self._testCompare(devname, vals)
+ dev = self._nodeDevFromName(devname)
+ self.assertEqual(dev.pretty_name(),
+ "0000:00:19:0 Intel Corporation 82566MM Gigabit Network Connection")
+
+ nodename = "pci_8086_10fb"
+ obj = self._nodeDevFromName(nodename)
+ self.assertEqual(obj.is_pci_sriov(), True)
+ nodename = "pci_8086_2448"
+ obj = self._nodeDevFromName(nodename)
+ self.assertEqual(obj.is_pci_bridge(), True)
+
def testUSBDevDevice1(self):
devname = "usb_device_781_5151_2004453082054CA1BEEE"
@@ -213,16 +212,6 @@ class TestNodeDev(unittest.TestCase):
devfile = "pcidev.xml"
self._testNode2DeviceCompare(nodename, devfile)
- def testPCIParse(self):
- nodename = "pci_1180_476"
- obj = self._nodeDevFromName(nodename)
- self.assertEqual(obj.iommu_group, 3)
-
- def testNodeDevSRIOV(self):
- nodename = "pci_8086_10fb"
- obj = self._nodeDevFromName(nodename)
- self.assertEqual(obj.capability_type, "virt_functions")
-
def testNodeDevFail(self):
nodename = "usb_device_1d6b_1_0000_00_1d_1_if0"
devfile = ""
diff --git a/virtManager/addhardware.py b/virtManager/addhardware.py
index a24130ee..a1701702 100644
--- a/virtManager/addhardware.py
+++ b/virtManager/addhardware.py
@@ -538,8 +538,7 @@ class vmmAddHardware(vmmGObjectUI):
for dev in devs:
if devtype == "usb_device" and dev.xmlobj.is_linux_root_hub():
continue
- if (devtype == "pci" and
- dev.xmlobj.capability_type == "pci-bridge"):
+ if dev.xmlobj.is_pci_bridge():
continue
prettyname = dev.xmlobj.pretty_name()
diff --git a/virtManager/createnet.py b/virtManager/createnet.py
index a323e4fc..272ed63b 100644
--- a/virtManager/createnet.py
+++ b/virtManager/createnet.py
@@ -159,7 +159,7 @@ class vmmCreateNetwork(vmmGObjectUI):
devprettynames = []
ifnames = []
for pcidev in self.conn.filter_nodedevs("pci"):
- if pcidev.xmlobj.capability_type != "virt_functions":
+ if not pcidev.xmlobj.is_pci_sriov():
continue
devdesc = pcidev.xmlobj.pretty_name()
for netdev in self.conn.filter_nodedevs("net"):
diff --git a/virtinst/nodedev.py b/virtinst/nodedev.py
index 52c4b4af..1d836260 100644
--- a/virtinst/nodedev.py
+++ b/virtinst/nodedev.py
@@ -110,7 +110,15 @@ class NodeDevice(XMLBuilder):
return None
def compare_to_hostdev(self, hostdev):
- ignore = hostdev
+ if self.device_type == "pci":
+ if hostdev.type != self.device_type:
+ return False
+
+ return (_compare_int(self.domain, hostdev.domain) and
+ _compare_int(self.bus, hostdev.bus) and
+ _compare_int(self.slot, hostdev.slot) and
+ _compare_int(self.function, hostdev.function))
+
return False
def pretty_name(self):
@@ -124,9 +132,25 @@ class NodeDevice(XMLBuilder):
if self.device_type == "net":
if self.interface:
ret = _("Interface %s") % self.interface
+ if self.device_type == "pci":
+ devstr = "%.4X:%.2X:%.2X:%X" % (int(self.domain),
+ int(self.bus),
+ int(self.slot),
+ int(self.function))
+ ret = "%s %s %s" % (devstr, self._vendor_name, self._product_name)
return ret
+ ########################
+ # XML helper functions #
+ ########################
+
+ def is_pci_sriov(self):
+ return self._capability_type == "virt_functions"
+ def is_pci_bridge(self):
+ return self._capability_type == "pci-bridge"
+
+
##################
# XML properties #
##################
@@ -134,38 +158,15 @@ class NodeDevice(XMLBuilder):
# type='net' options
interface = XMLProperty("./capability/interface")
-
-class PCIDevice(NodeDevice):
+ # type='pci' options
domain = XMLProperty("./capability/domain")
bus = XMLProperty("./capability/bus")
slot = XMLProperty("./capability/slot")
function = XMLProperty("./capability/function")
+ _product_name = XMLProperty("./capability/product")
+ _vendor_name = XMLProperty("./capability/vendor")
+ _capability_type = XMLProperty("./capability/capability/@type")
- product_name = XMLProperty("./capability/product")
- product_id = XMLProperty("./capability/product/@id")
- vendor_name = XMLProperty("./capability/vendor")
- vendor_id = XMLProperty("./capability/vendor/@id")
-
- capability_type = XMLProperty("./capability/capability/@type")
-
- iommu_group = XMLProperty("./capability/iommuGroup/@number", is_int=True)
-
- def pretty_name(self):
- devstr = "%.4X:%.2X:%.2X:%X" % (int(self.domain),
- int(self.bus),
- int(self.slot),
- int(self.function))
-
- return "%s %s %s" % (devstr, self.vendor_name, self.product_name)
-
- def compare_to_hostdev(self, hostdev):
- if hostdev.type != self.device_type:
- return False
-
- return (_compare_int(self.domain, hostdev.domain) and
- _compare_int(self.bus, hostdev.bus) and
- _compare_int(self.slot, hostdev.slot) and
- _compare_int(self.function, hostdev.function))
class USBDevice(NodeDevice):
@@ -373,9 +374,7 @@ def _AddressStringToNodedev(conn, addrstr):
def _typeToDeviceClass(t):
- if t == NodeDevice.CAPABILITY_TYPE_PCI:
- return PCIDevice
- elif t == NodeDevice.CAPABILITY_TYPE_USBDEV:
+ if t == NodeDevice.CAPABILITY_TYPE_USBDEV:
return USBDevice
elif t == NodeDevice.CAPABILITY_TYPE_USBBUS:
return USBBus