Add support for tags at image creation
Add new image and server stack for testing tagged image creation. Change-Id: I27c6458ab76f31492b17a8c095b11ff1e6872886
This commit is contained in:
parent
711cfcb6ad
commit
6b0b746fcb
@ -18,6 +18,7 @@ import io
|
||||
import os
|
||||
import tempfile
|
||||
import time
|
||||
import typing
|
||||
|
||||
from oslo_log import log
|
||||
import requests
|
||||
@ -182,8 +183,10 @@ class UploadGranceImageFixture(GlanceImageFixture):
|
||||
disk_format = "raw"
|
||||
container_format = "bare"
|
||||
create_image_retries = None
|
||||
tags: typing.List[str] = []
|
||||
|
||||
def __init__(self, disk_format=None, container_format=None, **kwargs):
|
||||
def __init__(self, disk_format=None, container_format=None, tags=None,
|
||||
**kwargs):
|
||||
super(UploadGranceImageFixture, self).__init__(**kwargs)
|
||||
|
||||
if container_format:
|
||||
@ -194,6 +197,9 @@ class UploadGranceImageFixture(GlanceImageFixture):
|
||||
self.disk_format = disk_format
|
||||
tobiko.check_valid_type(self.disk_format, str)
|
||||
|
||||
self.tags = list(tags or self.tags)
|
||||
tobiko.check_valid_type(self.tags, list)
|
||||
|
||||
self.prevent_image_create = get_bool_env('TOBIKO_PREVENT_CREATE')
|
||||
|
||||
def setup_image(self):
|
||||
@ -223,10 +229,7 @@ class UploadGranceImageFixture(GlanceImageFixture):
|
||||
'(re-tries left %d)...',
|
||||
self.image_name, retries)
|
||||
image_id = _client.create_image(
|
||||
client=self.glance_client,
|
||||
name=self.image_name,
|
||||
disk_format=self.disk_format,
|
||||
container_format=self.container_format)['id']
|
||||
**self.create_image_parameters)['id']
|
||||
|
||||
cleanup_image_ids.add(image_id)
|
||||
LOG.debug('Created image %r (id=%r)...',
|
||||
@ -250,6 +253,14 @@ class UploadGranceImageFixture(GlanceImageFixture):
|
||||
|
||||
return image
|
||||
|
||||
@property
|
||||
def create_image_parameters(self):
|
||||
return dict(client=self.glance_client,
|
||||
name=self.image_name,
|
||||
disk_format=self.disk_format,
|
||||
container_format=self.container_format,
|
||||
tags=self.tags)
|
||||
|
||||
@contextlib.contextmanager
|
||||
def _cleanup_image_ids(self):
|
||||
created_image_ids = set()
|
||||
|
@ -35,6 +35,8 @@ CirrosDifferentHostServerStackFixture = (
|
||||
_cirros.CirrosDifferentHostServerStackFixture)
|
||||
CirrosSameHostServerStackFixture = _cirros.CirrosSameHostServerStackFixture
|
||||
RebootCirrosServerOperation = _cirros.RebootCirrosServerOperation
|
||||
EvacuableCirrosImageFixture = _cirros.EvacuableCirrosImageFixture
|
||||
EvacuableServerStackFixture = _cirros.EvacuableServerStackFixture
|
||||
|
||||
L3haNetworkStackFixture = _l3ha.L3haNetworkStackFixture
|
||||
L3haServerStackFixture = _l3ha.L3haServerStackFixture
|
||||
|
@ -76,3 +76,14 @@ class RebootCirrosServerOperation(sh.RebootHostOperation):
|
||||
@property
|
||||
def ssh_client(self):
|
||||
return self.stack.ssh_client
|
||||
|
||||
|
||||
class EvacuableCirrosImageFixture(CirrosImageFixture):
|
||||
|
||||
tags = ['evacuable']
|
||||
|
||||
|
||||
class EvacuableServerStackFixture(CirrosServerStackFixture):
|
||||
|
||||
#: Glance image used to create a Nova server instance
|
||||
image_fixture = tobiko.required_setup_fixture(EvacuableCirrosImageFixture)
|
||||
|
@ -52,3 +52,17 @@ class CirrosServerStackTest(testtools.TestCase):
|
||||
self.stack.ssh_client.connect()
|
||||
output = self.stack.console_output
|
||||
self.assertTrue(output)
|
||||
|
||||
|
||||
class EvacuablesServerStackTest(CirrosServerStackTest):
|
||||
|
||||
#: Stack of resources with a server attached to a floating IP
|
||||
stack = tobiko.required_setup_fixture(stacks.EvacuableServerStackFixture)
|
||||
|
||||
def test_image_fixture_tags(self):
|
||||
image_fixture = self.stack.image_fixture
|
||||
self.assertEqual(['evacuable'], image_fixture.tags)
|
||||
|
||||
def test_image_tags(self):
|
||||
image = self.stack.image_fixture.get_image()
|
||||
self.assertEqual(['evacuable'], image.tags)
|
||||
|
Loading…
Reference in New Issue
Block a user