Change in vdsm[master]: janitorial: factorize key removals from Vm.conf
fromani at redhat.com
fromani at redhat.com
Thu Dec 19 10:59:07 UTC 2013
Francesco Romani has uploaded a new change for review.
Change subject: janitorial: factorize key removals from Vm.conf
......................................................................
janitorial: factorize key removals from Vm.conf
introduce a common method to del items from Vm.conf.
Previously, the code was scattered in a few places, using two
different idioms (locking elided in the examples for the sake of
brevity)
if key in self.conf:
del self.conf[key]
vs
try:
del self.conf[key]
except:
pass
the benefit of this patch, beyond the minor cleanup and the
removal of a couple of except: clauses, is there is now one
code path to remove keys. Future extension may include
a debug message when trying to remove an inexistent key.
Change-Id: Ib5a3da3fea0346f5f75c2f9d60c995aaf7214c6d
Signed-off-by: Francesco Romani <fromani at redhat.com>
---
M vdsm/vm.py
1 file changed, 7 insertions(+), 13 deletions(-)
git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/56/22556/1
diff --git a/vdsm/vm.py b/vdsm/vm.py
index 1358b09..6747c14 100644
--- a/vdsm/vm.py
+++ b/vdsm/vm.py
@@ -2147,15 +2147,9 @@
if self._initTimePauseCode == 'ENOSPC':
self.cont()
else:
- try:
- with self._confLock:
- del self.conf['pauseCode']
- except:
- pass
+ self._delConfKey('pauseCode')
- if 'recover' in self.conf:
- with self._confLock:
- del self.conf['recover']
+ self._delConfKey('recover')
self.saveState()
except Exception as e:
if 'recover' in self.conf:
@@ -2475,6 +2469,10 @@
raise RuntimeError('waiting more that %ss for _guestCpuLock' %
timeout)
+ def _delConfKey(self, key):
+ with self._confLock:
+ self.conf.pop(key, None)
+
def cont(self, afterState='Up', guestCpuLocked=False):
if not guestCpuLocked:
self._acquireCpuLockWithTimeout()
@@ -2486,11 +2484,7 @@
if hasattr(self, 'updateGuestCpuRunning'):
self.updateGuestCpuRunning()
self._lastStatus = afterState
- try:
- with self._confLock:
- del self.conf['pauseCode']
- except:
- pass
+ self._delConfKey('pauseCode')
return {'status': doneCode, 'output': ['']}
finally:
if not guestCpuLocked:
--
To view, visit http://gerrit.ovirt.org/22556
To unsubscribe, visit http://gerrit.ovirt.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ib5a3da3fea0346f5f75c2f9d60c995aaf7214c6d
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