Change in vdsm[master]: events: make sure to send only one event per status

piotr.kliczewski at gmail.com piotr.kliczewski at gmail.com
Fri Jun 19 13:12:19 UTC 2015


Piotr Kliczewski has uploaded a new change for review.

Change subject: events: make sure to send only one event per status
......................................................................

events: make sure to send only one event per status

Initially we made an assumption that engine can handle more than one
event containing the same status. The assumtion is not true and there
are flows where engine logic assumes only one status change.

Change-Id: I044a8f409ccdac4210784e21167bab320ddfe808
Signed-off-by: pkliczewski <piotr.kliczewski at gmail.com>
---
M vdsm/virt/vm.py
1 file changed, 22 insertions(+), 23 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/79/42579/1

diff --git a/vdsm/virt/vm.py b/vdsm/virt/vm.py
index 063bc3a..25a9b10 100644
--- a/vdsm/virt/vm.py
+++ b/vdsm/virt/vm.py
@@ -306,6 +306,7 @@
         else:
             self._lastStatus = vmstatus.WAIT_FOR_LAUNCH
         self._evaluatedStatus = None
+        self._eventLock = threading.Lock()
         self._migrationSourceThread = migration.SourceThread(self)
         self._kvmEnable = self.conf.get('kvmEnable', 'true')
         self._incomingMigrationFinished = threading.Event()
@@ -380,32 +381,30 @@
                 self._lastStatus = value
 
     def send_status_event(self):
-        vm_status = self._getVmStatus()['status']
+        with self._eventLock:
+            vm_status = self._getVmStatus()['status']
 
-        # this check is to reduce number of send events
-        # It is not safe since evaluatedStatus can change but
-        # in the worst case we will send the same event twice
-        if vm_status != self._evaluatedStatus:
-            self._evaluatedStatus = vm_status
-            stats = {
-                'status': vm_status,
-                'hash': str(hash((self._domain.devices_hash,
-                                  self.guestAgent.diskMappingHash))),
-            }
+            if vm_status != self._evaluatedStatus:
+                self._evaluatedStatus = vm_status
+                stats = {
+                    'status': vm_status,
+                    'hash': str(hash((self._domain.devices_hash,
+                                      self.guestAgent.diskMappingHash))),
+                }
 
-            # TODO: DOWN and exitCode must be set atomically. Once this is done
-            # we can remove the multiple conditions from this code.
-            if vm_status == vmstatus.DOWN:
-                if 'exitCode' in self.conf:
-                    stats['exitCode'] = self.conf['exitCode']
-                if 'exitMessage' in self.conf:
-                    stats['exitMessage'] = self.conf['exitMessage']
-                if 'exitReason' in self.conf:
-                    stats['exitReason'] = self.conf['exitReason']
+                # TODO: DOWN and exitCode must be set atomically. Once this is
+                # done we can remove the multiple conditions from this code.
+                if vm_status == vmstatus.DOWN:
+                    if 'exitCode' in self.conf:
+                        stats['exitCode'] = self.conf['exitCode']
+                    if 'exitMessage' in self.conf:
+                        stats['exitMessage'] = self.conf['exitMessage']
+                    if 'exitReason' in self.conf:
+                        stats['exitReason'] = self.conf['exitReason']
 
-            self.log.debug('Last status %s and evaluated status %s',
-                           self.lastStatus, vm_status)
-            self._notify('VM_status', stats)
+                self.log.debug('Last status %s and evaluated status %s',
+                               self.lastStatus, vm_status)
+                self._notify('VM_status', stats)
 
     def _notify(self, operation, params):
         sub_id = '|virt|%s|%s' % (operation, self.id)


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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I044a8f409ccdac4210784e21167bab320ddfe808
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Piotr Kliczewski <piotr.kliczewski at gmail.com>


More information about the vdsm-patches mailing list