Merge "Add tests for scheduler hints of share create."

This commit is contained in:
Zuul 2021-09-17 18:26:18 +00:00 committed by Gerrit Code Review
commit f293988bbf
4 changed files with 182 additions and 2 deletions

View File

@ -31,7 +31,7 @@ ShareGroup = [
"This value is only used to validate the versions "
"response from Manila."),
cfg.StrOpt("max_api_microversion",
default="2.61",
default="2.65",
help="The maximum api microversion is configured to be the "
"value of the latest microversion supported by Manila."),
cfg.StrOpt("region",

View File

@ -243,9 +243,11 @@ class SharesV2Client(shares_client.SharesClient):
metadata=None, share_network_id=None,
share_type_id=None, is_public=False,
share_group_id=None, availability_zone=None,
version=LATEST_MICROVERSION, experimental=False):
version=LATEST_MICROVERSION, experimental=False,
scheduler_hints=None):
headers = EXPERIMENTAL if experimental else None
metadata = metadata or {}
scheduler_hints = scheduler_hints or {}
if name is None:
name = data_utils.rand_name("tempest-created-share")
if description is None:
@ -275,6 +277,9 @@ class SharesV2Client(shares_client.SharesClient):
post_body["share"]["share_type"] = share_type_id
if share_group_id:
post_body["share"]["share_group_id"] = share_group_id
if scheduler_hints:
post_body["share"]["scheduler_hints"] = scheduler_hints
body = json.dumps(post_body)
resp, body = self.post("shares", body, headers=headers,
extra_headers=experimental, version=version)

View File

@ -0,0 +1,102 @@
# Copyright 2021 Cloudification GmbH
# 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 tempest import config
from tempest.lib import decorators
from testtools import testcase as tc
from manila_tempest_tests.tests.api import base
from manila_tempest_tests import utils
CONF = config.CONF
class SharesSchedulerHintsTest(base.BaseSharesMixedTest):
@classmethod
def skip_checks(cls):
super(SharesSchedulerHintsTest, cls).skip_checks()
if not CONF.share.multi_backend:
raise cls.skipException("Manila multi-backend is disabled.")
elif len(CONF.share.backend_names) < 2:
raise cls.skipException("For running multi-backend tests required"
" two names in config. Skipping.")
elif any(not name for name in CONF.share.backend_names):
raise cls.skipException("Share backend names can not be empty. "
"Skipping.")
utils.check_skip_if_microversion_not_supported('2.65')
@classmethod
def resource_setup(cls):
super(SharesSchedulerHintsTest, cls).resource_setup()
# create share type
cls.share_type = cls.create_share_type()
cls.share_type_id = cls.share_type['id']
# create share
cls.share_a = cls.create_share(share_type_id=cls.share_type_id)
@decorators.idempotent_id('f96d5836-bfc9-4c22-888e-3f62d731573c')
@tc.attr(base.TAG_POSITIVE, base.TAG_API_WITH_BACKEND)
def test_same_host_scheduler_hint_in_share_creation(self):
scheduler_hint = {"same_host": "%s" % self.share_a["id"]}
# create share with metadata
share_b = self.create_share(share_type_id=self.share_type_id,
scheduler_hints=scheduler_hint,
cleanup_in_class=False)
# get backend of shares
share_a = self.admin_shares_v2_client.get_share(
self.share_a['id'])['share']
backend_a = share_a['host']
share_b = self.admin_shares_v2_client.get_share(
share_b['id'])['share']
backend_b = share_b['host']
# verify same backends
self.assertEqual(backend_a, backend_b)
# get metadata of share
metadata_a = self.shares_client.get_metadata(
self.share_a["id"])['metadata']
md_a = {"__affinity_same_host": "%s" % share_b["id"]}
metadata_b = self.shares_client.get_metadata(
share_b["id"])['metadata']
md_b = {"__affinity_same_host": "%s" % self.share_a["id"]}
# verify metadata
self.assertEqual(md_a, metadata_a)
self.assertEqual(md_b, metadata_b)
@decorators.idempotent_id('6569e0c3-43c9-4ee2-84ff-ea7fa8da8110')
@tc.attr(base.TAG_POSITIVE, base.TAG_API_WITH_BACKEND)
def test_different_host_scheduler_hint_in_share_creation(self):
scheduler_hint = {"different_host": "%s" % self.share_a["id"]}
# create share with metadata
share_c = self.create_share(share_type_id=self.share_type_id,
scheduler_hints=scheduler_hint,
cleanup_in_class=False)
# get backend of shares
share_a = self.admin_shares_v2_client.get_share(
self.share_a['id'])['share']
backend_a = share_a['host']
share_c = self.admin_shares_v2_client.get_share(share_c['id'])['share']
backend_c = share_c['host']
# verify different backends
self.assertNotEqual(backend_a, backend_c)

View File

@ -0,0 +1,73 @@
# Copyright 2021 Cloudification GmbH
# 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 tempest import config
from tempest.lib import decorators
from tempest.lib import exceptions as lib_exc
from testtools import testcase as tc
from manila_tempest_tests import share_exceptions
from manila_tempest_tests.tests.api import base
from manila_tempest_tests import utils
FAKE_SHARE_ID = "2d316e9f-39fc-468e-b2d9-634b25ae85f6"
CONF = config.CONF
class SharesSchedulerHintsNegativeTest(base.BaseSharesMixedTest):
@classmethod
def skip_checks(cls):
super(SharesSchedulerHintsNegativeTest, cls).skip_checks()
if not CONF.share.multi_backend:
raise cls.skipException("Manila multi-backend is disabled.")
elif len(CONF.share.backend_names) < 2:
raise cls.skipException("For running multi-backend tests required"
" two names in config. Skipping.")
elif any(not name for name in CONF.share.backend_names):
raise cls.skipException("Share backend names can not be empty. "
"Skipping.")
utils.check_skip_if_microversion_not_supported('2.65')
@classmethod
def resource_setup(cls):
super(SharesSchedulerHintsNegativeTest, cls).resource_setup()
# create share type
cls.share_type = cls.create_share_type()
cls.share_type_id = cls.share_type['id']
# create share
cls.share_a = cls.create_share(share_type_id=cls.share_type_id)
@decorators.idempotent_id('2228a187-4f03-4195-9e23-fa1a42110fdc')
@tc.attr(base.TAG_NEGATIVE, base.TAG_API_WITH_BACKEND)
def test_scheduler_hint_with_invalid_share_id(self):
scheduler_hint = {"same_host": FAKE_SHARE_ID}
self.assertRaises(lib_exc.NotFound,
self.create_share,
share_type_id=self.share_type_id,
scheduler_hints=scheduler_hint,
cleanup_in_class=False)
@decorators.idempotent_id('6f0c5561-8a6a-4cfb-bbe7-84ffc39bf78d')
@tc.attr(base.TAG_NEGATIVE, base.TAG_API_WITH_BACKEND)
def test_scheduler_hint_with_invalid_hint(self):
scheduler_hint = {"same_host": "%s" % self.share_a["id"],
"different_host": "%s" % self.share_a["id"]}
self.assertRaises(share_exceptions.ShareBuildErrorException,
self.create_share,
share_type_id=self.share_type_id,
scheduler_hints=scheduler_hint,
cleanup_in_class=False)