From ff20190d1f950cd66e2187a5b3bea41d7bf7c679 Mon Sep 17 00:00:00 2001
From: Guido Trotter <ultrotter@google.com>
Date: Mon, 19 Apr 2010 16:27:44 +0100
Subject: [PATCH] ReleaseUid: accept an integer as uid

We can't guarantee to keep the LockedObject around, when ReleaseUid is
called (because that might happen, for example, after a ganeti
shutdown/restart). So we'll support releasing on just an integer uid.

Signed-off-by: Guido Trotter <ultrotter@google.com>
Reviewed-by: Iustin Pop <iustin@google.com>
---
 lib/uidpool.py | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/lib/uidpool.py b/lib/uidpool.py
index a74cbd0d6..80e7807c5 100644
--- a/lib/uidpool.py
+++ b/lib/uidpool.py
@@ -323,9 +323,13 @@ def RequestUnusedUid(all_uids):
 def ReleaseUid(uid):
   """This should be called when the given user-id is no longer in use.
 
+  @type uid: LockedUid or integer
+  @param uid: the uid to release back to the pool
+
   """
-  # Make sure we release the exclusive lock, if there is any
-  uid.Unlock()
+  if isinstance(uid, LockedUid):
+    # Make sure we release the exclusive lock, if there is any
+    uid.Unlock()
   try:
     uid_path = utils.PathJoin(constants.UIDPOOL_LOCKDIR, str(uid))
     os.remove(uid_path)
-- 
GitLab