Sandro Bonazzola has uploaded a new change for review.

Change subject: Added logging of insufficient local space
......................................................................

Added logging of insufficient local space

When checking for space availability for decompressing the ovf
file in a temporary directory, notify the user and log an error
if there isn't enough space.

Also fixed the return value of space_test_ovf when tarfile raises an
exception and made space_test_ovf a static method.

Change-Id: Id9742144ed5f28399908d2dde116d34d86b3f119
Signed-off-by: Sandro Bonazzola <[email protected]>
---
M src/__main__.py
1 file changed, 16 insertions(+), 2 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-image-uploader 
refs/changes/88/12688/1

diff --git a/src/__main__.py b/src/__main__.py
index cecf296..1f3c833 100644
--- a/src/__main__.py
+++ b/src/__main__.py
@@ -483,7 +483,8 @@
             os.seteuid(0)
             os.setegid(0)
 
-    def space_test_ovf(self, ovf_file, dest_dir):
+    @staticmethod
+    def space_test_ovf(ovf_file, dest_dir):
         '''Checks to see if there is enough room to decompress the tgz into 
dest_dir'''
         tar = tarfile.open(ovf_file, "r:gz")
         size_in_bytes = 0
@@ -493,7 +494,7 @@
                     size_in_bytes += tarinfo.size
         except:
             logging.error(_("Unable to calculate the decompressed size of 
%s.") % ovf_file)
-            return False
+            return (False,-1)
         finally:
             tar.close()
 
@@ -1208,6 +1209,19 @@
                         if self.unpack_ovf(ovf_file, ovf_extract_dir):
                             if (self.update_ovf_xml(ovf_extract_dir)):
                                 self.copy_files_nfs(ovf_extract_dir, dest_dir, 
address, ovf_file_size, ovf_file)
+                    else:
+                        if ovf_file_size > 0:
+                            ExitCodes.exit_code = ExitCodes.CRITICAL
+                            size_needed_mb = "%1.f" % \
+                                (float(ovf_file_size) / float(pow(2, 20)))
+                            logging.error(_(
+                                "Not enough space in {tempdir}:"
+                                " {size_needed} Mb are needed.").format(
+                                    tempdir=tempfile.gettempdir(),
+                                    size_needed=size_needed_mb
+                                )
+                            )
+
                 finally:
                     try:
                         logging.debug("Cleaning up OVF extract directory %s" % 
ovf_extract_dir)


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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Id9742144ed5f28399908d2dde116d34d86b3f119
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-image-uploader
Gerrit-Branch: master
Gerrit-Owner: Sandro Bonazzola <[email protected]>
_______________________________________________
Engine-patches mailing list
[email protected]
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to