Browse Source

Add support for tags at image creation

Add new image and server stack for testing tagged
image creation.

Change-Id: I27c6458ab76f31492b17a8c095b11ff1e6872886
changes/40/734440/5
Federico Ressi 1 year ago
parent
commit
6b0b746fcb
  1. 2
      linters-requirements.txt
  2. 21
      tobiko/openstack/glance/_image.py
  3. 2
      tobiko/openstack/stacks/__init__.py
  4. 11
      tobiko/openstack/stacks/_cirros.py
  5. 14
      tobiko/tests/functional/openstack/stacks/test_cirros.py

2
linters-requirements.txt

@ -4,4 +4,4 @@ ansible-lint==4.2.0 # MIT
flake8>=3.8.1 # MIT
flake8-import-order==0.12 # LGPLv3
mypy>=0.740 # MIT
pylint>=2.5.2 # GPLv2
pylint>=2.5.2 # GPLv2

21
tobiko/openstack/glance/_image.py

@ -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()

2
tobiko/openstack/stacks/__init__.py

@ -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

11
tobiko/openstack/stacks/_cirros.py

@ -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)

14
tobiko/tests/functional/openstack/stacks/test_cirros.py

@ -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…
Cancel
Save