From ab0c99057b33cf1646b86ef95f0f1b7be16062d8 Mon Sep 17 00:00:00 2001 From: Cole Robinson Date: Wed, 5 Jun 2019 16:13:44 -0400 Subject: [PATCH] nodedev: Fold DRMDevice into NodeDevice --- tests/nodedev.py | 21 ++++++++---------- virtManager/gfxdetails.py | 6 ++---- virtinst/devices/graphics.py | 3 +-- virtinst/nodedev.py | 41 ++++++++++++++++++------------------ 4 files changed, 32 insertions(+), 39 deletions(-) diff --git a/tests/nodedev.py b/tests/nodedev.py index f7e3282a6..2eccee9d5 100644 --- a/tests/nodedev.py +++ b/tests/nodedev.py @@ -138,18 +138,15 @@ class TestNodeDev(unittest.TestCase): def testDRMDevice(self): devname = "drm_renderD129" - vals = {"name": "drm_renderD129", - "parent": "pci_0000_00_02_0", - "devnodes": [ - {"path": "/dev/dri/renderD129", "node_type": "dev"}, - {"path": "/dev/dri/by-path/pci-0000:00:02.0-render", "node_type": "link"}, - {"path": "/dev/dri/by-id/foo-render", "node_type": "link"} - ], - "device_type": NodeDevice.CAPABILITY_TYPE_DRM, - "drm_type": "render"} - dev = self._testCompare(devname, vals) - self.assertEqual(dev.drm_pretty_name(self.conn), - "0000:00:02:0 Intel Corporation HD Graphics 530 (render)") + dev = self._nodeDevFromName(devname) + self.assertEqual(dev.devnodes[0].path, "/dev/dri/renderD129") + self.assertEqual(dev.devnodes[0].node_type, "dev") + self.assertEqual(dev.devnodes[1].path, + "/dev/dri/by-path/pci-0000:00:02.0-render") + self.assertEqual(dev.devnodes[1].node_type, "link") + self.assertEqual(dev.is_drm_render(), True) + self.assertEqual(dev.pretty_name(), + "0000:00:02:0 Intel Corporation HD Graphics 530 (render)") # NodeDevice 2 Device XML tests diff --git a/virtManager/gfxdetails.py b/virtManager/gfxdetails.py index c2207dd69..8fb9a6789 100644 --- a/virtManager/gfxdetails.py +++ b/virtManager/gfxdetails.py @@ -106,12 +106,10 @@ class vmmGraphicsDetails(vmmGObjectUI): devs = self.conn.filter_nodedevs("drm") for i in devs: drm = i.xmlobj - if drm.drm_type != 'render': + if not drm.is_drm_render(): continue rendernode = drm.get_devnode().path - - model.append([rendernode, - i.xmlobj.drm_pretty_name(self.conn.get_backend())]) + model.append([rendernode, i.xmlobj.pretty_name()]) def _get_config_graphics_ports(self): port = uiutil.spin_get_helper(self.widget("graphics-port")) diff --git a/virtinst/devices/graphics.py b/virtinst/devices/graphics.py index 7b3c1e6ba..6ab316599 100644 --- a/virtinst/devices/graphics.py +++ b/virtinst/devices/graphics.py @@ -259,8 +259,7 @@ class DeviceGraphics(Device): if not self.rendernode and self.conn.check_support( self.conn.SUPPORT_CONN_SPICE_RENDERNODE): for nodedev in self.conn.fetch_all_nodedevs(): - if (nodedev.device_type != 'drm' or - nodedev.drm_type != 'render'): + if not nodedev.is_drm_render(): continue self.rendernode = nodedev.get_devnode().path break diff --git a/virtinst/nodedev.py b/virtinst/nodedev.py index b609b5243..3095c85fd 100644 --- a/virtinst/nodedev.py +++ b/virtinst/nodedev.py @@ -97,16 +97,6 @@ class NodeDevice(XMLBuilder): name = XMLProperty("./name") parent = XMLProperty("./parent") device_type = XMLProperty("./capability/@type") - devnodes = XMLChildProperty(DevNode) - - def get_devnode(self, parent="by-path"): - for d in self.devnodes: - paths = d.path.split(os.sep) - if len(paths) > 2 and paths[-2] == parent: - return d - if len(self.devnodes) > 0: - return self.devnodes[0] - return None def compare_to_hostdev(self, hostdev): if self.device_type == "pci": @@ -184,6 +174,11 @@ class NodeDevice(XMLBuilder): if self.device_type == "usb_device": return self._usb_pretty_name() + if self.device_type == "drm": + parent = NodeDevice.lookupNodedevFromString( + self.conn, self.parent) + return "%s (%s)" % (parent.pretty_name(), self._drm_type) + return self.name @@ -200,6 +195,9 @@ class NodeDevice(XMLBuilder): return (self.vendor_id == "0x1d6b" and self.product_id in ["0x0001", "0x0002", "0x0003"]) + def is_drm_render(self): + return self.device_type == "drm" and self._drm_type == "render" + ################## # XML properties # @@ -237,14 +235,18 @@ class NodeDevice(XMLBuilder): "./capability/capability[@type='removable']/media_available", is_int=True) + # type='drm' options + _drm_type = XMLProperty("./capability/type") + devnodes = XMLChildProperty(DevNode) -class DRMDevice(NodeDevice): - drm_type = XMLProperty("./capability/type") - - def drm_pretty_name(self, conn): - parent = NodeDevice.lookupNodedevFromString(conn, self.parent) - - return "%s (%s)" % (parent.pretty_name(), self.drm_type) + def get_devnode(self, parent="by-path"): + for d in self.devnodes: + paths = d.path.split(os.sep) + if len(paths) > 2 and paths[-2] == parent: + return d + if len(self.devnodes) > 0: + return self.devnodes[0] + return None def _AddressStringToHostdev(conn, addrstr): @@ -313,7 +315,4 @@ def _AddressStringToNodedev(conn, addrstr): def _typeToDeviceClass(t): - if t == NodeDevice.CAPABILITY_TYPE_DRM: - return DRMDevice - else: - return NodeDevice + return NodeDevice