Add possibility to prevent Tobiko from creating test image

It can be done with env variable TOBIKO_PREVENT_CREATE.

Change-Id: I46b3fb4e34c482b99b53461cb404012f02d2c890
This commit is contained in:
Slawek Kaplonski 2019-08-05 12:31:57 +00:00
parent 9b9dec3bdb
commit b66d690c93
2 changed files with 28 additions and 22 deletions

View File

@ -250,7 +250,7 @@ can be used::
export TOBIKO_PREVENT_CREATE=True export TOBIKO_PREVENT_CREATE=True
If this is set to ``True`` or ``1`` then Tobiko will not try to create resources like VMs, 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 What's Next
----------- -----------

View File

@ -23,6 +23,7 @@ from oslo_log import log
import requests import requests
import tobiko import tobiko
from tobiko.config import get_bool_env
from tobiko.openstack.glance import _client from tobiko.openstack.glance import _client
from tobiko.openstack.glance import _io from tobiko.openstack.glance import _io
@ -185,6 +186,8 @@ class UploadGranceImageFixture(GlanceImageFixture):
self.disk_format = disk_format self.disk_format = disk_format
tobiko.check_valid_type(self.disk_format, str) tobiko.check_valid_type(self.disk_format, str)
self.prevent_image_create = get_bool_env('TOBIKO_PREVENT_CREATE')
def setup_image(self): def setup_image(self):
self.create_image() self.create_image()
@ -198,29 +201,32 @@ class UploadGranceImageFixture(GlanceImageFixture):
break break
retries -= 1 retries -= 1
if image: if not self.prevent_image_create:
LOG.debug('Delete existing image: %r (id=%r)', if image:
self.image_name, image.id) LOG.debug('Delete existing image: %r (id=%r)',
self.delete_image(image.id) self.image_name, image.id)
self.wait_for_image_deleted() self.delete_image(image.id)
self.wait_for_image_deleted()
# Cleanup cached objects # Cleanup cached objects
self.image = image = None self.image = image = None
try: try:
LOG.debug('Creating Glance image %r (re-tries left %d)...', LOG.debug('Creating Glance image %r '
self.image_name, retries) '(re-tries left %d)...',
image_id = _client.create_image( self.image_name, retries)
client=self.client, image_id = _client.create_image(
name=self.image_name, client=self.client,
disk_format=self.disk_format, name=self.image_name,
container_format=self.container_format)['id'] disk_format=self.disk_format,
except Exception: container_format=self.container_format)['id']
LOG.exception('Image creation failed %r.', self.image_name) except Exception:
else: LOG.exception('Image creation failed %r.',
cleanup_image_ids.add(image_id) self.image_name)
LOG.debug('Created image %r (id=%r)...', self.image_name, else:
image_id) cleanup_image_ids.add(image_id)
LOG.debug('Created image %r (id=%r)...',
self.image_name, image_id)
if image: if image:
if image.id in cleanup_image_ids: if image.id in cleanup_image_ids: