From 12aad60a79ddb075c53311d77ce9ecd8b8728e0a Mon Sep 17 00:00:00 2001 From: Srikanth Aithal Date: Tue, 6 Aug 2019 10:40:08 +0530 Subject: [PATCH] Introduce option to remove backup file Currently after backup/restore of any image would leave .backup file behind. This would have been done to reuse backup when next time there is a call for backup function, but there can be scenarios where user would like to remove backup once original image is restored. This commit introduces an option to allow users to remove backup images by providing a flag. Signed-off-by: Srikanth Aithal --- virttest/storage.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/virttest/storage.py b/virttest/storage.py index 5d5c2d65e4..9aaa6981b1 100644 --- a/virttest/storage.py +++ b/virttest/storage.py @@ -441,6 +441,20 @@ def get_backup_set(filename, backup_dir, action, good): continue backup_func(src, dst) + def rm_backup_image(self): + """ + Remove backup image + """ + backup_dir = utils_misc.get_path(self.root_dir, + self.params.get("backup_dir", "")) + image_name = os.path.join(backup_dir, "%s.backup" % + os.path.basename(self.image_filename)) + logging.debug("Removing image file %s as requested", image_name) + if os.path.exists(image_name): + os.unlink(image_name) + else: + logging.warning("Image file %s not found", image_name) + def save_image(self, params, filename, root_dir=None): """ Save images to a path for later debugging.