Vinzenz Feenstra has uploaded a new change for review.

Change subject: Refactor VM._guestSockCleanup into utils.rmFileAndLink
......................................................................

Refactor VM._guestSockCleanup into utils.rmFileAndLink

Change-Id: I749d5e15c91e0046ac700d2eec7220aa7cbd8ac2
Signed-off-by: Vinzenz Feenstra <[email protected]>
---
M lib/vdsm/utils.py
M vdsm/virt/vm.py
2 files changed, 14 insertions(+), 8 deletions(-)


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

diff --git a/lib/vdsm/utils.py b/lib/vdsm/utils.py
index cd178da..7a5792e 100644
--- a/lib/vdsm/utils.py
+++ b/lib/vdsm/utils.py
@@ -116,6 +116,18 @@
         os.utime(filePath, None)
 
 
+def rmFileAndLink(fileToRemove):
+    """
+    Try to remove a file and if it is a link remove the linked file as well.
+    If the file or link does not exists it is assumed that it was already
+    removed.
+    """
+    if os.path.islink(fileToRemove):
+        realPath = os.path.realpath(fileToRemove)
+        rmFile(realPath)
+    rmFile(fileToRemove)
+
+
 def rmFile(fileToRemove):
     """
     Try to remove a file.
diff --git a/vdsm/virt/vm.py b/vdsm/virt/vm.py
index 0e19235..bcca057 100644
--- a/vdsm/virt/vm.py
+++ b/vdsm/virt/vm.py
@@ -2361,7 +2361,7 @@
         except Exception:
             pass
 
-        self._guestSockCleanup(self._guestSocketFile)
+        utils.rmFileAndLink(self._guestSocketFile)
 
     def setDownStatus(self, code, exitReasonCode, exitMessage=''):
         if not exitMessage:
@@ -2637,12 +2637,6 @@
         self._vmStats.start()
         self._guestEventTime = self._startTime
 
-    @staticmethod
-    def _guestSockCleanup(sock):
-        if os.path.islink(sock):
-            utils.rmFile(os.path.realpath(sock))
-        utils.rmFile(sock)
-
     def _cleanup(self):
         """
         General clean up routine
@@ -2651,7 +2645,7 @@
         self._cleanupFloppy()
         self._cleanupGuestAgent()
         utils.rmFile(self._recoveryFile)
-        self._guestSockCleanup(self._qemuguestSocketFile)
+        utils.rmFileAndLink(self._qemuguestSocketFile)
 
     def updateGuestCpuRunning(self):
         self._guestCpuRunning = (self._dom.info()[0] ==


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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I749d5e15c91e0046ac700d2eec7220aa7cbd8ac2
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Vinzenz Feenstra <[email protected]>
_______________________________________________
vdsm-patches mailing list
[email protected]
https://lists.fedorahosted.org/mailman/listinfo/vdsm-patches

Reply via email to