Merge "Use local variable instead of instance variable"
diff --git a/manila_tempest_tests/config.py b/manila_tempest_tests/config.py
index 5a9087c..6f9813c 100644
--- a/manila_tempest_tests/config.py
+++ b/manila_tempest_tests/config.py
@@ -31,7 +31,7 @@
                     "This value is only used to validate the versions "
                     "response from Manila."),
     cfg.StrOpt("max_api_microversion",
-               default="2.61",
+               default="2.65",
                help="The maximum api microversion is configured to be the "
                     "value of the latest microversion supported by Manila."),
     cfg.StrOpt("region",
@@ -131,6 +131,16 @@
                help="Backend capability to create consistent snapshots of "
                     "share group members. Will be used with creation "
                     "of new share group types as group spec."),
+    cfg.BoolOpt("capability_thin_provisioned",
+                default=False,
+                help="Defines whether to create shares as thin provisioned, "
+                     "adding the extra spec 'thin_provisioning' as 'True' for "
+                     "setting up the custom share types. It may be useful to "
+                     "run tempest with  back end storage systems without much "
+                     "space. Take care enabling it, the manila scheduler "
+                     "capability filter will request this capability in all "
+                     "share types and the the capacity filter will allow "
+                     "oversubscription."),
     cfg.StrOpt("share_network_id",
                default="",
                help="Some backend drivers requires share network "
diff --git a/manila_tempest_tests/services/share/v2/json/shares_client.py b/manila_tempest_tests/services/share/v2/json/shares_client.py
index 194f1da..01028cd 100644
--- a/manila_tempest_tests/services/share/v2/json/shares_client.py
+++ b/manila_tempest_tests/services/share/v2/json/shares_client.py
@@ -243,9 +243,11 @@
                      metadata=None, share_network_id=None,
                      share_type_id=None, is_public=False,
                      share_group_id=None, availability_zone=None,
-                     version=LATEST_MICROVERSION, experimental=False):
+                     version=LATEST_MICROVERSION, experimental=False,
+                     scheduler_hints=None):
         headers = EXPERIMENTAL if experimental else None
         metadata = metadata or {}
+        scheduler_hints = scheduler_hints or {}
         if name is None:
             name = data_utils.rand_name("tempest-created-share")
         if description is None:
@@ -275,6 +277,9 @@
             post_body["share"]["share_type"] = share_type_id
         if share_group_id:
             post_body["share"]["share_group_id"] = share_group_id
+        if scheduler_hints:
+            post_body["share"]["scheduler_hints"] = scheduler_hints
+
         body = json.dumps(post_body)
         resp, body = self.post("shares", body, headers=headers,
                                extra_headers=experimental, version=version)
diff --git a/manila_tempest_tests/tests/api/admin/test_replication_actions.py b/manila_tempest_tests/tests/api/admin/test_replication_actions.py
index ba8d63b..6d71476 100644
--- a/manila_tempest_tests/tests/api/admin/test_replication_actions.py
+++ b/manila_tempest_tests/tests/api/admin/test_replication_actions.py
@@ -114,7 +114,7 @@
     def test_manage_share_for_replication_type(self):
         """Manage a share with replication share type."""
         # Create a share and unmanage it
-        share = self.create_share(size=2,
+        share = self.create_share(size=CONF.share.share_size,
                                   share_type_id=self.share_type_id,
                                   availability_zone=self.share_zone,
                                   share_network_id=self.sn_id,
@@ -164,7 +164,7 @@
                           'Manage/Unmanage Tests are disabled.')
     def test_unmanage_replicated_share_with_no_replica(self):
         """Unmanage a replication type share that does not have replica."""
-        share = self.create_share(size=2,
+        share = self.create_share(size=CONF.share.share_size,
                                   share_type_id=self.share_type_id,
                                   share_network_id=self.sn_id,
                                   availability_zone=self.share_zone,
diff --git a/manila_tempest_tests/tests/api/admin/test_share_servers_migration.py b/manila_tempest_tests/tests/api/admin/test_share_servers_migration.py
index 81b447f..f74e043 100644
--- a/manila_tempest_tests/tests/api/admin/test_share_servers_migration.py
+++ b/manila_tempest_tests/tests/api/admin/test_share_servers_migration.py
@@ -383,22 +383,13 @@
             resource_name='share_server'
         )
 
-        # Check if the source server went to inactive status if it exists.
-        try:
-            src_server = self.shares_v2_client.show_share_server(
-                src_server_id)['share_server']
-        except exceptions.NotFound:
-            src_server = None
-
-        if src_server:
-            self.assertEqual(
-                src_server['status'], constants.SERVER_STATE_INACTIVE)
-
         # Validate the share server migration complete.
         share = self.shares_v2_client.get_share(share['id'])['share']
         self._validate_share_server_migration_complete(
             share, dest_host, dest_server_id, snapshot_id=snapshot_id,
             share_network_id=dest_share_network_id)
+        self.admin_shares_client.wait_for_resource_deletion(
+            server_id=src_server_id)
 
     @decorators.idempotent_id('52e154eb-2d39-45af-b5c1-49ea569ab804')
     @tc.attr(base.TAG_POSITIVE, base.TAG_BACKEND)
diff --git a/manila_tempest_tests/tests/api/base.py b/manila_tempest_tests/tests/api/base.py
index 0e875c2..dd25062 100755
--- a/manila_tempest_tests/tests/api/base.py
+++ b/manila_tempest_tests/tests/api/base.py
@@ -1081,6 +1081,8 @@
         extra_specs_dict = {"driver_handles_share_servers": dhss}
         if extra_specs:
             extra_specs_dict.update(extra_specs)
+        if CONF.share.capability_thin_provisioned:
+            extra_specs_dict['thin_provisioning'] = 'True'
         return extra_specs_dict
 
     @classmethod
diff --git a/manila_tempest_tests/tests/api/test_scheduler_hints.py b/manila_tempest_tests/tests/api/test_scheduler_hints.py
new file mode 100644
index 0000000..83e5a1a
--- /dev/null
+++ b/manila_tempest_tests/tests/api/test_scheduler_hints.py
@@ -0,0 +1,102 @@
+# Copyright 2021 Cloudification GmbH
+# All Rights Reserved.
+#
+#    Licensed under the Apache License, Version 2.0 (the "License"); you may
+#    not use this file except in compliance with the License. You may obtain
+#    a copy of the License at
+#
+#         http://www.apache.org/licenses/LICENSE-2.0
+#
+#    Unless required by applicable law or agreed to in writing, software
+#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+#    License for the specific language governing permissions and limitations
+#    under the License.
+
+from tempest import config
+from tempest.lib import decorators
+from testtools import testcase as tc
+
+from manila_tempest_tests.tests.api import base
+from manila_tempest_tests import utils
+
+CONF = config.CONF
+
+
+class SharesSchedulerHintsTest(base.BaseSharesMixedTest):
+
+    @classmethod
+    def skip_checks(cls):
+        super(SharesSchedulerHintsTest, cls).skip_checks()
+        if not CONF.share.multi_backend:
+            raise cls.skipException("Manila multi-backend is disabled.")
+        elif len(CONF.share.backend_names) < 2:
+            raise cls.skipException("For running multi-backend tests required"
+                                    " two names in config. Skipping.")
+        elif any(not name for name in CONF.share.backend_names):
+            raise cls.skipException("Share backend names can not be empty. "
+                                    "Skipping.")
+        utils.check_skip_if_microversion_not_supported('2.65')
+
+    @classmethod
+    def resource_setup(cls):
+        super(SharesSchedulerHintsTest, cls).resource_setup()
+        # create share type
+        cls.share_type = cls.create_share_type()
+        cls.share_type_id = cls.share_type['id']
+
+        # create share
+        cls.share_a = cls.create_share(share_type_id=cls.share_type_id)
+
+    @decorators.idempotent_id('f96d5836-bfc9-4c22-888e-3f62d731573c')
+    @tc.attr(base.TAG_POSITIVE, base.TAG_API_WITH_BACKEND)
+    def test_same_host_scheduler_hint_in_share_creation(self):
+        scheduler_hint = {"same_host": "%s" % self.share_a["id"]}
+
+        # create share with metadata
+        share_b = self.create_share(share_type_id=self.share_type_id,
+                                    scheduler_hints=scheduler_hint,
+                                    cleanup_in_class=False)
+
+        # get backend of shares
+        share_a = self.admin_shares_v2_client.get_share(
+            self.share_a['id'])['share']
+        backend_a = share_a['host']
+        share_b = self.admin_shares_v2_client.get_share(
+            share_b['id'])['share']
+        backend_b = share_b['host']
+
+        # verify same backends
+        self.assertEqual(backend_a, backend_b)
+
+        # get metadata of share
+        metadata_a = self.shares_client.get_metadata(
+            self.share_a["id"])['metadata']
+        md_a = {"__affinity_same_host": "%s" % share_b["id"]}
+        metadata_b = self.shares_client.get_metadata(
+            share_b["id"])['metadata']
+        md_b = {"__affinity_same_host": "%s" % self.share_a["id"]}
+
+        # verify metadata
+        self.assertEqual(md_a, metadata_a)
+        self.assertEqual(md_b, metadata_b)
+
+    @decorators.idempotent_id('6569e0c3-43c9-4ee2-84ff-ea7fa8da8110')
+    @tc.attr(base.TAG_POSITIVE, base.TAG_API_WITH_BACKEND)
+    def test_different_host_scheduler_hint_in_share_creation(self):
+        scheduler_hint = {"different_host": "%s" % self.share_a["id"]}
+
+        # create share with metadata
+        share_c = self.create_share(share_type_id=self.share_type_id,
+                                    scheduler_hints=scheduler_hint,
+                                    cleanup_in_class=False)
+
+        # get backend of shares
+        share_a = self.admin_shares_v2_client.get_share(
+            self.share_a['id'])['share']
+        backend_a = share_a['host']
+        share_c = self.admin_shares_v2_client.get_share(share_c['id'])['share']
+        backend_c = share_c['host']
+
+        # verify different backends
+        self.assertNotEqual(backend_a, backend_c)
diff --git a/manila_tempest_tests/tests/api/test_scheduler_hints_negative.py b/manila_tempest_tests/tests/api/test_scheduler_hints_negative.py
new file mode 100644
index 0000000..c6c75f7
--- /dev/null
+++ b/manila_tempest_tests/tests/api/test_scheduler_hints_negative.py
@@ -0,0 +1,73 @@
+# Copyright 2021 Cloudification GmbH
+# All Rights Reserved.
+#
+#    Licensed under the Apache License, Version 2.0 (the "License"); you may
+#    not use this file except in compliance with the License. You may obtain
+#    a copy of the License at
+#
+#         http://www.apache.org/licenses/LICENSE-2.0
+#
+#    Unless required by applicable law or agreed to in writing, software
+#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+#    License for the specific language governing permissions and limitations
+#    under the License.
+
+from tempest import config
+from tempest.lib import decorators
+from tempest.lib import exceptions as lib_exc
+from testtools import testcase as tc
+
+from manila_tempest_tests import share_exceptions
+from manila_tempest_tests.tests.api import base
+from manila_tempest_tests import utils
+
+FAKE_SHARE_ID = "2d316e9f-39fc-468e-b2d9-634b25ae85f6"
+CONF = config.CONF
+
+
+class SharesSchedulerHintsNegativeTest(base.BaseSharesMixedTest):
+
+    @classmethod
+    def skip_checks(cls):
+        super(SharesSchedulerHintsNegativeTest, cls).skip_checks()
+        if not CONF.share.multi_backend:
+            raise cls.skipException("Manila multi-backend is disabled.")
+        elif len(CONF.share.backend_names) < 2:
+            raise cls.skipException("For running multi-backend tests required"
+                                    " two names in config. Skipping.")
+        elif any(not name for name in CONF.share.backend_names):
+            raise cls.skipException("Share backend names can not be empty. "
+                                    "Skipping.")
+        utils.check_skip_if_microversion_not_supported('2.65')
+
+    @classmethod
+    def resource_setup(cls):
+        super(SharesSchedulerHintsNegativeTest, cls).resource_setup()
+        # create share type
+        cls.share_type = cls.create_share_type()
+        cls.share_type_id = cls.share_type['id']
+
+        # create share
+        cls.share_a = cls.create_share(share_type_id=cls.share_type_id)
+
+    @decorators.idempotent_id('2228a187-4f03-4195-9e23-fa1a42110fdc')
+    @tc.attr(base.TAG_NEGATIVE, base.TAG_API_WITH_BACKEND)
+    def test_scheduler_hint_with_invalid_share_id(self):
+        scheduler_hint = {"same_host": FAKE_SHARE_ID}
+        self.assertRaises(lib_exc.NotFound,
+                          self.create_share,
+                          share_type_id=self.share_type_id,
+                          scheduler_hints=scheduler_hint,
+                          cleanup_in_class=False)
+
+    @decorators.idempotent_id('6f0c5561-8a6a-4cfb-bbe7-84ffc39bf78d')
+    @tc.attr(base.TAG_NEGATIVE, base.TAG_API_WITH_BACKEND)
+    def test_scheduler_hint_with_invalid_hint(self):
+        scheduler_hint = {"same_host": "%s" % self.share_a["id"],
+                          "different_host": "%s" % self.share_a["id"]}
+        self.assertRaises(share_exceptions.ShareBuildErrorException,
+                          self.create_share,
+                          share_type_id=self.share_type_id,
+                          scheduler_hints=scheduler_hint,
+                          cleanup_in_class=False)
diff --git a/manila_tempest_tests/tests/api/test_share_group_actions.py b/manila_tempest_tests/tests/api/test_share_group_actions.py
index 680b565..a07e99f 100644
--- a/manila_tempest_tests/tests/api/test_share_group_actions.py
+++ b/manila_tempest_tests/tests/api/test_share_group_actions.py
@@ -80,8 +80,8 @@
         # Create 2 shares - inside first and second share groups
         cls.share_name = data_utils.rand_name("tempest-share-name")
         cls.share_desc = data_utils.rand_name("tempest-share-description")
-        cls.share_size = 1
-        cls.share_size2 = 2
+        cls.share_size = CONF.share.share_size
+        cls.share_size2 = CONF.share.share_size + 2
         cls.shares = cls.create_shares([
             {'kwargs': {
                 'name': cls.share_name,
diff --git a/manila_tempest_tests/tests/api/test_share_groups_negative.py b/manila_tempest_tests/tests/api/test_share_groups_negative.py
index 68fb18f..c45cc95 100644
--- a/manila_tempest_tests/tests/api/test_share_groups_negative.py
+++ b/manila_tempest_tests/tests/api/test_share_groups_negative.py
@@ -65,7 +65,7 @@
         # Create a share in the share group
         cls.share_name = data_utils.rand_name("tempest-share-name")
         cls.share_desc = data_utils.rand_name("tempest-share-description")
-        cls.share_size = 1
+        cls.share_size = CONF.share.share_size
         cls.share = cls.create_share(
             name=cls.share_name,
             description=cls.share_desc,