Change in vdsm[master]: vm: rename buildConfDevices

fromani at redhat.com fromani at redhat.com
Thu Oct 30 14:35:44 UTC 2014


Francesco Romani has uploaded a new change for review.

Change subject: vm: rename buildConfDevices
......................................................................

vm: rename buildConfDevices

Them Vm.buildConfDevices method is not building configuration.
It is rather making sure the device configuration structure
is correct and in the form VDSM expect.

There is indeed fallback code in the case Engine is older,
but still this is more normalization than build.

This patch rearranges the method flows, with no
changes in behaviour, to reflect the real purpose
of the method.

Change-Id: I1df2a31458a25e06f3713bc4dd978bf4d9ea2439
Signed-off-by: Francesco Romani <fromani at redhat.com>
---
M tests/vmTests.py
M tests/vmfakelib.py
M vdsm/clientIF.py
M vdsm/virt/vm.py
4 files changed, 18 insertions(+), 12 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/65/34665/1

diff --git a/tests/vmTests.py b/tests/vmTests.py
index 6eecdcc..6daeeec 100644
--- a/tests/vmTests.py
+++ b/tests/vmTests.py
@@ -1516,7 +1516,8 @@
                    {'type': 'graphics', 'device': 'vnc', 'port': '-1'}]
 
         with fake.VM(self.VM_PARAMS, devices) as testvm:
-            testvm._updateDevices(testvm.buildConfDevices())
+            testvm._updateDevices(
+                testvm.setupDevicesConf(testvm.conf['devices']))
             res = testvm.getStats()
             self.assertIn('displayPort', res)
             self.assertEqual(res['displayType'],
@@ -1609,13 +1610,13 @@
         for conf in self.confDisplay:
             conf.update(self.conf)
             with fake.VM(conf) as testvm:
-                devs = testvm.buildConfDevices()
+                devs = testvm.setupDevicesConf(testvm.conf['devices'])
                 self.assertTrue(devs['graphics'])
 
     def testGraphicsDevice(self):
         for dev in self.confDeviceGraphics:
             with fake.VM(self.conf, dev) as testvm:
-                devs = testvm.buildConfDevices()
+                devs = testvm.setupDevicesConf(testvm.conf['devices'])
                 self.assertTrue(devs['graphics'])
 
     def testGraphicsDeviceMixed(self):
@@ -1627,7 +1628,7 @@
             conf.update(self.conf)
             for dev in self.confDeviceGraphics:
                 with fake.VM(self.conf, dev) as testvm:
-                    devs = testvm.buildConfDevices()
+                    devs = testvm.setupDevicesConf(testvm.conf['devices'])
                     self.assertEqual(len(devs['graphics']), 1)
                     self.assertEqual(devs['graphics'][0]['device'],
                                      dev[0]['device'])
@@ -1673,7 +1674,7 @@
         devices = [{'type': 'graphics', 'device': primary},
                    {'type': 'graphics', 'device': secondary}]
         with fake.VM(self.conf, devices) as testvm:
-            devs = testvm.buildConfDevices()
+            devs = testvm.setupDevicesConf(testvm.conf['devices'])
             self.assertTrue(len(devs['graphics']) == 2)
 
     @permutations([['vnc'], ['spice']])
@@ -1681,7 +1682,9 @@
         devices = [{'type': 'graphics', 'device': devType},
                    {'type': 'graphics', 'device': devType}]
         with fake.VM(self.conf, devices) as testvm:
-            self.assertRaises(ValueError, testvm.buildConfDevices)
+            self.assertRaises(ValueError,
+                              testvm.setupDevicesConf,
+                              testvm.conf['devices'])
 
 
 @expandPermutations
diff --git a/tests/vmfakelib.py b/tests/vmfakelib.py
index 83c5b7a..1baa681 100644
--- a/tests/vmfakelib.py
+++ b/tests/vmfakelib.py
@@ -169,6 +169,8 @@
                                (libvirtconnection, 'get', Connection)]):
             vmParams = {'vmId': 'TESTING'}
             vmParams.update({} if params is None else params)
+            if 'devices' not in vmParams:
+                vmParams['devices'] = tuple()
             cif = ClientIF()
             fake = vm.Vm(cif, vmParams)
             cif.vmContainer[fake.id] = fake
diff --git a/vdsm/clientIF.py b/vdsm/clientIF.py
index 440e5e7..24087c2 100644
--- a/vdsm/clientIF.py
+++ b/vdsm/clientIF.py
@@ -457,8 +457,9 @@
                 try:
                     # Do not prepare volumes when system goes down
                     if self._enabled:
-                        vmObj.preparePaths(
-                            vmObj.buildConfDevices()[vm.DISK_DEVICES])
+                        devices = vmObj.setupDevicesConf(
+                            vmObj.conf.get('devices'))
+                        vmObj.preparePaths(devices[vm.DISK_DEVICES])
                 except:
                     self.log.error("Vm %s recovery failed",
                                    vmId, exc_info=True)
diff --git a/vdsm/virt/vm.py b/vdsm/virt/vm.py
index 87c6517..9556484 100644
--- a/vdsm/virt/vm.py
+++ b/vdsm/virt/vm.py
@@ -1385,7 +1385,7 @@
                 'truesize': 0})
         return removables
 
-    def buildConfDevices(self):
+    def setupDevicesConf(self, devconf):
         """
         Return the "devices" section of this Vm's conf.
         If missing, create it according to old API.
@@ -1395,7 +1395,7 @@
         # For BC we need to save previous behaviour for old type parameters.
         # The new/old type parameter will be distinguished
         # by existence/absence of the 'devices' key
-        if self.conf.get('devices') is None:
+        if devconf is None:
             devices[DISK_DEVICES] = self.getConfDrives()
             devices[NIC_DEVICES] = self.getConfNetworkInterfaces()
             devices[SOUND_DEVICES] = self.getConfSound()
@@ -1403,7 +1403,7 @@
             devices[GRAPHICS_DEVICES] = self.getConfGraphics()
             devices[CONTROLLER_DEVICES] = self.getConfController()
         else:
-            for dev in self.conf.get('devices'):
+            for dev in devconf:
                 try:
                     devices[dev['type']].append(dev)
                 except KeyError:
@@ -2639,7 +2639,7 @@
 
     def _run(self):
         self.log.info("VM wrapper has started")
-        devices = self.buildConfDevices()
+        devices = self.setupDevicesConf(self.conf.get('devices'))
 
         # recovery flow note:
         # we do not start disk stats collection here since


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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I1df2a31458a25e06f3713bc4dd978bf4d9ea2439
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Francesco Romani <fromani at redhat.com>


More information about the vdsm-patches mailing list