Fixing download of the cirros image

Download the image fails if the path doesn't exist.
img-dir in tempest.conf points to etc, so if you're running
python-tempestconf outside tempest dir, without tempest
overrides, it will point to default_dir/etc/cirros.
If etc doesn't exist, it will fail to download the image,
this patch fix it.

Change-Id: Ib44e57442da2aa656916327d70f8dccdc0c6d1be
This commit is contained in:
Arx Cruz 2018-05-11 12:14:23 +02:00
parent ff5fbcbdb3
commit 2bb8bfd385
2 changed files with 10 additions and 2 deletions

View File

@ -55,9 +55,15 @@ class ImageService(VersionedService):
:type conf: TempestConf object
"""
img_path = os.path.join(conf.get("scenario", "img_dir"),
img_dir = os.path.join(conf.get("scenario", "img_dir"))
img_path = os.path.join(img_dir,
os.path.basename(self.image_path))
name = self.image_path[self.image_path.rfind('/') + 1:]
if not os.path.exists(img_dir):
try:
os.makedirs(img_dir)
except OSError:
raise
conf.set('scenario', 'img_file', name)
alt_name = name + "_alt"
image_id = None

View File

@ -47,9 +47,11 @@ class TestImageService(BaseServiceTest):
@mock.patch('config_tempest.services.image.ImageService'
'.find_or_upload_image')
def _test_create_tempest_images(self, mock_find_upload):
@mock.patch('os.makedirs')
def _test_create_tempest_images(self, mock_makedirs, mock_find_upload):
mock_find_upload.side_effect = ["id_c", "id_d"]
self.Service.create_tempest_images(conf=self.conf)
mock_makedirs.assert_called()
self.assertEqual(self.conf.get('compute', 'image_ref'), 'id_c')
self.assertEqual(self.conf.get('compute', 'image_ref_alt'), 'id_d')
self.assertEqual(self.conf.get('scenario', 'img_file'),