Change in vdsm[master]: vmdevices: bootstrap sound module and isolate legacy parsing

mpolednik at redhat.com mpolednik at redhat.com
Wed Apr 22 11:59:03 UTC 2015


Martin Polednik has uploaded a new change for review.

Change subject: vmdevices: bootstrap sound module and isolate legacy parsing
......................................................................

vmdevices: bootstrap sound module and isolate legacy parsing

In a continuous effort to reduce size and broadness of vm.py, this
patch takes device-specific parsing method and encapsulates it in the
device module.

Change-Id: I16148a12dbdd8881c5488790481816303fecbfbb
Signed-off-by: Martin Polednik <mpolednik at redhat.com>
---
M debian/vdsm.install
M tests/deviceTests.py
M vdsm.spec.in
M vdsm/virt/vm.py
M vdsm/virt/vmdevices/Makefile.am
M vdsm/virt/vmdevices/__init__.py
M vdsm/virt/vmdevices/core.py
A vdsm/virt/vmdevices/sound.py
8 files changed, 55 insertions(+), 27 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/35/40135/1

diff --git a/debian/vdsm.install b/debian/vdsm.install
index 919398b..d18a328 100644
--- a/debian/vdsm.install
+++ b/debian/vdsm.install
@@ -167,5 +167,6 @@
 ./usr/share/vdsm/virt/vmdevices/hostdevice.py
 ./usr/share/vdsm/virt/vmdevices/hwclass.py
 ./usr/share/vdsm/virt/vmdevices/network.py
+./usr/share/vdsm/virt/vmdevices/sound.py
 ./usr/share/vdsm/virt/vmdevices/storage.py
 ./var/lib/polkit-1/localauthority/10-vendor.d/10-vdsm-libvirt-access.pkla
diff --git a/tests/deviceTests.py b/tests/deviceTests.py
index 1235cca..dd70aaa 100644
--- a/tests/deviceTests.py
+++ b/tests/deviceTests.py
@@ -252,7 +252,7 @@
     def testSoundXML(self):
         soundXML = '<sound model="ac97"/>'
         dev = {'device': 'ac97'}
-        sound = vmdevices.core.Sound(self.conf, self.log, **dev)
+        sound = vmdevices.sound.Sound(self.conf, self.log, **dev)
         self.assertXMLEqual(sound.getXML().toxml(), soundXML)
 
     def testVideoXML(self):
diff --git a/vdsm.spec.in b/vdsm.spec.in
index 93c7073..8a899fb 100644
--- a/vdsm.spec.in
+++ b/vdsm.spec.in
@@ -1109,6 +1109,7 @@
 %{_datadir}/%{vdsm_name}/virt/vmdevices/hostdevice.py*
 %{_datadir}/%{vdsm_name}/virt/vmdevices/hwclass.py*
 %{_datadir}/%{vdsm_name}/virt/vmdevices/network.py*
+%{_datadir}/%{vdsm_name}/virt/vmdevices/sound.py*
 %{_datadir}/%{vdsm_name}/virt/vmdevices/storage.py*
 %{_datadir}/%{vdsm_name}/tool
 
diff --git a/vdsm/virt/vm.py b/vdsm/virt/vm.py
index 901537d..831a29a 100644
--- a/vdsm/virt/vm.py
+++ b/vdsm/virt/vm.py
@@ -642,7 +642,7 @@
     _ongoingCreations = threading.BoundedSemaphore(4)
     DeviceMapping = ((hwclass.DISK, vmdevices.storage.Drive),
                      (hwclass.NIC, vmdevices.network.Interface),
-                     (hwclass.SOUND, vmdevices.core.Sound),
+                     (hwclass.SOUND, vmdevices.sound.Sound),
                      (hwclass.VIDEO, vmdevices.core.Video),
                      (hwclass.GRAPHICS, vmdevices.graphics.Graphics),
                      (hwclass.CONTROLLER, vmdevices.core.Controller),
@@ -821,7 +821,8 @@
                 vmdevices.storage.mapping_from_legacy_conf(self.conf,
                                                            self.arch)
             devices[hwclass.NIC] = self.getConfNetworkInterfaces()
-            devices[hwclass.SOUND] = self.getConfSound()
+            devices[hwclass.SOUND] = \
+                vmdevices.sound.mapping_from_legacy_conf(self.conf)
             devices[hwclass.VIDEO] = self.getConfVideo()
             devices[hwclass.GRAPHICS] = self.getConfGraphics()
             devices[hwclass.CONTROLLER] = self.getConfController()
@@ -932,17 +933,6 @@
                 if self.conf['display'] in ('qxl', 'qxlnc')
                 else 'vnc'),
             'specParams': vmdevices.graphics.makeSpecParams(self.conf)}]
-
-    def getConfSound(self):
-        """
-        Normalize sound device provided by conf.
-        """
-        scards = []
-        if self.conf.get('soundDevice'):
-            scards.append({'type': hwclass.SOUND,
-                           'device': self.conf.get('soundDevice')})
-
-        return scards
 
     def getConfNetworkInterfaces(self):
         """
diff --git a/vdsm/virt/vmdevices/Makefile.am b/vdsm/virt/vmdevices/Makefile.am
index 74dc033..576394a 100644
--- a/vdsm/virt/vmdevices/Makefile.am
+++ b/vdsm/virt/vmdevices/Makefile.am
@@ -26,5 +26,6 @@
 	hostdevice.py \
 	hwclass.py \
 	network.py \
+	sound.py \
 	storage.py \
 	$(NULL)
diff --git a/vdsm/virt/vmdevices/__init__.py b/vdsm/virt/vmdevices/__init__.py
index 9c83b89..72f2bd9 100644
--- a/vdsm/virt/vmdevices/__init__.py
+++ b/vdsm/virt/vmdevices/__init__.py
@@ -23,7 +23,8 @@
 from . import hwclass
 from . import graphics
 from . import network
+from . import sound
 from . import storage
 
 # Silence pyflakes
-core, graphics, hostdevice, hwclass, network, storage
+core, graphics, hostdevice, hwclass, network, sound, storage
diff --git a/vdsm/virt/vmdevices/core.py b/vdsm/virt/vmdevices/core.py
index 1eb50d0..90d66b3 100644
--- a/vdsm/virt/vmdevices/core.py
+++ b/vdsm/virt/vmdevices/core.py
@@ -122,18 +122,6 @@
         return card
 
 
-class Sound(Base):
-    __slots__ = ('address')
-
-    def getXML(self):
-        """
-        Create domxml for sound device
-        """
-        sound = self.createXmlElem('sound', None, ['address'])
-        sound.setAttrs(model=self.device)
-        return sound
-
-
 class Redir(Base):
     __slots__ = ('address',)
 
diff --git a/vdsm/virt/vmdevices/sound.py b/vdsm/virt/vmdevices/sound.py
new file mode 100644
index 0000000..167fb79
--- /dev/null
+++ b/vdsm/virt/vmdevices/sound.py
@@ -0,0 +1,46 @@
+#
+# Copyright 2015 Red Hat, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+#
+# Refer to the README and COPYING files for full details of the license
+#
+
+from . import hwclass
+from .core import Base
+
+
+def mapping_from_legacy_conf(conf):
+    """
+    Normalize sound device provided by conf.
+    """
+    scards = []
+    if conf.get('soundDevice'):
+        scards.append({'type': hwclass.SOUND,
+                       'device': conf.get('soundDevice')})
+
+    return scards
+
+
+class Sound(Base):
+    __slots__ = ('address')
+
+    def getXML(self):
+        """
+        Create domxml for sound device
+        """
+        sound = self.createXmlElem('sound', None, ['address'])
+        sound.setAttrs(model=self.device)
+        return sound


-- 
To view, visit https://gerrit.ovirt.org/40135
To unsubscribe, visit https://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I16148a12dbdd8881c5488790481816303fecbfbb
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Martin Polednik <mpolednik at redhat.com>


More information about the vdsm-patches mailing list