Use fixture to create Manila resources

With this patch, tobiko handles manila resources using Fixtures.

Depends-On: https://review.opendev.org/c/x/devstack-plugin-tobiko/+/954052

Change-Id: Ibec4cf4d9cf9b7c77e0f2cc74fb3439b92813967
This commit is contained in:
Eduardo Olivares
2023-09-15 10:45:23 +02:00
parent 92863bc24a
commit 176845a862
6 changed files with 95 additions and 15 deletions

View File

@@ -42,4 +42,3 @@ RESOURCE_STATUS = _constants.RESOURCE_STATUS
STATUS_AVAILABLE = _constants.STATUS_AVAILABLE
STATUS_ERROR = _constants.STATUS_ERROR
STATUS_ERROR_DELETING = _constants.STATUS_ERROR_DELETING
SHARE_NAME = _constants.SHARE_NAME

View File

@@ -14,6 +14,7 @@
from __future__ import absolute_import
from manilaclient.v2 import client as manilaclient
from manilaclient.v2 import shares as manilashares
from manilaclient import exceptions
from oslo_log import log
@@ -65,7 +66,8 @@ def get_manila_client(session=None, shared=True, init_client=None,
return manila_client(fixture)
def create_share(share_protocol=None, size=None, client=None, **kwargs):
def create_share(share_protocol=None, size=None, client=None, **kwargs) \
-> manilashares.Share:
share_protocol = share_protocol or CONF.tobiko.manila.share_protocol
share_size = size or CONF.tobiko.manila.size
return manila_client(client).shares.create(

View File

@@ -19,6 +19,3 @@ RESOURCE_STATUS = 'status'
STATUS_AVAILABLE = 'available'
STATUS_ERROR = 'error'
STATUS_ERROR_DELETING = 'error_deleting'
# Manila resource names
SHARE_NAME = "tobiko-manila-share"

View File

@@ -18,6 +18,7 @@ from __future__ import absolute_import
from tobiko.openstack.stacks import _cirros
from tobiko.openstack.stacks import _designate
from tobiko.openstack.stacks import _l3ha
from tobiko.openstack.stacks import _manila
from tobiko.openstack.stacks import _neutron
from tobiko.openstack.stacks import _nova
from tobiko.openstack.stacks import _octavia
@@ -101,3 +102,6 @@ AdvancedPeerServerStackFixture = _advanced_vm.AdvancedPeerServerStackFixture
VlanNetworkStackFixture = _vlan.VlanNetworkStackFixture
VlanProxyServerStackFixture = _vlan.VlanProxyServerStackFixture
# Manila resources
ManilaShareFixture = _manila.ManilaShareFixture

View File

@@ -0,0 +1,78 @@
# Copyright (c) 2025 Red Hat, Inc.
#
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from __future__ import absolute_import
import typing
from manilaclient.v2.shares import Share
from oslo_log import log
import tobiko
from tobiko.openstack import manila
from tobiko.openstack.base import _fixture as base_fixture
LOG = log.getLogger(__name__)
class ManilaShareFixture(base_fixture.ResourceFixture):
_resource: typing.Optional[Share] = None
share_protocol: typing.Optional[str] = None
size: typing.Optional[int] = None
def __init__(self, share_protocol=None, size=None):
super().__init__()
self.share_protocol = share_protocol or self.share_protocol
self.size = size or self.size
@property
def share_id(self):
return self.resource_id
@property
def share(self):
return self.resource
@tobiko.interworker_synched('manila_setup_fixture')
def try_create_resource(self):
super().try_create_resource()
def resource_create(self):
share = manila.create_share(share_protocol=self.share_protocol,
size=self.size,
name=self.name)
manila.wait_for_share_status(share['id'])
LOG.debug(f'Share {share["name"]} was deployed successfully '
f'with id {share["id"]}')
return share
def resource_delete(self):
LOG.debug('Deleting Share %r ...', self.name)
manila.delete_share(self.share_id)
manila.wait_for_resource_deletion(self.share_id)
LOG.debug('Share %r deleted.', self.name)
def resource_find(self):
found_shares = manila.get_shares_by_name(self.name)
if len(found_shares) > 1:
tobiko.fail(f'Unexpected number of shares found: {found_shares}')
if found_shares:
LOG.debug("Share %r found.", self.name)
return found_shares[0]
# no shares found
LOG.debug("Share %r not found.", self.name)

View File

@@ -18,9 +18,11 @@ from __future__ import absolute_import
import testtools
from oslo_log import log
import tobiko
from tobiko import config
from tobiko.openstack import keystone
from tobiko.openstack import manila
from tobiko.openstack import stacks
LOG = log.getLogger(__name__)
CONF = config.CONF
@@ -35,20 +37,18 @@ class ManilaApiTestCase(testtools.TestCase):
After upgrade/disruptions/etc, check the share is still valid and it can be
extended.
"""
@classmethod
def setUpClass(cls):
if config.get_bool_env('TOBIKO_PREVENT_CREATE'):
LOG.debug('skipping creation of manila resources')
cls.share = manila.get_shares_by_name(manila.SHARE_NAME)[0]
else:
manila.ensure_default_share_type_exists()
cls.share = manila.create_share(name=manila.SHARE_NAME)
share_fixture = tobiko.required_fixture(stacks.ManilaShareFixture)
share = None
manila.wait_for_share_status(cls.share['id'])
def setUp(self):
super(ManilaApiTestCase, self).setUp()
self.share = self.share_fixture.share
@config.skip_if_prevent_create()
def test_1_create_share(self):
self.assertEqual(manila.SHARE_NAME, self.share['name'])
manila.wait_for_share_status(self.share['id'])
found_shares = manila.get_shares_by_name(self.share['name'])
self.assertEqual(len(found_shares), 1)
@config.skip_unless_prevent_create()
def test_2_extend_share(self):