Merge "Move "get_access_rule_data_from_config" method under utils.py"

This commit is contained in:
Zuul 2023-01-04 21:29:10 +00:00 committed by Gerrit Code Review
commit c142317fa2
8 changed files with 46 additions and 41 deletions

View File

@ -722,35 +722,6 @@ class BaseSharesTest(test.BaseTestCase):
resource_name='share_replica', status_attr="replica_state")
return replica
@classmethod
def _get_access_rule_data_from_config(cls):
"""Get the first available access type/to combination from config.
This method opportunistically picks the first configured protocol
to create the share. Do not use this method in tests where you need
to test depth and breadth in the access types and access recipients.
"""
protocol = cls.shares_v2_client.share_protocol
if protocol in CONF.share.enable_ip_rules_for_protocols:
access_type = "ip"
access_to = utils.rand_ip()
elif protocol in CONF.share.enable_user_rules_for_protocols:
access_type = "user"
access_to = CONF.share.username_for_user_rules
elif protocol in CONF.share.enable_cert_rules_for_protocols:
access_type = "cert"
access_to = "client3.com"
elif protocol in CONF.share.enable_cephx_rules_for_protocols:
access_type = "cephx"
access_to = data_utils.rand_name(
cls.__class__.__name__ + '-cephx-id')
else:
message = "Unrecognized protocol and access rules configuration."
raise cls.skipException(message)
return access_type, access_to
@classmethod
def create_share_network(cls, client=None,
cleanup_in_class=False,
@ -1054,7 +1025,8 @@ class BaseSharesTest(test.BaseTestCase):
raise_rule_in_error_state=True, cleanup=True):
client = client or self.shares_v2_client
a_type, a_to = self._get_access_rule_data_from_config()
a_type, a_to = utils.get_access_rule_data_from_config(
client.share_protocol)
access_type = access_type or a_type
access_to = access_to or a_to

View File

@ -55,8 +55,8 @@ class AccessRulesMetadataTest(base.BaseSharesMixedTest):
@classmethod
def resource_setup(cls):
super(AccessRulesMetadataTest, cls).resource_setup()
cls.protocol = cls.shares_v2_client.share_protocol
cls.access_type, __ = cls._get_access_rule_data_from_config()
cls.access_type, __ = utils.get_access_rule_data_from_config(
cls.shares_v2_client.share_protocol)
int_range = range(20, 50)
cls.access_to = {
# list of unique values is required for ability to create lots

View File

@ -55,9 +55,9 @@ class AccessesMetadataNegativeTest(base.BaseSharesMixedTest):
@classmethod
def resource_setup(cls):
super(AccessesMetadataNegativeTest, cls).resource_setup()
cls.protocol = cls.shares_v2_client.share_protocol
cls.access_type, cls.access_to = (
cls._get_access_rule_data_from_config()
utils.get_access_rule_data_from_config(
cls.shares_v2_client.share_protocol)
)
# create share type
cls.share_type = cls.create_share_type()

View File

@ -330,7 +330,8 @@ class ReplicationTest(base.BaseSharesMixedTest):
@tc.attr(base.TAG_POSITIVE, base.TAG_BACKEND)
def test_add_access_rule_create_replica_delete_rule(self):
# Add access rule to the share
access_type, access_to = self._get_access_rule_data_from_config()
access_type, access_to = utils.get_access_rule_data_from_config(
self.shares_v2_client.share_protocol)
self.allow_access(
self.shares[0]["id"], access_type=access_type, access_to=access_to,
access_level='ro')
@ -346,7 +347,8 @@ class ReplicationTest(base.BaseSharesMixedTest):
@decorators.idempotent_id('3af3f19a-1195-464e-870b-1a3918914f1b')
@tc.attr(base.TAG_POSITIVE, base.TAG_BACKEND)
def test_create_replica_add_access_rule_delete_replica(self):
access_type, access_to = self._get_access_rule_data_from_config()
access_type, access_to = utils.get_access_rule_data_from_config(
self.shares_v2_client.share_protocol)
# Create the replica
share_replica = self._verify_create_replica()
@ -408,7 +410,8 @@ class ReplicationTest(base.BaseSharesMixedTest):
share = self.create_shares([self.creation_data])[0]
# Add access rule
access_type, access_to = self._get_access_rule_data_from_config()
access_type, access_to = utils.get_access_rule_data_from_config(
self.shares_v2_client.share_protocol)
self.allow_access(
share["id"], access_type=access_type, access_to=access_to,
access_level='ro')

View File

@ -190,7 +190,8 @@ class ReplicationNegativeTest(ReplicationNegativeBase):
@decorators.idempotent_id('600a13d2-5cf0-482e-97af-9f598b55a407')
@tc.attr(base.TAG_NEGATIVE, base.TAG_API_WITH_BACKEND)
def test_add_access_rule_share_replica_error_status(self):
access_type, access_to = self._get_access_rule_data_from_config()
access_type, access_to = utils.get_access_rule_data_from_config(
self.shares_v2_client.share_protocol)
# Create the replica
share_replica = self.create_share_replica(self.share1["id"],
self.replica_zone,

View File

@ -437,9 +437,9 @@ class ShareRulesTest(base.BaseSharesMixedTest):
@classmethod
def resource_setup(cls):
super(ShareRulesTest, cls).resource_setup()
cls.protocol = cls.shares_v2_client.share_protocol
cls.access_type, cls.access_to = (
cls._get_access_rule_data_from_config()
utils.get_access_rule_data_from_config(
cls.shares_v2_client.share_protocol)
)
cls.share_type = cls.create_share_type()
cls.share_type_id = cls.share_type['id']

View File

@ -153,7 +153,8 @@ class ShareIpRulesForNFSNegativeTest(base.BaseSharesMixedTest):
@decorators.idempotent_id('d2856c7d-9417-416d-8d08-e68376ee5b2e')
@tc.attr(base.TAG_NEGATIVE, base.TAG_API_WITH_BACKEND)
def test_add_access_rule_on_share_with_no_host(self):
access_type, access_to = self._get_access_rule_data_from_config()
access_type, access_to = utils.get_access_rule_data_from_config(
self.protocol)
extra_specs = self.add_extra_specs_to_dict(
{"share_backend_name": 'invalid_backend'})
share_type = self.create_share_type('invalid_backend',

View File

@ -19,6 +19,7 @@ import re
from netaddr import ip
from tempest import config
from tempest.lib.common.utils import data_utils
import testtools
CONF = config.CONF
@ -190,6 +191,33 @@ def get_configured_extra_specs(variation=None):
return extra_specs
def get_access_rule_data_from_config(protocol):
"""Get the first available access type/to combination from config.
This method opportunistically picks the first configured protocol
to create the share. Do not use this method in tests where you need
to test depth and breadth in the access types and access recipients.
"""
if protocol in CONF.share.enable_ip_rules_for_protocols:
access_type = "ip"
access_to = rand_ip()
elif protocol in CONF.share.enable_user_rules_for_protocols:
access_type = "user"
access_to = CONF.share.username_for_user_rules
elif protocol in CONF.share.enable_cert_rules_for_protocols:
access_type = "cert"
access_to = "client3.com"
elif protocol in CONF.share.enable_cephx_rules_for_protocols:
access_type = "cephx"
access_to = data_utils.rand_name("cephx-id")
else:
message = "Unrecognized protocol and access rules configuration."
raise testtools.TestCase.skipException(message)
return access_type, access_to
def replication_with_multitenancy_support():
return (share_network_subnets_are_supported() and
CONF.share.multitenancy_enabled)