bug 13777: propagate snapshot packaging failures up. Reviewed-By: Anthony

tar command random failure may occur due to linux kernal bug (or feature) that tar can't handle well. The failuar happens when tar wants to package a newly created file before file system has fully synced
diff --git a/vmware-base/src/com/cloud/hypervisor/vmware/mo/VirtualMachineMO.java b/vmware-base/src/com/cloud/hypervisor/vmware/mo/VirtualMachineMO.java
index 382d1eb..2270541 100755
--- a/vmware-base/src/com/cloud/hypervisor/vmware/mo/VirtualMachineMO.java
+++ b/vmware-base/src/com/cloud/hypervisor/vmware/mo/VirtualMachineMO.java
@@ -1242,7 +1242,13 @@
 						out.close();

 						

 						// tar files into OVA

-						if(packToOva) {

+						if(packToOva) {
+						    // Important! we need to sync file system before we can safely use tar to work around a linux kernal bug(or feature)
+                            s_logger.info("Sync file system before we package OVA...");
+                            
+						    Script commandSync = new Script(true, "sync", 0, s_logger);
+                            commandSync.execute();
+						    

 					        Script command = new Script(false, "tar", 0, s_logger);

 					        command.setWorkDir(exportDir);

 					        command.add("-cf", exportName + ".ova");

@@ -1250,13 +1256,16 @@
 					        for(String name: fileNames) {

                                 command.add((new File(name).getName()));

                             }

-					        

-					        String result = command.execute();

-					        if(result == null) {
-					            success = true;

+					        
+                            s_logger.info("Package OVA with commmand: " + command.toString());
+					        command.execute();
+					        
+					        // to be safe, physically test existence of the target OVA file
+					        if((new File(exportDir + File.separator + exportName + ".ova")).exists()) {
+					            success = true;
 					        } else {
-					            s_logger.error("failed to execute command: " + command.toString());
-					        }

+					            s_logger.error(exportDir + File.separator + exportName + ".ova is not created as expected");
+					        }
 						}
 					}

 				} catch(Throwable e) {

@@ -1270,10 +1279,8 @@
                         }
 					}
 					
-					if(!success) {
-					    new File(exportDir + File.separator + exportName + ".ova").delete();
+					if(!success)
 					    throw new Exception("Unable to finish the whole process to package as a OVA file");
-					} 

 				}

 			}

 		} finally {