Change in vdsm[master]: vm: move device setup into __init__

fromani at redhat.com fromani at redhat.com
Mon Nov 3 12:56:18 UTC 2014


Francesco Romani has uploaded a new change for review.

Change subject: vm: move device setup into __init__
......................................................................

vm: move device setup into __init__

Device hierarchy should never change except fot hotplug/hotunplug.
Besides avoiding RuntimeError, this is more correct and safer.

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


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/53/34753/1

diff --git a/tests/vmTestsData.py b/tests/vmTestsData.py
index 3316598..bb84412 100644
--- a/tests/vmTestsData.py
+++ b/tests/vmTestsData.py
@@ -29,7 +29,7 @@
     'smp': '1', 'cpuPinning': {}, 'numaTune': {}, 'maxVCpus': '160',
     'tabletEnable': False,
     'displayNetwork': 'mydisp', 'custom': {},
-    'guestNumaNodes': []},
+    'guestNumaNodes': [], 'devices': []},
 
     """<?xml version="1.0" encoding="utf-8"?>
         <domain type="kvm">
@@ -50,6 +50,11 @@
        path="/var/lib/libvirt/qemu/channels/%(vmId)s.org.qemu.guest_agent.0"/>
                 </channel>
                 <input bus="ps2" type="mouse"/>
+                <memballoon model="none"/>
+                <graphics autoport="yes" passwd="*****"
+       passwdValidTo="1970-01-01T00:00:01" port="-1" type="vnc">
+                    <listen network="vdsm-mydisp" type="network"/>
+                </graphics>
                 </devices>
                 <os>
                     <type arch="x86_64" machine="pc">hvm</type>
@@ -93,7 +98,7 @@
     'smp': '1', 'cpuPinning': {}, 'numaTune': {}, 'maxVCpus': '160',
     'tabletEnable': False,
     'displayNetwork': 'mydisp', 'custom': {},
-    'guestNumaNodes': []},
+    'guestNumaNodes': [], 'devices': []},
 
     """<?xml version="1.0" encoding="utf-8"?>
         <domain type="kvm"
@@ -116,6 +121,11 @@
                 </channel>
                 <input bus="usb" type="mouse"/>
                 <emulator>/usr/bin/qemu-system-ppc64</emulator>
+                <memballoon model="none"/>
+                <graphics autoport="yes" passwd="*****"
+       passwdValidTo="1970-01-01T00:00:01" port="-1" type="vnc">
+                    <listen network="vdsm-mydisp" type="network"/>
+                </graphics>
                 </devices>
                 <os>
                     <type arch="ppc64" machine="pc">hvm</type>
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..30a38da 100644
--- a/vdsm/clientIF.py
+++ b/vdsm/clientIF.py
@@ -457,8 +457,7 @@
                 try:
                     # Do not prepare volumes when system goes down
                     if self._enabled:
-                        vmObj.preparePaths(
-                            vmObj.buildConfDevices()[vm.DISK_DEVICES])
+                        vmObj.preparePaths(vmObj.getDiskDevicesConf())
                 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 05b15e9..05ee6b0 100644
--- a/vdsm/virt/vm.py
+++ b/vdsm/virt/vm.py
@@ -1302,6 +1302,8 @@
         self._liveMergeCleanupThreads = {}
         self._shutdownReason = None
 
+        self._setupDevices()
+
     def _get_lastStatus(self):
         PAUSED_STATES = (vmstatus.POWERING_DOWN, vmstatus.REBOOT_IN_PROGRESS,
                          vmstatus.UP)
@@ -1516,7 +1518,7 @@
             'type': GRAPHICS_DEVICES,
             'device': (
                 'spice'
-                if self.conf['display'] in ('qxl', 'qxlnc')
+                if self.conf.get('display') in ('qxl', 'qxlnc')
                 else 'vnc'),
             'specParams': makeSpecParams(self.conf)}]
 
@@ -2643,20 +2645,30 @@
         except Exception:
             self.log.warning('failed to set Vm niceness', exc_info=True)
 
+    def _setupDevices(self):
+        devices = self.buildConfDevices()
+
+        if not self.recovering:
+            self._updateDevices(devices)
+
+        for devType, devClass in self.DeviceMapping:
+            for dev in devices[devType]:
+                self._devices[devType].append(devClass(self.conf, self.log,
+                                                       **dev))
+
     def _run(self):
         self.log.info("VM wrapper has started")
-        devices = self.buildConfDevices()
-        self._updateDiskSizes(devices[DISK_DEVICES])
 
+        drives = list(self.getDiskDevicesConf())
+        self._updateDiskSizes(drives)
         # recovery flow note:
         # we do not start disk stats collection here since
         # in the recovery flow irs may not be ready yet.
         # Disk stats collection is started from clientIF at the end
         # of the recovery process.
         if not self.recovering:
-            self.preparePaths(devices[DISK_DEVICES])
-            self._prepareTransientDisks(devices[DISK_DEVICES])
-            self._updateDevices(devices)
+            self.preparePaths(drives)
+            self._prepareTransientDisks(drives)
             # We need to save conf here before we actually run VM.
             # It's not enough to save conf only on status changes as we did
             # before, because if vdsm will restarted between VM run and conf
@@ -2664,11 +2676,6 @@
             # So, to get proper device objects during VM recovery flow
             # we must to have updated conf before VM run
             self.saveState()
-
-        for devType, devClass in self.DeviceMapping:
-            for dev in devices[devType]:
-                self._devices[devType].append(devClass(self.conf, self.log,
-                                                       **dev))
 
         # We should set this event as a last part of drives initialization
         self._pathsPreparedEvent.set()
@@ -5362,6 +5369,11 @@
             if dev['type'] == BALLOON_DEVICES:
                 yield dev
 
+    def getDiskDevicesConf(self):
+        for dev in self.conf['devices']:
+            if dev['type'] == DISK_DEVICES:
+                yield dev
+
     @property
     def sdIds(self):
         """


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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I5e5a8e7916bb0c0d2519949397a5c1c64085e08e
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