Codebase list manila-tempest-plugin / 4a80316
Move "get_access_rule_data_from_config" method under utils.py This method is based only on tempest configuration, so better to move it under utils.py method that other classes will benefit it without having to inherit from it. Change-Id: Ia0cf15210e697988cd54ae82db8bb76aa17a5996 lkuchlan 1 year, 5 months ago
8 changed file(s) with 46 addition(s) and 41 deletion(s). Raw diff Collapse all Expand all
720720 client, replica["id"], constants.REPLICATION_STATE_ACTIVE,
721721 resource_name='share_replica', status_attr="replica_state")
722722 return replica
723
724 @classmethod
725 def _get_access_rule_data_from_config(cls):
726 """Get the first available access type/to combination from config.
727
728 This method opportunistically picks the first configured protocol
729 to create the share. Do not use this method in tests where you need
730 to test depth and breadth in the access types and access recipients.
731 """
732 protocol = cls.shares_v2_client.share_protocol
733
734 if protocol in CONF.share.enable_ip_rules_for_protocols:
735 access_type = "ip"
736 access_to = utils.rand_ip()
737 elif protocol in CONF.share.enable_user_rules_for_protocols:
738 access_type = "user"
739 access_to = CONF.share.username_for_user_rules
740 elif protocol in CONF.share.enable_cert_rules_for_protocols:
741 access_type = "cert"
742 access_to = "client3.com"
743 elif protocol in CONF.share.enable_cephx_rules_for_protocols:
744 access_type = "cephx"
745 access_to = data_utils.rand_name(
746 cls.__class__.__name__ + '-cephx-id')
747 else:
748 message = "Unrecognized protocol and access rules configuration."
749 raise cls.skipException(message)
750
751 return access_type, access_to
752723
753724 @classmethod
754725 def create_share_network(cls, client=None,
10531024 raise_rule_in_error_state=True, cleanup=True):
10541025
10551026 client = client or self.shares_v2_client
1056 a_type, a_to = self._get_access_rule_data_from_config()
1027 a_type, a_to = utils.get_access_rule_data_from_config(
1028 client.share_protocol)
10571029 access_type = access_type or a_type
10581030 access_to = access_to or a_to
10591031
5454 @classmethod
5555 def resource_setup(cls):
5656 super(AccessRulesMetadataTest, cls).resource_setup()
57 cls.protocol = cls.shares_v2_client.share_protocol
58 cls.access_type, __ = cls._get_access_rule_data_from_config()
57 cls.access_type, __ = utils.get_access_rule_data_from_config(
58 cls.shares_v2_client.share_protocol)
5959 int_range = range(20, 50)
6060 cls.access_to = {
6161 # list of unique values is required for ability to create lots
5454 @classmethod
5555 def resource_setup(cls):
5656 super(AccessesMetadataNegativeTest, cls).resource_setup()
57 cls.protocol = cls.shares_v2_client.share_protocol
5857 cls.access_type, cls.access_to = (
59 cls._get_access_rule_data_from_config()
58 utils.get_access_rule_data_from_config(
59 cls.shares_v2_client.share_protocol)
6060 )
6161 # create share type
6262 cls.share_type = cls.create_share_type()
329329 @tc.attr(base.TAG_POSITIVE, base.TAG_BACKEND)
330330 def test_add_access_rule_create_replica_delete_rule(self):
331331 # Add access rule to the share
332 access_type, access_to = self._get_access_rule_data_from_config()
332 access_type, access_to = utils.get_access_rule_data_from_config(
333 self.shares_v2_client.share_protocol)
333334 self.allow_access(
334335 self.shares[0]["id"], access_type=access_type, access_to=access_to,
335336 access_level='ro')
345346 @decorators.idempotent_id('3af3f19a-1195-464e-870b-1a3918914f1b')
346347 @tc.attr(base.TAG_POSITIVE, base.TAG_BACKEND)
347348 def test_create_replica_add_access_rule_delete_replica(self):
348 access_type, access_to = self._get_access_rule_data_from_config()
349 access_type, access_to = utils.get_access_rule_data_from_config(
350 self.shares_v2_client.share_protocol)
349351 # Create the replica
350352 share_replica = self._verify_create_replica()
351353
407409
408410 share = self.create_shares([self.creation_data])[0]
409411 # Add access rule
410 access_type, access_to = self._get_access_rule_data_from_config()
412 access_type, access_to = utils.get_access_rule_data_from_config(
413 self.shares_v2_client.share_protocol)
411414 self.allow_access(
412415 share["id"], access_type=access_type, access_to=access_to,
413416 access_level='ro')
189189 @decorators.idempotent_id('600a13d2-5cf0-482e-97af-9f598b55a407')
190190 @tc.attr(base.TAG_NEGATIVE, base.TAG_API_WITH_BACKEND)
191191 def test_add_access_rule_share_replica_error_status(self):
192 access_type, access_to = self._get_access_rule_data_from_config()
192 access_type, access_to = utils.get_access_rule_data_from_config(
193 self.shares_v2_client.share_protocol)
193194 # Create the replica
194195 share_replica = self.create_share_replica(self.share1["id"],
195196 self.replica_zone,
436436 @classmethod
437437 def resource_setup(cls):
438438 super(ShareRulesTest, cls).resource_setup()
439 cls.protocol = cls.shares_v2_client.share_protocol
440439 cls.access_type, cls.access_to = (
441 cls._get_access_rule_data_from_config()
440 utils.get_access_rule_data_from_config(
441 cls.shares_v2_client.share_protocol)
442442 )
443443 cls.share_type = cls.create_share_type()
444444 cls.share_type_id = cls.share_type['id']
152152 @decorators.idempotent_id('d2856c7d-9417-416d-8d08-e68376ee5b2e')
153153 @tc.attr(base.TAG_NEGATIVE, base.TAG_API_WITH_BACKEND)
154154 def test_add_access_rule_on_share_with_no_host(self):
155 access_type, access_to = self._get_access_rule_data_from_config()
155 access_type, access_to = utils.get_access_rule_data_from_config(
156 self.protocol)
156157 extra_specs = self.add_extra_specs_to_dict(
157158 {"share_backend_name": 'invalid_backend'})
158159 share_type = self.create_share_type('invalid_backend',
1818
1919 from netaddr import ip
2020 from tempest import config
21 from tempest.lib.common.utils import data_utils
2122 import testtools
2223
2324 CONF = config.CONF
189190 return extra_specs
190191
191192
193 def get_access_rule_data_from_config(protocol):
194 """Get the first available access type/to combination from config.
195
196 This method opportunistically picks the first configured protocol
197 to create the share. Do not use this method in tests where you need
198 to test depth and breadth in the access types and access recipients.
199 """
200
201 if protocol in CONF.share.enable_ip_rules_for_protocols:
202 access_type = "ip"
203 access_to = rand_ip()
204 elif protocol in CONF.share.enable_user_rules_for_protocols:
205 access_type = "user"
206 access_to = CONF.share.username_for_user_rules
207 elif protocol in CONF.share.enable_cert_rules_for_protocols:
208 access_type = "cert"
209 access_to = "client3.com"
210 elif protocol in CONF.share.enable_cephx_rules_for_protocols:
211 access_type = "cephx"
212 access_to = data_utils.rand_name("cephx-id")
213 else:
214 message = "Unrecognized protocol and access rules configuration."
215 raise testtools.TestCase.skipException(message)
216
217 return access_type, access_to
218
219
192220 def replication_with_multitenancy_support():
193221 return (share_network_subnets_are_supported() and
194222 CONF.share.multitenancy_enabled)