Merge "Add share resize scenario tests for CephFS Native"
diff --git a/manila_tempest_tests/config.py b/manila_tempest_tests/config.py
index de5cf58..7993693 100644
--- a/manila_tempest_tests/config.py
+++ b/manila_tempest_tests/config.py
@@ -290,5 +290,11 @@
                help="Default size in GB for shares created by share tests."),
     cfg.BoolOpt("run_ipv6_tests",
                 default=False,
-                help="Enable or disable running IPv6 tests."),
+                help="Enable or disable running IPv6 NFS scenario tests. "
+                     "These tests validate that IPv6 export locations work, "
+                     "and that access can be provided to IPv6 clients. When "
+                     "you do not specify a storage_network, the tests will "
+                     "attempt to create an IPv6 subnet on the project network "
+                     "they create for ping and SSH to the client test VM "
+                     "where data path testing is performed."),
 ]
diff --git a/manila_tempest_tests/tests/scenario/manager_share.py b/manila_tempest_tests/tests/scenario/manager_share.py
index aed0edd..7067e6b 100644
--- a/manila_tempest_tests/tests/scenario/manager_share.py
+++ b/manila_tempest_tests/tests/scenario/manager_share.py
@@ -21,6 +21,7 @@
 from tempest.common import waiters
 from tempest import config
 from tempest.lib.common.utils import data_utils
+from tempest.lib.common.utils import test_utils
 from tempest.lib import exceptions
 
 from manila_tempest_tests.common import constants
@@ -29,7 +30,6 @@
 from manila_tempest_tests.tests.scenario import manager
 from manila_tempest_tests import utils
 
-
 CONF = config.CONF
 LOG = log.getLogger(__name__)
 
@@ -98,17 +98,6 @@
                                             flavor=self.flavor_ref,
                                             ssh_user=self.ssh_user))
 
-        self.security_group = self._create_security_group()
-        self.network = self._create_network(namestart="manila-share")
-        self.subnet = self._create_subnet(
-            network=self.network,
-            namestart="manila-share-sub",
-            ip_version=self.ip_version,
-            use_default_subnetpool=self.ipv6_enabled)
-        router = self._get_router()
-        self._create_router_interface(subnet_id=self.subnet['id'],
-                                      router_id=router['id'])
-
         self.storage_network = (
             self._get_network_by_name_or_id(CONF.share.storage_network)
             if CONF.share.storage_network else None
@@ -117,6 +106,24 @@
             self.storage_network['name'] if self.storage_network else None
         )
 
+        # Tests need to be able to ssh into the VM - so we need
+        # a security group, and a tenant private network
+        self.security_group = self._create_security_group()
+        self.network = self._create_network(namestart="manila-share")
+        # When not using a "storage network" to connect shares to VMs,
+        # we need the subnet to match the IP version we're testing
+        subnet_ip_params = {} if self.storage_network else {
+            'ip_version': self.ip_version,
+            'use_default_subnetpool': self.ipv6_enabled
+        }
+        self.subnet = self._create_subnet(
+            network=self.network,
+            namestart="manila-share-sub",
+            **subnet_ip_params)
+        router = self._get_router()
+        self._create_router_interface(subnet_id=self.subnet['id'],
+                                      router_id=router['id'])
+
         if CONF.share.multitenancy_enabled:
             # Skip if DHSS=False
             self.share_network = self.create_share_network()
@@ -193,6 +200,24 @@
         self.share = self.shares_client.get_share(self.share['id'])
         return remote_client
 
+    def validate_ping_to_export_location(self, export, remote_client,
+                                         ping_timeout=None):
+        timeout = ping_timeout or CONF.validation.ping_timeout
+
+        def ping_to_export_location(export, remote_client):
+            ip, version = self.get_ip_and_version_from_export_location(export)
+            try:
+                remote_client.exec_command(
+                    "ping{} -c5 -w1 {}".format(
+                        '6' if version == 6 else '', ip))
+                return True
+            except exceptions.SSHExecCommandFailed:
+                return False
+
+        test_utils.call_until_true(ping_to_export_location,
+                                   timeout, 1, export=export,
+                                   remote_client=remote_client)
+
     def write_data_to_mounted_share(self, escaped_string, remote_client,
                                     mount_point='/mnt/t1'):
         remote_client.exec_command("echo \"{escaped_string}\" "
diff --git a/manila_tempest_tests/tests/scenario/test_share_basic_ops.py b/manila_tempest_tests/tests/scenario/test_share_basic_ops.py
index 3cdc3ae..5ed3633 100644
--- a/manila_tempest_tests/tests/scenario/test_share_basic_ops.py
+++ b/manila_tempest_tests/tests/scenario/test_share_basic_ops.py
@@ -44,13 +44,6 @@
      * Terminate the instance
     """
 
-    def _ping_host_from_export_location(self, export, remote_client):
-        ip, version = self.get_ip_and_version_from_export_location(export)
-        if version == 6:
-            remote_client.exec_command("ping6 -c 5 %s" % ip)
-        else:
-            remote_client.exec_command("ping -c 5 %s" % ip)
-
     @tc.attr(base.TAG_POSITIVE, base.TAG_BACKEND)
     def test_mount_share_one_vm(self):
         instance = self.boot_instance(wait_until="BUILD")
@@ -404,7 +397,7 @@
 
     def mount_share(self, location, remote_client, target_dir=None):
 
-        self._ping_host_from_export_location(location, remote_client)
+        self.validate_ping_to_export_location(location, remote_client)
 
         target_dir = target_dir or "/mnt"
         remote_client.exec_command(
@@ -428,7 +421,7 @@
 
     def mount_share(self, location, remote_client, target_dir=None):
 
-        self._ping_host_from_export_location(location, remote_client)
+        self.validate_ping_to_export_location(location, remote_client)
 
         location = location.replace("\\", "/")
         target_dir = target_dir or "/mnt"
diff --git a/manila_tempest_tests/tests/scenario/test_share_extend.py b/manila_tempest_tests/tests/scenario/test_share_extend.py
index 823e3c9..3bc4dd4 100644
--- a/manila_tempest_tests/tests/scenario/test_share_extend.py
+++ b/manila_tempest_tests/tests/scenario/test_share_extend.py
@@ -159,6 +159,9 @@
             instance=kwargs['instance'], access_level=access_level)
 
     def mount_share(self, location, remote_client, target_dir=None):
+
+        self.validate_ping_to_export_location(location, remote_client)
+
         target_dir = target_dir or "/mnt"
         remote_client.exec_command(
             "sudo mount -vt nfs \"%s\" %s" % (location, target_dir)
@@ -181,6 +184,9 @@
             instance=kwargs['instance'], access_level=access_level)
 
     def mount_share(self, location, remote_client, target_dir=None):
+
+        self.validate_ping_to_export_location(location, remote_client)
+
         location = location.replace("\\", "/")
         target_dir = target_dir or "/mnt"
         remote_client.exec_command(
@@ -197,6 +203,10 @@
         super(TestShareExtendCEPHFS, self).test_create_extend_and_write()
 
 
+class TestShareExtendNFSIPv6(TestShareExtendNFS):
+    ip_version = 6
+
+
 # NOTE(u_glide): this function is required to exclude ShareExtendBase
 # from executed test cases.
 # See: https://docs.python.org/3/library/unittest.html#load-tests-protocol
diff --git a/manila_tempest_tests/tests/scenario/test_share_manage_unmanage.py b/manila_tempest_tests/tests/scenario/test_share_manage_unmanage.py
index 1005740..c707874 100644
--- a/manila_tempest_tests/tests/scenario/test_share_manage_unmanage.py
+++ b/manila_tempest_tests/tests/scenario/test_share_manage_unmanage.py
@@ -178,6 +178,9 @@
     protocol = "nfs"
 
     def mount_share(self, location, remote_client, target_dir=None):
+
+        self.validate_ping_to_export_location(location, remote_client)
+
         target_dir = target_dir or "/mnt"
         remote_client.exec_command(
             "sudo mount -vt nfs \"%s\" %s" % (location, target_dir)
@@ -188,6 +191,9 @@
     protocol = "cifs"
 
     def mount_share(self, location, remote_client, target_dir=None):
+
+        self.validate_ping_to_export_location(location, remote_client)
+
         location = location.replace("\\", "/")
         target_dir = target_dir or "/mnt"
         remote_client.exec_command(
@@ -195,6 +201,10 @@
         )
 
 
+class ShareManageUnmanageNFSIPv6(ShareManageUnmanageNFS):
+    ip_version = 6
+
+
 # NOTE(u_glide): this function is required to exclude ShareManageUnmanageBase
 # from executed test cases.
 # See: https://docs.python.org/3/library/unittest.html#load-tests-protocol
diff --git a/manila_tempest_tests/tests/scenario/test_share_shrink.py b/manila_tempest_tests/tests/scenario/test_share_shrink.py
index 1d0e028..5a6ab71 100644
--- a/manila_tempest_tests/tests/scenario/test_share_shrink.py
+++ b/manila_tempest_tests/tests/scenario/test_share_shrink.py
@@ -174,6 +174,9 @@
             instance=kwargs['instance'], access_level=access_level)
 
     def mount_share(self, location, ssh_client, target_dir=None):
+
+        self.validate_ping_to_export_location(location, ssh_client)
+
         target_dir = target_dir or "/mnt"
         ssh_client.exec_command(
             "sudo mount -vt nfs \"%s\" %s" % (location, target_dir)
@@ -196,6 +199,9 @@
             instance=kwargs['instance'], access_level=access_level)
 
     def mount_share(self, location, ssh_client, target_dir=None):
+
+        self.validate_ping_to_export_location(location, ssh_client)
+
         location = location.replace("\\", "/")
         target_dir = target_dir or "/mnt"
         ssh_client.exec_command(
@@ -212,6 +218,10 @@
         super(TestShareShrinkCEPHFS, self).test_create_shrink_and_write()
 
 
+class TestShareShrinkNFSIPv6(TestShareShrinkNFS):
+    ip_version = 6
+
+
 # NOTE(u_glide): this function is required to exclude ShareShrinkBase from
 # executed test cases.
 # See: https://docs.python.org/3/library/unittest.html#load-tests-protocol