Added ability to not run share group snapshot tests

Also added one more test for share group usages in order to have ability
to test usages when snapshots are not supported.

Change-Id: Ied4915c8110f90bf37fabe0b9eb575db2291a230
Related-Prod: https://mirantis.jira.com/browse/PRODX-48556
(cherry picked from commit a857dc55df61f6a4c61de453c8fdc7a3b6a0186b)
diff --git a/manila_tempest_tests/config.py b/manila_tempest_tests/config.py
index 56a5b5a..78fe966 100644
--- a/manila_tempest_tests/config.py
+++ b/manila_tempest_tests/config.py
@@ -243,6 +243,11 @@
                 default=True,
                 deprecated_name="run_consistency_group_tests",
                 help="Defines whether to run share group tests or not."),
+    cfg.BoolOpt("run_share_group_snapshot_tests",
+                default=True,
+                help="Defines whether to run tests that use share group "
+                     "snapshots or not. Disable this feature if used driver "
+                     "does not support it."),
     cfg.BoolOpt("run_replication_tests",
                 default=False,
                 help="Defines whether to run replication tests or not. "
diff --git a/manila_tempest_tests/tests/api/admin/test_quotas.py b/manila_tempest_tests/tests/api/admin/test_quotas.py
index e8377e1..08b2388 100644
--- a/manila_tempest_tests/tests/api/admin/test_quotas.py
+++ b/manila_tempest_tests/tests/api/admin/test_quotas.py
@@ -895,6 +895,13 @@
                 self.assertEqual(0, quotas[key]['reserved'])
                 self.assertEqual(0, quotas[key]['in_use'])
 
+    def _get_quota_set(self):
+        p_quotas = self.client.detail_quotas(
+            tenant_id=self.tenant_id)['quota_set']
+        u_quotas = self.client.detail_quotas(
+            tenant_id=self.tenant_id, user_id=self.user_id)['quota_set']
+        return p_quotas, u_quotas
+
     def _check_sg_usages(self, quotas, in_use, limit):
         """Helper method for 'test_share_group_quotas_usages' test."""
         self.assertEqual(0, int(quotas['share_groups']['reserved']))
@@ -910,10 +917,7 @@
 
     def _check_usages(self, sg_in_use, sgs_in_use):
         """Helper method for 'test_share_group_quotas_usages' test."""
-        p_quotas = self.client.detail_quotas(
-            tenant_id=self.tenant_id)['quota_set']
-        u_quotas = self.client.detail_quotas(
-            tenant_id=self.tenant_id, user_id=self.user_id)['quota_set']
+        p_quotas, u_quotas = self._get_quota_set()
         self._check_sg_usages(p_quotas, sg_in_use, 3)
         self._check_sg_usages(u_quotas, sg_in_use, 2)
         self._check_sgs_usages(p_quotas, sgs_in_use)
@@ -929,6 +933,8 @@
     @testtools.skipUnless(
         CONF.share.capability_create_share_from_snapshot_support,
         "Tests for shares from snapshots are disabled.")
+    @testtools.skipUnless(CONF.share.run_share_group_snapshot_tests,
+                          "Share group snapshot tests are disabled.")
     def test_share_group_quotas_usages(self):
         # Set quotas for project (3 SG, 1 SGS) and user (2 SG, 1 SGS)
         self.update_quotas(self.tenant_id,
@@ -990,3 +996,51 @@
         self.client.wait_for_resource_deletion(
             share_group_id=share_group1['id'])
         self._check_usages(0, 0)
+
+    @tc.attr(base.TAG_POSITIVE, base.TAG_API_WITH_BACKEND)
+    @testtools.skipUnless(
+        CONF.share.run_share_group_tests, 'Share Group tests disabled.')
+    @utils.skip_if_microversion_not_supported(SHARE_GROUPS_MICROVERSION)
+    @decorators.idempotent_id('76728d1b-0134-4a83-888b-b4cdbdcf0be0')
+    def test_share_group_quotas_usages_no_snapshots(self):
+        # Set quotas for project (2 SG) and user (1 SG)
+        self.update_quotas(self.tenant_id,
+                           share_groups=2)
+
+        self.update_quotas(self.tenant_id,
+                           user_id=self.user_id,
+                           share_groups=1)
+
+        # Check usages, they should be 0s
+        p_quotas, u_quotas = self._get_quota_set()
+        self._check_sg_usages(p_quotas, 0, 2)
+        self._check_sg_usages(u_quotas, 0, 1)
+
+        # Create SG1 and check usages
+        share_group1 = self.create_share_group(
+            share_group_type_id=self.share_group_type_id,
+            share_type_ids=[self.share_type_id],
+            cleanup_in_class=False,
+            client=self.client)
+        p_quotas, u_quotas = self._get_quota_set()
+        self._check_sg_usages(p_quotas, 1, 2)
+        self._check_sg_usages(u_quotas, 1, 1)
+
+        # Check creation of SG2 fails and check usages
+        self.assertRaises(
+            lib_exc.OverLimit,
+            self.create_share_group,
+            share_group_type_id=self.share_group_type_id,
+            share_type_ids=[self.share_type_id],
+            client=self.client, cleanup_in_class=False)
+        p_quotas, u_quotas = self._get_quota_set()
+        self._check_sg_usages(p_quotas, 1, 2)
+        self._check_sg_usages(u_quotas, 1, 1)
+
+        # Delete SG1 and check usages
+        self.client.delete_share_group(share_group1['id'])
+        self.client.wait_for_resource_deletion(
+            share_group_id=share_group1['id'])
+        p_quotas, u_quotas = self._get_quota_set()
+        self._check_sg_usages(p_quotas, 0, 2)
+        self._check_sg_usages(u_quotas, 0, 1)
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 d60d054..0a00aae 100644
--- a/manila_tempest_tests/tests/api/test_share_group_actions.py
+++ b/manila_tempest_tests/tests/api/test_share_group_actions.py
@@ -95,7 +95,8 @@
         ])
 
         # Create share group snapshots
-        if CONF.share.capability_snapshot_support:
+        if CONF.share.capability_snapshot_support and \
+            CONF.share.run_share_group_snapshot_tests:
             cls.sg_snap_name = data_utils.rand_name("tempest-sg-snap-name")
             cls.sg_snap_desc = data_utils.rand_name("tempest-sg-snap-desc")
 
@@ -267,6 +268,8 @@
                             LATEST_MICROVERSION]))
     @testtools.skipUnless(CONF.share.run_snapshot_tests,
                           "Snapshot tests are disabled.")
+    @testtools.skipUnless(CONF.share.run_share_group_snapshot_tests,
+                          "Share group snapshot tests are disabled.")
     def test_get_share_group_snapshot(self, version):
         utils.check_skip_if_microversion_not_supported(version)
 
@@ -297,6 +300,8 @@
     @tc.attr(base.TAG_POSITIVE, base.TAG_API_WITH_BACKEND)
     @testtools.skipUnless(CONF.share.run_snapshot_tests,
                           "Snapshot tests are disabled.")
+    @testtools.skipUnless(CONF.share.run_share_group_snapshot_tests,
+                          "Share group snapshot tests are disabled.")
     def test_get_share_group_snapshot_members_min(self):
         sg_snapshot = self.shares_v2_client.get_share_group_snapshot(
             self.sg_snapshot['id'],
@@ -331,6 +336,8 @@
     @testtools.skipUnless(
         CONF.share.capability_create_share_from_snapshot_support,
         "Tests creating shares from snapshots are disabled.")
+    @testtools.skipUnless(CONF.share.run_share_group_snapshot_tests,
+                          "Share group snapshot tests are disabled.")
     def test_create_share_group_from_populated_share_group_snapshot(self,
                                                                     version):
         utils.check_skip_if_microversion_not_supported(version)
diff --git a/manila_tempest_tests/tests/api/test_share_groups.py b/manila_tempest_tests/tests/api/test_share_groups.py
index b203481..0f93ea5 100644
--- a/manila_tempest_tests/tests/api/test_share_groups.py
+++ b/manila_tempest_tests/tests/api/test_share_groups.py
@@ -107,6 +107,8 @@
     @tc.attr(base.TAG_POSITIVE, base.TAG_API_WITH_BACKEND)
     @testtools.skipUnless(CONF.share.run_snapshot_tests,
                           "Snapshot tests are disabled.")
+    @testtools.skipUnless(CONF.share.run_share_group_snapshot_tests,
+                          "Share group snapshot tests are disabled.")
     def test_create_delete_empty_share_group_snapshot_min(self):
         # Create base share group
         share_group = self.create_share_group(
@@ -150,6 +152,8 @@
     @tc.attr(base.TAG_POSITIVE, base.TAG_API_WITH_BACKEND)
     @testtools.skipUnless(CONF.share.run_snapshot_tests,
                           "Snapshot tests are disabled.")
+    @testtools.skipUnless(CONF.share.run_share_group_snapshot_tests,
+                          "Share group snapshot tests are disabled.")
     def test_create_share_group_from_empty_share_group_snapshot_min(self):
         # Create base share group
         share_group = self.create_share_group(
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 c45cc95..f63fa34 100644
--- a/manila_tempest_tests/tests/api/test_share_groups_negative.py
+++ b/manila_tempest_tests/tests/api/test_share_groups_negative.py
@@ -73,7 +73,8 @@
             share_type_id=cls.share_type_id,
             share_group_id=cls.share_group['id'],
         )
-        if CONF.share.run_snapshot_tests:
+        if CONF.share.run_snapshot_tests and \
+            CONF.share.run_share_group_snapshot_tests:
             # Create a share group snapshot of the share group
             cls.sg_snap_name = data_utils.rand_name("tempest-sg-snap-name")
             cls.sg_snap_desc = data_utils.rand_name(
@@ -86,6 +87,8 @@
 
     @decorators.idempotent_id('7ce3fb52-1bec-42b1-9b4f-671c8465764b')
     @tc.attr(base.TAG_NEGATIVE, base.TAG_API_WITH_BACKEND)
+    @testtools.skipUnless(CONF.share.run_share_group_snapshot_tests,
+                          "Share group snapshot tests are disabled.")
     def test_create_sg_with_invalid_source_sg_snapshot_id_value_min(self):
         self.assertRaises(
             lib_exc.BadRequest,
@@ -96,6 +99,8 @@
 
     @decorators.idempotent_id('43c7a454-06b4-4c6e-8aaf-34709db64e28')
     @tc.attr(base.TAG_NEGATIVE, base.TAG_API_WITH_BACKEND)
+    @testtools.skipUnless(CONF.share.run_share_group_snapshot_tests,
+                          "Share group snapshot tests are disabled.")
     def test_create_sg_with_nonexistent_source_sg_snapshot_id_value_min(self):
         self.assertRaises(
             lib_exc.BadRequest,
@@ -146,6 +151,8 @@
 
     @decorators.idempotent_id('25a829e2-be7d-4a4d-881e-bc0634515985')
     @tc.attr(base.TAG_NEGATIVE, base.TAG_API_WITH_BACKEND)
+    @testtools.skipUnless(CONF.share.run_share_group_snapshot_tests,
+                          "Share group snapshot tests are disabled.")
     def test_create_sg_snapshot_with_invalid_sg_id_value_min(self):
         self.assertRaises(
             lib_exc.BadRequest,
@@ -156,6 +163,8 @@
 
     @decorators.idempotent_id('16ad5a77-0ef7-4906-8e14-56703c2c9d71')
     @tc.attr(base.TAG_NEGATIVE, base.TAG_API_WITH_BACKEND)
+    @testtools.skipUnless(CONF.share.run_share_group_snapshot_tests,
+                          "Share group snapshot tests are disabled.")
     def test_create_sg_snapshot_with_nonexistent_sg_id_value_min(self):
         self.assertRaises(
             lib_exc.BadRequest,
@@ -213,6 +222,8 @@
     @tc.attr(base.TAG_NEGATIVE, base.TAG_API_WITH_BACKEND)
     @testtools.skipUnless(CONF.share.run_snapshot_tests,
                           "Snapshot tests are disabled.")
+    @testtools.skipUnless(CONF.share.run_share_group_snapshot_tests,
+                          "Share group snapshot tests are disabled.")
     def test_delete_sg_in_use_by_sg_snapshot_min(self):
         self.assertRaises(
             lib_exc.Conflict,
@@ -224,6 +235,8 @@
     @tc.attr(base.TAG_NEGATIVE, base.TAG_API_WITH_BACKEND)
     @testtools.skipUnless(CONF.share.run_snapshot_tests,
                           "Snapshot tests are disabled.")
+    @testtools.skipUnless(CONF.share.run_share_group_snapshot_tests,
+                          "Share group snapshot tests are disabled.")
     def test_delete_share_in_use_by_sg_snapshot_min(self):
         params = {'share_group_id': self.share['share_group_id']}
         self.assertRaises(