Francesco Romani has uploaded a new change for review.

Change subject: virt: graphdev: switch to GraphicsDevice
......................................................................

virt: graphdev: switch to GraphicsDevice

use the new GraphicsDevice class instead
of the legacy method.

Change-Id: Id90608c8a5746b41951d85a93c897f69b2d78131
Signed-off-by: Francesco Romani <[email protected]>
---
M tests/vmTests.py
M vdsm/virt/vm.py
2 files changed, 43 insertions(+), 59 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/96/26896/1

diff --git a/tests/vmTests.py b/tests/vmTests.py
index 533ea98..9123183 100644
--- a/tests/vmTests.py
+++ b/tests/vmTests.py
@@ -412,14 +412,7 @@
 
         for vmConf, xml in zip(vmConfs, expectedXMLs):
             vmConf.update(self.conf)
-            domxml = vm._DomXML(vmConf, self.log,
-                                caps.Architecture.X86_64)
-            domxml.appendGraphics()
-            self.assertXML(domxml.dom, xml, 'devices/graphics')
-            if vmConf['display'] == 'qxl':
-                self.assertXML(domxml.dom, spiceChannelXML, 'devices/channel')
-
-            with FakeVM(vmConf) as fake:
+            with FakeVM(vmConf):
                 dev = vm.GraphicsDevice.getDeviceFromConf(vmConf)
                 graph = vm.GraphicsDevice(vmConf, self.log, **dev)
                 self.assertXML(graph.getXML(), xml)
diff --git a/vdsm/virt/vm.py b/vdsm/virt/vm.py
index e0d7903..d5299ba 100644
--- a/vdsm/virt/vm.py
+++ b/vdsm/virt/vm.py
@@ -793,56 +793,6 @@
         commandLine.appendChildWithArgs('qemu:arg', value='keyboard')
         self.dom.appendChild(commandLine)
 
-    def appendGraphics(self):
-        """
-        Add graphics section to domain xml.
-
-        <graphics autoport="yes" listen="0" type="vnc"/>
-
-        or
-
-        <graphics autoport="yes" keymap="en-us" listen="0" port="5910"
-                  tlsPort="5890" type="spice" passwd="foo"
-                  passwdValidTo="2010-04-09T15:51:00"/>
-        <channel type='spicevmc'>
-           <target type='virtio' name='com.redhat.spice.0'/>
-        </channel>
-        """
-        graphicsAttrs = {'port': self.conf['displayPort'], 'autoport': 'yes'}
-        if self.conf['display'] == 'vnc':
-            graphicsAttrs['type'] = 'vnc'
-        elif 'qxl' in self.conf['display']:
-            graphicsAttrs['type'] = 'spice'
-            graphicsAttrs['tlsPort'] = self.conf['displaySecurePort']
-
-        if self.conf.get('keyboardLayout'):
-            graphicsAttrs['keymap'] = self.conf['keyboardLayout']
-        if 'spiceDisableTicketing' not in self.conf:
-            graphicsAttrs['passwd'] = '*****'
-            graphicsAttrs['passwdValidTo'] = '1970-01-01T00:00:01'
-
-        graphics = XMLElement('graphics', **graphicsAttrs)
-
-        if 'qxl' in self.conf['display']:
-            if self.conf.get('spiceSecureChannels'):
-                for channel in self.conf['spiceSecureChannels'].split(','):
-                    graphics.appendChildWithArgs('channel', name=channel[1:],
-                                                 mode='secure')
-
-            vmc = XMLElement('channel', type='spicevmc')
-            vmc.appendChildWithArgs('target', type='virtio',
-                                    name='com.redhat.spice.0')
-            self._devices.appendChild(vmc)
-
-        if self.conf.get('displayNetwork'):
-            graphics.appendChildWithArgs('listen', type='network',
-                                         network=netinfo.LIBVIRT_NET_PREFIX +
-                                         self.conf.get('displayNetwork'))
-        else:
-            graphics.setAttrs(listen='0')
-
-        self._devices.appendChild(graphics)
-
     def appendEmulator(self):
         emulatorPath = '/usr/bin/qemu-system-' + self.arch
 
@@ -1640,6 +1590,7 @@
                      (NIC_DEVICES, NetworkInterfaceDevice),
                      (SOUND_DEVICES, SoundDevice),
                      (VIDEO_DEVICES, VideoDevice),
+                     (GRAPHICS_DEVICES, GraphicsDevice),
                      (CONTROLLER_DEVICES, ControllerDevice),
                      (GENERAL_DEVICES, GeneralDevice),
                      (BALLOON_DEVICES, BalloonDevice),
@@ -1860,8 +1811,14 @@
             devices[NIC_DEVICES] = self.getConfNetworkInterfaces()
             devices[SOUND_DEVICES] = self.getConfSound()
             devices[VIDEO_DEVICES] = self.getConfVideo()
+            devices[GRAPHICS_DEVICES] = self.getConfGraphics()
             devices[CONTROLLER_DEVICES] = self.getConfController()
         else:
+            # ensure backward compatibility
+            derivedGraphics = self.__legacyGraphics()
+            if derivedGraphics:
+                self.conf['devices'].append(derivedGraphics)
+
             for dev in self.conf.get('devices'):
                 try:
                     devices[dev['type']].append(dev)
@@ -1912,6 +1869,8 @@
             if len(devices[device]) > 1:
                 raise ValueError("only a single %s device is "
                                  "supported" % device)
+        if not devices[GRAPHICS_DEVICES]:
+            raise ValueError("at least one graphics device is required")
 
     def getConfController(self):
         """
@@ -1944,6 +1903,20 @@
                            'device': devType})
 
         return vcards
+
+    def getConfGraphics(self):
+        """
+        Normalize graphics device provided by conf.
+        """
+        graph = self.__legacyGraphics()
+        if graph is None:
+            graph = {
+                'type': GRAPHICS_DEVICES,
+                'device': 'spice',
+                'specParams': {
+                    'port': GraphicsDevice.LIBVIRT_PORT_AUTOSELECT}}
+        # else already normalized by adjustDisplayParams
+        return [graph]
 
     def getConfSound(self):
         """
@@ -2746,7 +2719,6 @@
                 self._qemuguestSocketFile.decode('utf-8'),
                 _QEMU_GA_DEVICE_NAME)
         domxml.appendInput()
-        domxml.appendGraphics()
 
         if self.arch == caps.Architecture.PPC64:
             domxml.appendEmulator()
@@ -2796,6 +2768,7 @@
         self._getUnderlyingDisplayPort()
         self._getUnderlyingSoundDeviceInfo()
         self._getUnderlyingVideoDeviceInfo()
+        self._getUnderlyingGraphicsDeviceInfo()
         self._getUnderlyingControllerDeviceInfo()
         self._getUnderlyingBalloonDeviceInfo()
         self._getUnderlyingWatchdogDeviceInfo()
@@ -4842,6 +4815,24 @@
                 self.log.debug('Found unknown drive: %s', diskDev)
                 self.conf['devices'].append(diskDev)
 
+    def _getUnderlyingGraphicsDeviceInfo(self):
+        """
+        Obtain graphics framebuffer devices info from libvirt.
+        Libvirt only allows 0 or 1 device of each type, so mapping between
+        _devices and conf.devices is based on this fact.
+        """
+        graphicsXml = _domParseStr(self._lastXMLDesc).childNodes[0]. \
+            getElementsByTagName('devices')[0].getElementsByTagName('graphics')
+
+        for gxml in graphicsXml:
+            graphicsType = gxml.getAttribute('type')
+
+            for dev in self.conf['devices']:
+                if dev['device'] == graphicsType:
+                    specParams = dev.get('specParams', {})
+                    specParams['port'] = gxml.getAttribute('port')
+                    specParams['tlsPort'] = gxml.getAttribute('tlsPort')
+
     def _getUnderlyingDisplayPort(self):
         """
         Obtain display port info from libvirt.


-- 
To view, visit http://gerrit.ovirt.org/26896
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Id90608c8a5746b41951d85a93c897f69b2d78131
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Francesco Romani <[email protected]>
_______________________________________________
vdsm-patches mailing list
[email protected]
https://lists.fedorahosted.org/mailman/listinfo/vdsm-patches

Reply via email to