Merge "[Tempest] Remove noqa filters"
diff --git a/manila_tempest_tests/config.py b/manila_tempest_tests/config.py
index 33e88fb..3427b5d 100644
--- a/manila_tempest_tests/config.py
+++ b/manila_tempest_tests/config.py
@@ -34,7 +34,7 @@
                help="The minimum api microversion is configured to be the "
                     "value of the minimum microversion supported by Manila."),
     cfg.StrOpt("max_api_microversion",
-               default="2.16",
+               default="2.17",
                help="The maximum api microversion is configured to be the "
                     "value of the latest microversion supported by Manila."),
     cfg.StrOpt("region",
diff --git a/manila_tempest_tests/tests/api/admin/test_snapshot_manage.py b/manila_tempest_tests/tests/api/admin/test_snapshot_manage.py
index 3eed886..ecdd3bd 100644
--- a/manila_tempest_tests/tests/api/admin/test_snapshot_manage.py
+++ b/manila_tempest_tests/tests/api/admin/test_snapshot_manage.py
@@ -13,6 +13,7 @@
 #    License for the specific language governing permissions and limitations
 #    under the License.
 
+import ddt
 import six
 from tempest import config
 from tempest.lib.common.utils import data_utils
@@ -21,10 +22,12 @@
 import testtools
 
 from manila_tempest_tests.tests.api import base
+from manila_tempest_tests import utils
 
 CONF = config.CONF
 
 
+@ddt.ddt
 class ManageNFSSnapshotTest(base.BaseSharesAdminTest):
     protocol = 'nfs'
 
@@ -59,31 +62,12 @@
             cleanup_in_class=True,
             extra_specs=cls.extra_specs)
 
-        creation_data = {'kwargs': {
-            'share_type_id': cls.st['share_type']['id'],
-            'share_protocol': cls.protocol,
-        }}
+        # Create the base share
+        cls.share = cls.create_share(share_type_id=cls.st['share_type']['id'],
+                                     share_protocol=cls.protocol)
 
-        # Data for creating shares
-        data = [creation_data]
-        shares_created = cls.create_shares(data)
-
-        cls.snapshot = None
-        cls.shares = []
-        # Load all share data (host, etc.)
-        for share in shares_created:
-            cls.shares.append(cls.shares_v2_client.get_share(share['id']))
-            # Create snapshot
-            snap_name = data_utils.rand_name("tempest-snapshot-name")
-            snap_desc = data_utils.rand_name(
-                "tempest-snapshot-description")
-            snap = cls.create_snapshot_wait_for_active(
-                share['id'], snap_name, snap_desc)
-            cls.snapshot = cls.shares_v2_client.get_snapshot(snap['id'])
-            # Unmanage snapshot
-            cls.shares_v2_client.unmanage_snapshot(snap['id'])
-            cls.shares_client.wait_for_resource_deletion(
-                snapshot_id=snap['id'])
+        # Get updated data
+        cls.share = cls.shares_v2_client.get_share(cls.share['id'])
 
     def _test_manage(self, snapshot, version=CONF.share.max_api_microversion):
         name = ("Name for 'managed' snapshot that had ID %s" %
@@ -97,7 +81,8 @@
             snapshot['provider_location'],
             name=name,
             description=description,
-            driver_options={}
+            driver_options={},
+            version=version,
         )
 
         # Add managed snapshot to cleanup queue
@@ -109,6 +94,19 @@
         self.shares_v2_client.wait_for_snapshot_status(snapshot['id'],
                                                        'available')
 
+        # Verify manage snapshot API response
+        expected_keys = ["status", "links", "share_id", "name",
+                         "share_proto", "created_at",
+                         "description", "id", "share_size", "size",
+                         "provider_location"]
+        if utils.is_microversion_ge(version, '2.17'):
+            expected_keys.extend(["user_id", "project_id"])
+
+        actual_keys = snapshot.keys()
+
+        # Strict key check
+        self.assertEqual(set(expected_keys), set(actual_keys))
+
         # Verify data of managed snapshot
         get_snapshot = self.shares_v2_client.get_snapshot(snapshot['id'])
         self.assertEqual(name, get_snapshot['name'])
@@ -126,9 +124,31 @@
                           get_snapshot['id'])
 
     @test.attr(type=[base.TAG_POSITIVE, base.TAG_BACKEND])
-    def test_manage(self):
+    @ddt.data('2.12', '2.16', CONF.share.max_api_microversion)
+    def test_manage_different_versions(self, version):
+        """Run snapshot manage test for multiple versions.
+
+        This test is configured with ddt to run for the configured maximum
+        version as well as versions 2.12 (when the API was introduced) and
+        2.16.
+        """
+        # Skip in case specified version is not supported
+        utils.skip_if_microversion_not_supported(version)
+
+        snap_name = data_utils.rand_name("tempest-snapshot-name")
+        snap_desc = data_utils.rand_name("tempest-snapshot-description")
+        # Create snapshot
+        snapshot = self.create_snapshot_wait_for_active(
+            self.share['id'], snap_name, snap_desc)
+        snapshot = self.shares_v2_client.get_snapshot(snapshot['id'])
+        # Unmanage snapshot
+        self.shares_v2_client.unmanage_snapshot(snapshot['id'],
+                                                version=version)
+        self.shares_client.wait_for_resource_deletion(
+            snapshot_id=snapshot['id'])
+
         # Manage snapshot
-        self._test_manage(snapshot=self.snapshot)
+        self._test_manage(snapshot=snapshot, version=version)
 
 
 class ManageCIFSSnapshotTest(ManageNFSSnapshotTest):
diff --git a/manila_tempest_tests/tests/api/test_shares.py b/manila_tempest_tests/tests/api/test_shares.py
index 1da57e4..2acd81a 100644
--- a/manila_tempest_tests/tests/api/test_shares.py
+++ b/manila_tempest_tests/tests/api/test_shares.py
@@ -104,14 +104,26 @@
 
         # create snapshot
         snap = self.create_snapshot_wait_for_active(self.share["id"])
+
         detailed_elements = {'name', 'id', 'description',
                              'created_at', 'share_proto', 'size', 'share_size',
                              'share_id', 'status', 'links'}
-        self.assertTrue(detailed_elements.issubset(snap.keys()),
-                        'At least one expected element missing from snapshot '
-                        'response. Expected %(expected)s, got %(actual)s.' % {
-                            "expected": detailed_elements,
-                            "actual": snap.keys()})
+        msg = (
+            "At least one expected element missing from share "
+            "response. Expected %(expected)s, got %(actual)s." % {
+                "expected": detailed_elements,
+                "actual": snap.keys(),
+            }
+        )
+        self.assertTrue(detailed_elements.issubset(snap.keys()), msg)
+
+        # In v2.17 and beyond, we expect user_id and project_id keys
+        if utils.is_microversion_supported('2.17'):
+            detailed_elements.update({'user_id', 'project_id'})
+            self.assertTrue(detailed_elements.issubset(snap.keys()), msg)
+        else:
+            self.assertNotIn('user_id', detailed_elements)
+            self.assertNotIn('project_id', detailed_elements)
 
         # delete snapshot
         self.shares_client.delete_snapshot(snap["id"])
diff --git a/manila_tempest_tests/tests/api/test_shares_actions.py b/manila_tempest_tests/tests/api/test_shares_actions.py
index 16b8b58..3d4c54b 100644
--- a/manila_tempest_tests/tests/api/test_shares_actions.py
+++ b/manila_tempest_tests/tests/api/test_shares_actions.py
@@ -13,6 +13,7 @@
 #    License for the specific language governing permissions and limitations
 #    under the License.
 
+import ddt
 import six
 from tempest import config
 from tempest.lib.common.utils import data_utils
@@ -23,8 +24,10 @@
 from manila_tempest_tests import utils
 
 CONF = config.CONF
+LATEST_MICROVERSION = CONF.share.max_api_microversion
 
 
+@ddt.ddt
 class SharesActionsTest(base.BaseSharesTest):
     """Covers share functionality, that doesn't related to share type."""
 
@@ -399,30 +402,58 @@
     @test.attr(type=[base.TAG_POSITIVE, base.TAG_API_WITH_BACKEND])
     @testtools.skipUnless(CONF.share.run_snapshot_tests,
                           "Snapshot tests are disabled.")
-    def test_get_snapshot(self):
+    @ddt.data(None, '2.16', LATEST_MICROVERSION)
+    def test_get_snapshot(self, version):
 
         # get snapshot
-        get = self.shares_client.get_snapshot(self.snap["id"])
+        if version is None:
+            snapshot = self.shares_client.get_snapshot(self.snap["id"])
+        else:
+            utils.skip_if_microversion_not_supported(version)
+            snapshot = self.shares_v2_client.get_snapshot(
+                self.snap["id"], version=version)
 
         # verify keys
         expected_keys = ["status", "links", "share_id", "name",
                          "share_proto", "created_at",
-                         "description", "id", "share_size"]
-        actual_keys = get.keys()
-        [self.assertIn(key, actual_keys) for key in expected_keys]
+                         "description", "id", "share_size", "size"]
+        if version and utils.is_microversion_ge(version, '2.17'):
+            expected_keys.extend(["user_id", "project_id"])
+        actual_keys = snapshot.keys()
+
+        # strict key check
+        self.assertEqual(set(expected_keys), set(actual_keys))
 
         # verify data
         msg = "Expected name: '%s', actual name: '%s'" % (self.snap_name,
-                                                          get["name"])
-        self.assertEqual(self.snap_name, get["name"], msg)
+                                                          snapshot["name"])
+        self.assertEqual(self.snap_name, snapshot["name"], msg)
 
-        msg = "Expected description: '%s', "\
-              "actual description: '%s'" % (self.snap_desc, get["description"])
-        self.assertEqual(self.snap_desc, get["description"], msg)
+        msg = ("Expected description: '%s' actual description: '%s'" %
+               (self.snap_desc, snapshot["description"]))
+        self.assertEqual(self.snap_desc, snapshot["description"], msg)
 
-        msg = "Expected share_id: '%s', "\
-              "actual share_id: '%s'" % (self.shares[0]["id"], get["share_id"])
-        self.assertEqual(self.shares[0]["id"], get["share_id"], msg)
+        msg = ("Expected share_id: '%s', actual share_id: '%s'" %
+               (self.shares[0]["id"], snapshot["share_id"]))
+        self.assertEqual(self.shares[0]["id"], snapshot["share_id"], msg)
+
+        # Verify that the user_id and project_id are same as the one for
+        # the base share
+        if version and utils.is_microversion_ge(version, '2.17'):
+            msg = ("Expected %(key)s in snapshot: '%(expected)s', "
+                   "actual %(key)s in snapshot: '%(actual)s'")
+            self.assertEqual(self.shares[0]['user_id'],
+                             snapshot['user_id'],
+                             msg % {
+                                 'expected': self.shares[0]['user_id'],
+                                 'actual': snapshot['user_id'],
+                                 'key': 'user_id'})
+            self.assertEqual(self.shares[0]['project_id'],
+                             snapshot['project_id'],
+                             msg % {
+                                 'expected': self.shares[0]['project_id'],
+                                 'actual': snapshot['project_id'],
+                                 'key': 'project_id'})
 
     @test.attr(type=[base.TAG_POSITIVE, base.TAG_API_WITH_BACKEND])
     @testtools.skipUnless(CONF.share.run_snapshot_tests,
@@ -444,16 +475,26 @@
     @test.attr(type=[base.TAG_POSITIVE, base.TAG_API_WITH_BACKEND])
     @testtools.skipUnless(CONF.share.run_snapshot_tests,
                           "Snapshot tests are disabled.")
-    def test_list_snapshots_with_detail(self):
+    @ddt.data(None, '2.16', LATEST_MICROVERSION)
+    def test_list_snapshots_with_detail(self, version):
 
         # list share snapshots
-        snaps = self.shares_client.list_snapshots_with_detail()
+        if version is None:
+            snaps = self.shares_client.list_snapshots_with_detail()
+        else:
+            utils.skip_if_microversion_not_supported(version)
+            snaps = self.shares_v2_client.list_snapshots_with_detail(
+                version=version)
 
         # verify keys
-        keys = ["status", "links", "share_id", "name",
-                "share_proto", "created_at",
-                "description", "id", "share_size"]
-        [self.assertIn(key, sn.keys()) for sn in snaps for key in keys]
+        expected_keys = ["status", "links", "share_id", "name",
+                         "share_proto", "created_at", "description", "id",
+                         "share_size", "size"]
+        if version and utils.is_microversion_ge(version, '2.17'):
+            expected_keys.extend(["user_id", "project_id"])
+
+        # strict key check
+        [self.assertEqual(set(expected_keys), set(s.keys())) for s in snaps]
 
         # our share id in list and have no duplicates
         gen = [sid["id"] for sid in snaps if sid["id"] in self.snap["id"]]