Merge "Remove volume client and usage in scenario tests"
diff --git a/README.rst b/README.rst
index ca88f76..0a2d95b 100644
--- a/README.rst
+++ b/README.rst
@@ -7,7 +7,8 @@
 Tempest plugin to test Manila's features
 
 * Free software: Apache license
-* Documentation: https://docs.openstack.org/developer/openstack
+* Documentation: https://docs.openstack.org/manila/latest/
+* Release notes: https://docs.openstack.org/releasenotes/manila/
 * Source: https://git.openstack.org/cgit/openstack/manila-tempest-plugin
 * Bugs: https://bugs.launchpad.net/manila-tempest-plugin
 
diff --git a/manila_tempest_tests/tests/api/base.py b/manila_tempest_tests/tests/api/base.py
index d8bd45a..401c089 100644
--- a/manila_tempest_tests/tests/api/base.py
+++ b/manila_tempest_tests/tests/api/base.py
@@ -26,7 +26,6 @@
 from tempest import config
 from tempest.lib.common import dynamic_creds
 from tempest.lib.common.utils import data_utils
-from tempest.lib.common.utils import test_utils
 from tempest.lib import exceptions
 from tempest import test
 
@@ -127,9 +126,6 @@
     # Will be cleaned up in resource_cleanup
     class_resources = []
 
-    # Will be cleaned up in clear_net_resources
-    class_net_resources = []
-
     # Will be cleaned up in tearDown method
     method_resources = []
 
@@ -314,14 +310,12 @@
         super(BaseSharesTest, self).setUp()
         self.addCleanup(self.clear_isolated_creds)
         self.addCleanup(self.clear_resources)
-        self.addCleanup(self.clear_net_resources)
         verify_test_has_appropriate_tags(self)
 
     @classmethod
     def resource_cleanup(cls):
         cls.clear_resources(cls.class_resources)
         cls.clear_isolated_creds(cls.class_isolated_creds)
-        cls.clear_net_resources(cls.class_net_resources)
         super(BaseSharesTest, cls).resource_cleanup()
 
     @classmethod
@@ -399,24 +393,6 @@
                         network, subnet, router = net_data
                         net_id = network["id"]
                         subnet_id = subnet["id"]
-                        network_res = {
-                            "type": "network",
-                            "resource": network,
-                            "client": ic,
-                        }
-                        subnet_res = {
-                            "type": "subnet",
-                            "resource": subnet,
-                            "client": ic,
-                        }
-                        router_res = {
-                            "type": "router",
-                            "resource": router,
-                            "client": ic,
-                        }
-                        cls.class_net_resources.insert(0, network_res)
-                        cls.class_net_resources.insert(0, subnet_res)
-                        cls.class_net_resources.insert(0, router_res)
 
                     # Try get suitable share-network
                     share_networks = sc.list_share_networks_with_detail()
@@ -446,58 +422,6 @@
         return share_network_id
 
     @classmethod
-    def clear_net_resources(cls, resources=None):
-        if resources is None:
-            resources = cls.class_net_resources
-        for res in resources:
-            if "deleted" not in res.keys():
-                res["deleted"] = False
-            if not (res["deleted"]):
-                if res["type"] is "router":
-                    cls.clear_router(res['client'], res['resource'])
-                elif res["type"] is "subnet":
-                    cls.clear_subnet(res['client'], res['resource'])
-                elif res["type"] is "network":
-                    cls.clear_network(res['client'], res['resource'])
-                else:
-                    LOG.warning("Provided unsupported resource type for "
-                                "cleanup '%s'. Skipping." % res["type"])
-            res["deleted"] = True
-
-    @classmethod
-    def clear_router(cls, ic, router):
-        body = ic.ports_admin_client.list_ports(device_id=router['id'])
-        interfaces = body['ports']
-        for i in interfaces:
-            test_utils.call_and_ignore_notfound_exc(
-                ic.routers_admin_client.remove_router_interface, router['id'],
-                subnet_id=i['fixed_ips'][0]['subnet_id'])
-
-        try:
-            ic.routers_admin_client.delete_router(router['id'])
-        except exceptions.NotFound:
-            LOG.warning('router with name: %s not found for delete' %
-                        router['name'])
-
-    @classmethod
-    def clear_subnet(cls, ic, subnet):
-        client = ic.subnets_admin_client
-        try:
-            client.delete_subnet(subnet['id'])
-        except exceptions.NotFound:
-            LOG.warning('subnet with name: %s not found for delete' %
-                        subnet['name'])
-
-    @classmethod
-    def clear_network(cls, ic, network):
-        net_client = ic.networks_admin_client
-        try:
-            net_client.delete_network(network['id'])
-        except exceptions.NotFound:
-            LOG.warning('network with name: %s not found for delete' %
-                        network['name'])
-
-    @classmethod
     def _create_share(cls, share_protocol=None, size=None, name=None,
                       snapshot_id=None, description=None, metadata=None,
                       share_network_id=None, share_type_id=None,
@@ -991,8 +915,8 @@
                         client.wait_for_resource_deletion(snapshot_id=res_id)
                     elif (res["type"] is "share_network" and
                             res_id != CONF.share.share_network_id):
-                            client.delete_share_network(res_id)
-                            client.wait_for_resource_deletion(sn_id=res_id)
+                        client.delete_share_network(res_id)
+                        client.wait_for_resource_deletion(sn_id=res_id)
                     elif res["type"] is "security_service":
                         client.delete_security_service(res_id)
                         client.wait_for_resource_deletion(ss_id=res_id)
diff --git a/manila_tempest_tests/tests/api/test_rules_negative.py b/manila_tempest_tests/tests/api/test_rules_negative.py
index 22f232f..19db6bb 100644
--- a/manila_tempest_tests/tests/api/test_rules_negative.py
+++ b/manila_tempest_tests/tests/api/test_rules_negative.py
@@ -124,6 +124,39 @@
                 rule_id=rule["id"], share_id=self.share["id"], version=version)
 
     @tc.attr(base.TAG_NEGATIVE, base.TAG_API_WITH_BACKEND)
+    @ddt.data("10.20.30.40", "fd8c:b029:bba6:ac54::1",
+              "fd2c:b029:bba6:df54::1/128", "10.10.30.40/32")
+    def test_create_duplicate_single_host_rules(self, access_to):
+        """Test rules for individual clients with and without max-prefix."""
+        if ':' in access_to and utils.is_microversion_lt(
+                '2.38', CONF.share.max_api_microversion):
+            reason = ("Skipped. IPv6 rules are accepted from and beyond "
+                      "API version 2.38, the configured maximum API version "
+                      "is %s" % CONF.share.max_api_microversion)
+            raise self.skipException(reason)
+
+        rule = self.shares_v2_client.create_access_rule(
+            self.share["id"], "ip", access_to)
+        self.addCleanup(self.shares_v2_client.delete_access_rule,
+                        self.share["id"], rule['id'])
+        self.shares_v2_client.wait_for_share_status(
+            self.share["id"], "active", status_attr='access_rules_status')
+
+        self.assertRaises(lib_exc.BadRequest,
+                          self.shares_v2_client.create_access_rule,
+                          self.share["id"], "ip", access_to)
+
+        if '/' in access_to:
+            access_to = access_to.split("/")[0]
+        else:
+            access_to = ('%s/32' % access_to if '.' in access_to else
+                         '%s/128' % access_to)
+
+        self.assertRaises(lib_exc.BadRequest,
+                          self.shares_v2_client.create_access_rule,
+                          self.share["id"], "ip", access_to)
+
+    @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()
         extra_specs = self.add_extra_specs_to_dict(
diff --git a/manila_tempest_tests/tests/api/test_snapshot_rules_negative.py b/manila_tempest_tests/tests/api/test_snapshot_rules_negative.py
index 2991acd..2f3f193 100644
--- a/manila_tempest_tests/tests/api/test_snapshot_rules_negative.py
+++ b/manila_tempest_tests/tests/api/test_snapshot_rules_negative.py
@@ -21,6 +21,7 @@
 
 from manila_tempest_tests.tests.api import base
 from manila_tempest_tests.tests.api import test_snapshot_rules
+from manila_tempest_tests import utils
 
 CONF = config.CONF
 
@@ -58,14 +59,22 @@
                           self.snap["id"], "ip", target)
 
     @tc.attr(base.TAG_NEGATIVE, base.TAG_API_WITH_BACKEND)
-    def test_create_duplicate_of_ip_rule(self):
-        self._test_duplicate_rules()
-        self._test_duplicate_rules()
+    @ddt.data("1.2.3.4", "fd8c:b029:bba6:ac54::1",
+              "fd8c:b029:bba6:ac54::1/128", "1.2.3.4/32")
+    def test_create_duplicate_of_ip_rule(self, access_to):
+        self._test_duplicate_rules(access_to)
+        self._test_duplicate_rules(access_to)
 
-    def _test_duplicate_rules(self):
+    def _test_duplicate_rules(self, access_to):
+        if ':' in access_to and utils.is_microversion_lt(
+                '2.38', CONF.share.max_api_microversion):
+            reason = ("Skipped. IPv6 rules are accepted from and beyond "
+                      "API version 2.38, the configured maximum API version "
+                      "is %s" % CONF.share.max_api_microversion)
+            raise self.skipException(reason)
+
         # test data
         access_type = "ip"
-        access_to = "1.2.3.4"
 
         # create rule
         rule = self.shares_v2_client.create_snapshot_access_rule(
@@ -79,6 +88,16 @@
                           self.shares_v2_client.create_snapshot_access_rule,
                           self.snap["id"], access_type, access_to)
 
+        # try alternate notation
+        if '/' in access_to:
+            access_to = access_to.split("/")[0]
+        else:
+            access_to = ('%s/32' % access_to if '.' in access_to else
+                         '%s/128' % access_to)
+        self.assertRaises(lib_exc.BadRequest,
+                          self.shares_v2_client.create_snapshot_access_rule,
+                          self.snap["id"], access_type, access_to)
+
         # delete rule and wait for deletion
         self.shares_v2_client.delete_snapshot_access_rule(self.snap['id'],
                                                           rule['id'])