From 6bb29fdd274f70eb4a9bf32fc8813368eedb8af4 Mon Sep 17 00:00:00 2001 From: Martin Kopec Date: Mon, 28 Mar 2022 15:58:46 +0200 Subject: [PATCH] Fix TestImageService's unit tests The test class had hardcoded DEFAULT_IMAGE_DIR value to /img/ which resulted in unit tests failures when this path existed because the tests expect a call to makedirs which didn't happen as the DEFAULT_IMAGE_DIR already existed. The patch fixes that by passing exist_ok=True to makedirs call which will result in always calling makedirs, whether img_dir exists or not. Change-Id: I47d15747536394006f6b502b3025220a5077e547 --- config_tempest/services/image.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/config_tempest/services/image.py b/config_tempest/services/image.py index b77e4fe8..1bc67884 100644 --- a/config_tempest/services/image.py +++ b/config_tempest/services/image.py @@ -128,11 +128,8 @@ class ImageService(VersionedService): name = image_path[image_path.rfind('/') + 1:] if self.convert and name[-4:] == ".img": name = name[:-4] + ".raw" - if not os.path.exists(img_dir): - try: - os.makedirs(img_dir) - except OSError: - raise + # create img_dir if it doesn't exist already + os.makedirs(img_dir, exist_ok=True) alt_name = name + "_alt" image_id = None if conf.has_option('compute', 'image_ref'):