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
720 | 720 | client, replica["id"], constants.REPLICATION_STATE_ACTIVE, |
721 | 721 | resource_name='share_replica', status_attr="replica_state") |
722 | 722 | 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 | |
752 | 723 | |
753 | 724 | @classmethod |
754 | 725 | def create_share_network(cls, client=None, |
1053 | 1024 | raise_rule_in_error_state=True, cleanup=True): |
1054 | 1025 | |
1055 | 1026 | 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) | |
1057 | 1029 | access_type = access_type or a_type |
1058 | 1030 | access_to = access_to or a_to |
1059 | 1031 |
54 | 54 | @classmethod |
55 | 55 | def resource_setup(cls): |
56 | 56 | 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) | |
59 | 59 | int_range = range(20, 50) |
60 | 60 | cls.access_to = { |
61 | 61 | # list of unique values is required for ability to create lots |
54 | 54 | @classmethod |
55 | 55 | def resource_setup(cls): |
56 | 56 | super(AccessesMetadataNegativeTest, cls).resource_setup() |
57 | cls.protocol = cls.shares_v2_client.share_protocol | |
58 | 57 | 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) | |
60 | 60 | ) |
61 | 61 | # create share type |
62 | 62 | cls.share_type = cls.create_share_type() |
329 | 329 | @tc.attr(base.TAG_POSITIVE, base.TAG_BACKEND) |
330 | 330 | def test_add_access_rule_create_replica_delete_rule(self): |
331 | 331 | # 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) | |
333 | 334 | self.allow_access( |
334 | 335 | self.shares[0]["id"], access_type=access_type, access_to=access_to, |
335 | 336 | access_level='ro') |
345 | 346 | @decorators.idempotent_id('3af3f19a-1195-464e-870b-1a3918914f1b') |
346 | 347 | @tc.attr(base.TAG_POSITIVE, base.TAG_BACKEND) |
347 | 348 | 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) | |
349 | 351 | # Create the replica |
350 | 352 | share_replica = self._verify_create_replica() |
351 | 353 | |
407 | 409 | |
408 | 410 | share = self.create_shares([self.creation_data])[0] |
409 | 411 | # 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) | |
411 | 414 | self.allow_access( |
412 | 415 | share["id"], access_type=access_type, access_to=access_to, |
413 | 416 | access_level='ro') |
189 | 189 | @decorators.idempotent_id('600a13d2-5cf0-482e-97af-9f598b55a407') |
190 | 190 | @tc.attr(base.TAG_NEGATIVE, base.TAG_API_WITH_BACKEND) |
191 | 191 | 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) | |
193 | 194 | # Create the replica |
194 | 195 | share_replica = self.create_share_replica(self.share1["id"], |
195 | 196 | self.replica_zone, |
436 | 436 | @classmethod |
437 | 437 | def resource_setup(cls): |
438 | 438 | super(ShareRulesTest, cls).resource_setup() |
439 | cls.protocol = cls.shares_v2_client.share_protocol | |
440 | 439 | 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) | |
442 | 442 | ) |
443 | 443 | cls.share_type = cls.create_share_type() |
444 | 444 | cls.share_type_id = cls.share_type['id'] |
152 | 152 | @decorators.idempotent_id('d2856c7d-9417-416d-8d08-e68376ee5b2e') |
153 | 153 | @tc.attr(base.TAG_NEGATIVE, base.TAG_API_WITH_BACKEND) |
154 | 154 | 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) | |
156 | 157 | extra_specs = self.add_extra_specs_to_dict( |
157 | 158 | {"share_backend_name": 'invalid_backend'}) |
158 | 159 | share_type = self.create_share_type('invalid_backend', |
18 | 18 | |
19 | 19 | from netaddr import ip |
20 | 20 | from tempest import config |
21 | from tempest.lib.common.utils import data_utils | |
21 | 22 | import testtools |
22 | 23 | |
23 | 24 | CONF = config.CONF |
189 | 190 | return extra_specs |
190 | 191 | |
191 | 192 | |
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 | ||
192 | 220 | def replication_with_multitenancy_support(): |
193 | 221 | return (share_network_subnets_are_supported() and |
194 | 222 | CONF.share.multitenancy_enabled) |