Merge "Move "get_access_rule_data_from_config" method under utils.py"
diff --git a/manila_tempest_tests/tests/api/base.py b/manila_tempest_tests/tests/api/base.py
index 42c2fab..e7fe125 100755
--- a/manila_tempest_tests/tests/api/base.py
+++ b/manila_tempest_tests/tests/api/base.py
@@ -723,35 +723,6 @@
         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,
                              add_security_services=True, **kwargs):
@@ -1054,7 +1025,8 @@
                      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
 
diff --git a/manila_tempest_tests/tests/api/test_access_rules_metadata.py b/manila_tempest_tests/tests/api/test_access_rules_metadata.py
index ee541ac..6b0aa2d 100644
--- a/manila_tempest_tests/tests/api/test_access_rules_metadata.py
+++ b/manila_tempest_tests/tests/api/test_access_rules_metadata.py
@@ -55,8 +55,8 @@
     @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
diff --git a/manila_tempest_tests/tests/api/test_access_rules_metadata_negative.py b/manila_tempest_tests/tests/api/test_access_rules_metadata_negative.py
index c848ed3..98a1361 100644
--- a/manila_tempest_tests/tests/api/test_access_rules_metadata_negative.py
+++ b/manila_tempest_tests/tests/api/test_access_rules_metadata_negative.py
@@ -55,9 +55,9 @@
     @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()
diff --git a/manila_tempest_tests/tests/api/test_replication.py b/manila_tempest_tests/tests/api/test_replication.py
index 7873926..9a9a478 100644
--- a/manila_tempest_tests/tests/api/test_replication.py
+++ b/manila_tempest_tests/tests/api/test_replication.py
@@ -330,7 +330,8 @@
     @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 @@
     @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 @@
 
         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')
diff --git a/manila_tempest_tests/tests/api/test_replication_negative.py b/manila_tempest_tests/tests/api/test_replication_negative.py
index e7d0e7d..0262142 100644
--- a/manila_tempest_tests/tests/api/test_replication_negative.py
+++ b/manila_tempest_tests/tests/api/test_replication_negative.py
@@ -190,7 +190,8 @@
     @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,
diff --git a/manila_tempest_tests/tests/api/test_rules.py b/manila_tempest_tests/tests/api/test_rules.py
index 979bf06..925b725 100644
--- a/manila_tempest_tests/tests/api/test_rules.py
+++ b/manila_tempest_tests/tests/api/test_rules.py
@@ -437,9 +437,9 @@
     @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']
diff --git a/manila_tempest_tests/tests/api/test_rules_negative.py b/manila_tempest_tests/tests/api/test_rules_negative.py
index 1eb858d..a4b53f5 100644
--- a/manila_tempest_tests/tests/api/test_rules_negative.py
+++ b/manila_tempest_tests/tests/api/test_rules_negative.py
@@ -153,7 +153,8 @@
     @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',
diff --git a/manila_tempest_tests/utils.py b/manila_tempest_tests/utils.py
index 5ecfb36..057558b 100644
--- a/manila_tempest_tests/utils.py
+++ b/manila_tempest_tests/utils.py
@@ -19,6 +19,7 @@
 
 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 @@
     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)