diff --git a/doc/source/user/config.rst b/doc/source/user/config.rst index 8d8116a68..55eca452d 100644 --- a/doc/source/user/config.rst +++ b/doc/source/user/config.rst @@ -250,7 +250,7 @@ can be used:: export TOBIKO_PREVENT_CREATE=True If this is set to ``True`` or ``1`` then Tobiko will not try to create resources like VMs, -networks or routers and just run validation of what is exists in the cloud already. +networks, routers or images and just run validation of what is exists in the cloud already. What's Next ----------- diff --git a/tobiko/openstack/glance/_image.py b/tobiko/openstack/glance/_image.py index 6e2210462..173b70655 100644 --- a/tobiko/openstack/glance/_image.py +++ b/tobiko/openstack/glance/_image.py @@ -23,6 +23,7 @@ from oslo_log import log import requests import tobiko +from tobiko.config import get_bool_env from tobiko.openstack.glance import _client from tobiko.openstack.glance import _io @@ -185,6 +186,8 @@ class UploadGranceImageFixture(GlanceImageFixture): self.disk_format = disk_format tobiko.check_valid_type(self.disk_format, str) + self.prevent_image_create = get_bool_env('TOBIKO_PREVENT_CREATE') + def setup_image(self): self.create_image() @@ -198,29 +201,32 @@ class UploadGranceImageFixture(GlanceImageFixture): break retries -= 1 - if image: - LOG.debug('Delete existing image: %r (id=%r)', - self.image_name, image.id) - self.delete_image(image.id) - self.wait_for_image_deleted() + if not self.prevent_image_create: + if image: + LOG.debug('Delete existing image: %r (id=%r)', + self.image_name, image.id) + self.delete_image(image.id) + self.wait_for_image_deleted() - # Cleanup cached objects - self.image = image = None + # Cleanup cached objects + self.image = image = None - try: - LOG.debug('Creating Glance image %r (re-tries left %d)...', - self.image_name, retries) - image_id = _client.create_image( - client=self.client, - name=self.image_name, - disk_format=self.disk_format, - container_format=self.container_format)['id'] - except Exception: - LOG.exception('Image creation failed %r.', self.image_name) - else: - cleanup_image_ids.add(image_id) - LOG.debug('Created image %r (id=%r)...', self.image_name, - image_id) + try: + LOG.debug('Creating Glance image %r ' + '(re-tries left %d)...', + self.image_name, retries) + image_id = _client.create_image( + client=self.client, + name=self.image_name, + disk_format=self.disk_format, + container_format=self.container_format)['id'] + except Exception: + LOG.exception('Image creation failed %r.', + self.image_name) + else: + cleanup_image_ids.add(image_id) + LOG.debug('Created image %r (id=%r)...', + self.image_name, image_id) if image: if image.id in cleanup_image_ids: