[node-patches] Change in ovirt-node[master]: ovirt-node-upgrade: add lock file check to prevent parallel ...

Alon Bar-Lev alonbl at redhat.com
Mon Jul 1 20:19:30 UTC 2013


Alon Bar-Lev has posted comments on this change.

Change subject: ovirt-node-upgrade: add lock file check to prevent parallel runs
......................................................................


Patch Set 7: (8 inline comments)

....................................................
File scripts/ovirt-node-upgrade.py
Line 75: class LockFile(Base):
Line 76: 
Line 77:     def __init__(self):
Line 78:         super(LockFile, self).__init__()
Line 79:         self._pidfile = None
remove?
Line 80:         self._oldpid = None
Line 81:         lock_fd, self._lock_file = tempfile.mkstemp(prefix=".ovirtupgrade.")
Line 82:         os.close(lock_fd)
Line 83: 


Line 76: 
Line 77:     def __init__(self):
Line 78:         super(LockFile, self).__init__()
Line 79:         self._pidfile = None
Line 80:         self._oldpid = None
self._locked = False
Line 81:         lock_fd, self._lock_file = tempfile.mkstemp(prefix=".ovirtupgrade.")
Line 82:         os.close(lock_fd)
Line 83: 
Line 84:     def __enter__(self):


Line 90:     def _acquire(self):
Line 91:         self._logger.info("Acquiring Lock")
Line 92:         if os.path.exists(OVIRT_UPGRADE_LOCK):
Line 93:             with open(self._lock_file, "r") as f:
Line 94:                 self._oldpid = f.readline()
no need to store as member.
Line 95:                 if os.path.exists("/proc/%s" % self._oldpid):
Line 96:                     raise RuntimeError("You already have an instance of the" +
Line 97:                                        "program running")
Line 98:             os.remove(OVIRT_UPGRADE_LOCK)


Line 96:                     raise RuntimeError("You already have an instance of the" +
Line 97:                                        "program running")
Line 98:             os.remove(OVIRT_UPGRADE_LOCK)
Line 99:         try:
Line 100:             pidfile = open(self._lock_file, "w")
.

 with open(self._lock_file, "w") as f:
     f.write("%s" % os.getpid())
Line 101:             pidfile.write("%s" % os.getpid())
Line 102:             pidfile.close
Line 103:             os.symlink(self._lock_file, OVIRT_UPGRADE_LOCK)
Line 104:         except Exception as e:


Line 99:         try:
Line 100:             pidfile = open(self._lock_file, "w")
Line 101:             pidfile.write("%s" % os.getpid())
Line 102:             pidfile.close
Line 103:             os.symlink(self._lock_file, OVIRT_UPGRADE_LOCK)
self._locked = True
Line 104:         except Exception as e:
Line 105:             os.remove(self._lock_file)
Line 106:             self._logger.exception('Error: Upgrade Failed: %s', e)
Line 107:             raise RuntimeError("Unable to write lockfile")


Line 101:             pidfile.write("%s" % os.getpid())
Line 102:             pidfile.close
Line 103:             os.symlink(self._lock_file, OVIRT_UPGRADE_LOCK)
Line 104:         except Exception as e:
Line 105:             os.remove(self._lock_file)
no need as you do this at exit.
Line 106:             self._logger.exception('Error: Upgrade Failed: %s', e)
Line 107:             raise RuntimeError("Unable to write lockfile")
Line 108: 
Line 109:     def _remove(self):


Line 107:             raise RuntimeError("Unable to write lockfile")
Line 108: 
Line 109:     def _remove(self):
Line 110:         try:
Line 111:             if self._oldpid == os.getpid():
if self._locked:
Line 112:                 os.remove(OVIRT_UPGRADE_LOCK)
Line 113:                 if os.path.exists(self._lock_file):
Line 114:                     os.remove(self._lock_file)
Line 115:         except Exception as e:


Line 109:     def _remove(self):
Line 110:         try:
Line 111:             if self._oldpid == os.getpid():
Line 112:                 os.remove(OVIRT_UPGRADE_LOCK)
Line 113:                 if os.path.exists(self._lock_file):
this should be indent out
Line 114:                     os.remove(self._lock_file)
Line 115:         except Exception as e:
Line 116:             self._logger.exception('Error: Upgrade Failed: %s', e)
Line 117:             raise RuntimeError("Unable to remove lockfile")


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

Gerrit-MessageType: comment
Gerrit-Change-Id: Ifdd6553046d99cf9c9db29c1c899dc93e8ad733a
Gerrit-PatchSet: 7
Gerrit-Project: ovirt-node
Gerrit-Branch: master
Gerrit-Owner: Joey Boggs <jboggs at redhat.com>
Gerrit-Reviewer: Alon Bar-Lev <alonbl at redhat.com>
Gerrit-Reviewer: Fabian Deutsch <fabiand at fedoraproject.org>
Gerrit-Reviewer: Joey Boggs <jboggs at redhat.com>
Gerrit-Reviewer: Michael Burns <mburns at redhat.com>



More information about the node-patches mailing list