Change in vdsm[ovirt-3.3]: tests: prevent hook validation decorator from leaving script...

danken at redhat.com danken at redhat.com
Fri Jan 24 16:08:22 UTC 2014


Hello Miguel Angel Ajo Pelayo,

I'd like you to do a code review.  Please visit

    http://gerrit.ovirt.org/23672

to review the following change.

Change subject: tests: prevent hook validation decorator from leaving scripts installed
......................................................................

tests: prevent hook validation decorator from leaving scripts installed

It fixes a bug in the hook validation decorator, that left tests
scripts installed into the system. Now they're properly removed
right after the tests.

Adds rmTree function to vdsm.utils.

Change-Id: I138c3eab77ea6d35d6a997049940923026e06d96
Signed-off-by: Miguel Angel Ajo <miguelangel at ajo.es>
Reviewed-on: http://gerrit.ovirt.org/20310
Reviewed-by: Dan Kenigsberg <danken at redhat.com>
Tested-by: Dan Kenigsberg <danken at redhat.com>
---
M lib/vdsm/utils.py
M tests/hookValidation.py
2 files changed, 27 insertions(+), 5 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/72/23672/1

diff --git a/lib/vdsm/utils.py b/lib/vdsm/utils.py
index ef0f512..97a5442 100644
--- a/lib/vdsm/utils.py
+++ b/lib/vdsm/utils.py
@@ -42,6 +42,7 @@
 import os
 import pwd
 import select
+import shutil
 import signal
 import socket
 import stat
@@ -116,6 +117,21 @@
                           exc_info=True)
             raise
 
+
+def rmTree(directoryToRemove):
+    """
+    Try to remove a directory and all it's contents.
+
+    If the directory doesn't exist is assumed that it was already removed.
+    """
+    try:
+        shutil.rmtree(directoryToRemove)
+    except OSError as e:
+        if e.errno == errno.ENOENT:
+            logging.warning("Directory: %s already removed", directoryToRemove)
+        else:
+            raise
+
 IPXMLRPCRequestHandler = SimpleXMLRPCRequestHandler
 
 
diff --git a/tests/hookValidation.py b/tests/hookValidation.py
index 80e7239..d91f930 100644
--- a/tests/hookValidation.py
+++ b/tests/hookValidation.py
@@ -18,12 +18,13 @@
 # Refer to the README and COPYING files for full details of the license
 #
 
+import errno
 import os
-import shutil
 import tempfile
 
 from functools import wraps
 from vdsm import constants
+from vdsm import utils
 
 
 def _createHookScript(hook_path, hook_filename, script=None):
@@ -62,8 +63,11 @@
 
             try:
                 os.mkdir(hook_path)
-            except OSError:
-                directory_existed = True
+            except OSError as mkdir_error:
+                if mkdir_error.errno == errno.EEXIST:
+                    directory_existed = True
+                else:
+                    raise
 
             cookie_file = _createHookScript(hook_path, hook_name, hook_script)
 
@@ -74,9 +78,11 @@
                 output = test_function(*args, **kwargs)
             finally:
                 if directory_existed:
-                    os.unlink(cookie_file)
+                    utils.rmFile(hook_path + '/' + hook_name)
                 else:
-                    shutil.rmtree(hook_path)
+                    utils.rmTree(hook_path)
+
+                utils.rmFile(cookie_file)
 
                 if not functional:
                     constants.P_VDSM_HOOKS = old_vdsm_hooks


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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I138c3eab77ea6d35d6a997049940923026e06d96
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: ovirt-3.3
Gerrit-Owner: Dan Kenigsberg <danken at redhat.com>
Gerrit-Reviewer: Miguel Angel Ajo Pelayo <majopela at redhat.com>


More information about the vdsm-patches mailing list