Merge "Add ability to generate required parameters for manila in tempest conf"
diff --git a/_modules/runtest/tempest_sections/share.py b/_modules/runtest/tempest_sections/share.py
index be882df..5b1f86c 100644
--- a/_modules/runtest/tempest_sections/share.py
+++ b/_modules/runtest/tempest_sections/share.py
@@ -10,6 +10,187 @@
         }
 }
 
+FEATURE_SUPPORT = {
+    'lvm':
+        {
+            'create_delete_share': 'mitaka',
+            'manage_unmanage_share': '~',
+            'extend_share': 'mitaka',
+            'shrink_share': '~',
+            'create_delete_snapshot': 'mitaka',
+            'create_share_from_snapshot': 'mitaka',
+            'manage_unmanage_snapshot': '~',
+            'revert_to_snapshot': 'ocata',
+            'mountable_snapshot': 'ocata'
+        },
+    'glusterfs':
+        {
+            'create_delete_share': 'juno',
+            'manage_unmanage_share': '~',
+            'extend_share': '~',
+            'shrink_share': '~',
+            'create_delete_snapshot': 'liberty',
+            'create_share_from_snapshot': 'liberty',
+            'manage_unmanage_snapshot': '~',
+            'revert_to_snapshot': '~',
+            'mountable_snapshot': '~'
+        },
+    'nexentastor4':
+        {
+            'create_delete_share': 'newton',
+            'manage_unmanage_share': '~',
+            'extend_share': 'newton',
+            'shrink_share': '~',
+            'create_delete_snapshot': 'newton',
+            'create_share_from_snapshot': 'newton',
+            'manage_unmanage_snapshot': '~',
+            'revert_to_snapshot': '~',
+            'mountable_snapshot': '~'
+        },
+    'nexentastor5':
+        {
+            'create_delete_share': 'newton',
+            'manage_unmanage_share': '~',
+            'extend_share': 'newton',
+            'shrink_share': 'newton',
+            'create_delete_snapshot': 'newton',
+            'create_share_from_snapshot': 'newton',
+            'manage_unmanage_snapshot': '~',
+            'revert_to_snapshot': '~',
+            'mountable_snapshot': '~'
+        }
+}
+
+ACCESS_RULES = {
+    'lvm':
+        {
+            'ipv4':
+                {
+                    'release': 'mitaka',
+                    'protocols': 'nfs'
+                },
+            'ipv6':
+                {
+                    'release': 'pike',
+                    'protocols': 'nfs'
+                },
+            'user':
+                {
+                    'release': 'mitaka',
+                    'protocols': 'cifs'
+                }
+        },
+    'glusterfs':
+        {
+            'ipv4':
+                {
+                    'release': 'juno',
+                    'protocols': 'nfs'
+                },
+            'ipv6':
+                {
+                    'release': '~',
+                    'protocols': ''
+                },
+            'user':
+                {
+                    'release': '~',
+                    'protocols': ''
+                }
+        },
+    'nexentastor4':
+        {
+            'ipv4':
+                {
+                    'release': 'newton',
+                    'protocols': 'nfs'
+                },
+            'ipv6':
+                {
+                    'release': '~',
+                    'protocols': ''
+                },
+            'user':
+                {
+                    'release': '~',
+                    'protocols': ''
+                }
+        },
+    'nexentastor5':
+        {
+             'ipv4':
+                {
+                    'release': 'newton',
+                    'protocols': 'nfs'
+                },
+            'ipv6':
+                {
+                    'release': '~',
+                    'protocols': ''
+                },
+            'user':
+                {
+                    'release': '~',
+                    'protocols': ''
+                }
+        }
+}
+
+COMMON_CAPABILITIES = {
+    'lvm':
+        {
+            'dedupe': '~',
+            'compression': '~',
+            'thin_provisioning': '~',
+            'thick_provisioning': 'mitaka',
+            'qos': '~',
+            'create_share_from_snapshot': 'kilo',
+            'revert_to_snapshot': 'ocata',
+            'mountable_snapshot': 'ocata',
+            'ipv4_support': 'pike',
+            'ipv6_support': 'pike'
+        },
+    'glusterfs':
+        {
+            'dedupe': '~',
+            'compression': '~',
+            'thin_provisioning': '~',
+            'thick_provisioning': 'liberty',
+            'qos': '~',
+            'create_share_from snapshot': 'liberty',
+            'revert_to_snapshot': '~',
+            'mountable_snapshot': '~',
+            'ipv4_support': 'pike',
+            'ipv6_support': '~'
+        },
+    'nexentastor4':
+        {
+            'dedupe': 'newton',
+            'compression': 'newton',
+            'thin_provisioning': 'newton',
+            'thick_provisioning': 'newton',
+            'qos': '~',
+            'create_share_from_snapshot': 'newton',
+            'revert_to_snapshot': '~',
+            'mountable_snapshot': '~',
+            'ipv4_support': 'pike',
+            'ipv6_support': '~'
+        },
+    'nexentastor5':
+        {
+            'dedupe': 'newton',
+            'compression': 'newton',
+            'thin_provisioning': 'newton',
+            'thick_provisioning': 'newton',
+            'qos': '~',
+            'create_share_from_snapshot': 'newton',
+            'revert_to_snapshot': '~',
+            'mountable_snapshot': '~',
+            'ipv4_support': 'newton',
+            'ipv6_support': '~'
+        }
+}
+
 
 class Share(base_section.BaseSection):
     name = "share"
@@ -45,18 +226,29 @@
     @property
     def backend_names(self):
         c = conditions.BaseRule('manila.share.enabled', 'eq', True)
-        backend_names = []
         backends = self.get_item_when_condition_match(
             'manila.share.enabled_share_backends', c)
+        backend_names = []
         if backends:
             for item, value in backends.items():
                 if value.get('enabled', True):
                     backend_names.append(value['name'])
-        return ', '.join(backend_names)
+            return ', '.join(backend_names)
 
     @property
     def capability_create_share_from_snapshot_support(self):
-        pass
+        c = conditions.BaseRule('manila.share.enabled', 'eq', True)
+        manila_version = self.get_item_when_condition_match(
+            'manila.share.version', c)
+        backends = self.get_item_when_condition_match(
+            'manila.share.enabled_share_backends', c)
+        if backends:
+            for item, value in backends.items():
+                driver = value.get('type')
+                if manila_version >= COMMON_CAPABILITIES[driver][
+                    'create_share_from_snapshot']:
+                    return True
+            return False
 
     @property
     def capability_storage_protocol(self):
@@ -64,35 +256,56 @@
 
     @property
     def default_share_type_name(self):
-        pass
+        c = conditions.BaseRule('manila.api.enabled', 'eq', True)
+        return self.get_item_when_condition_match(
+            'manila.common.default_share_type', c)
 
     @property
     def enable_ip_rules_for_protocols(self):
-        pass
+        c = conditions.BaseRule('manila.share.enabled', 'eq', True)
+        manila_version = self.get_item_when_condition_match(
+            'manila.share.version', c)
+        backends = self.get_item_when_condition_match(
+            'manila.share.enabled_share_backends', c)
+        if backends:
+            for item, value in backends.items():
+                driver = value.get('type')
+                if manila_version >= ACCESS_RULES[driver]['ipv4']['release']:
+                    return ACCESS_RULES[driver]['ipv4']['protocols']
 
     @property
     def enable_user_rules_for_protocols(self):
-        pass
+        c = conditions.BaseRule('manila.share.enabled', 'eq', True)
+        manila_version = self.get_item_when_condition_match(
+            'manila.share.version', c)
+        backends = self.get_item_when_condition_match(
+            'manila.share.enabled_share_backends', c)
+        if backends:
+            for item, value in backends.items():
+                driver = value.get('type')
+                if manila_version >= ACCESS_RULES[driver]['user']['release']:
+                    return ACCESS_RULES[driver]['user']['protocols']
 
     @property
     def enable_protocols(self):
-        c = conditions.BaseRule('manila.share.enabled', 'eq', True)
-        proto = self.get_item_when_condition_match(
-            'manila.share.shares.Share2.share_proto', c)
-        if proto:
-            return proto.lower()
+        pass
 
     @property
     def multitenancy_enabled(self):
         c = conditions.BaseRule('manila.share.enabled', 'eq', True)
-        return self.get_item_when_condition_match(
-            'manila.share.shares.Share2.share_type.dhss',
-            c) or False
+        backends = self.get_item_when_condition_match(
+            'manila.share.enabled_share_backends', c)
+        if backends:
+            for item, value in backends.items():
+                if value.get('dhss', True):
+                    return True
+            return False
 
     @property
     def multi_backend(self):
-        c = conditions.BaseRule('manila.api.enabled', 'eq', True)
-        backends = self.get_item_when_condition_match('manila.share.enabled_share_backends', c)
+        c = conditions.BaseRule('manila.share.enabled', 'eq', True)
+        backends = self.get_item_when_condition_match(
+            'manila.share.enabled_share_backends', c)
         backend_names = []
         if backends:
             for item, value in backends.items():
@@ -103,16 +316,20 @@
     @property
     def max_api_microversion(self):
         c = conditions.BaseRule('manila.api.enabled', 'eq', True)
-        manila_version = self.get_item_when_condition_match('manila.api.version', c)
+        manila_version = self.get_item_when_condition_match(
+            'manila.api.version', c)
         if manila_version:
-            return MICROVERSION_RELEASE_MAPPING[manila_version]['max_api_microversion']
+            return MICROVERSION_RELEASE_MAPPING[manila_version][
+                'max_api_microversion']
 
     @property
     def min_api_microversion(self):
         c = conditions.BaseRule('manila.api.enabled', 'eq', True)
-        manila_version = self.get_item_when_condition_match('manila.api.version', c)
+        manila_version = self.get_item_when_condition_match(
+            'manila.api.version', c)
         if manila_version:
-            return MICROVERSION_RELEASE_MAPPING[manila_version]['min_api_microversion']
+            return MICROVERSION_RELEASE_MAPPING[manila_version][
+                'min_api_microversion']
 
     @property
     def run_ipv6_tests(self):
@@ -120,7 +337,18 @@
 
     @property
     def run_mount_snapshot_tests(self):
-        pass
+        c = conditions.BaseRule('manila.share.enabled', 'eq', True)
+        manila_version = self.get_item_when_condition_match(
+            'manila.share.version', c)
+        backends = self.get_item_when_condition_match(
+            'manila.share.enabled_share_backends', c)
+        if backends:
+            for item, value in backends.items():
+                driver = value.get('type')
+                if manila_version >= COMMON_CAPABILITIES[driver][
+                    'mountable_snapshot']:
+                    return True
+            return False
 
     @property
     def run_migration_with_preserve_snapshots_tests(self):
@@ -130,9 +358,11 @@
     def run_driver_assisted_migration_tests(self):
         pass
 
+    # Defines whether to run host-assisted migration tests or not
     @property
     def run_host_assisted_migration_tests(self):
-        pass
+        if conditions.BaseRule('manila.api.enabled', 'eq', True):
+            return False
 
     @property
     def run_replication_tests(self):
@@ -146,13 +376,33 @@
     def run_manage_unmanage_tests(self):
         pass
 
+    # Defines whether to run share group tests or not
     @property
     def run_share_group_tests(self):
-        pass
+        c = conditions.BaseRule('manila.share.enabled', 'eq', True)
+        backends = self.get_item_when_condition_match(
+            'manila.share.enabled_share_backends', c)
+        backend_names = []
+        if backends:
+            for item, value in backends.items():
+                if value.get('enabled', True):
+                    backend_names.append(value['name'])
+            return True if len(backend_names) > 1 else False
 
     @property
     def run_revert_to_snapshot_tests(self):
-        pass
+        c = conditions.BaseRule('manila.share.enabled', 'eq', True)
+        manila_version = self.get_item_when_condition_match(
+            'manila.share.version', c)
+        backends = self.get_item_when_condition_match(
+            'manila.share.enabled_share_backends', c)
+        if backends:
+            for item, value in backends.items():
+                driver = value.get('type')
+                if manila_version >= COMMON_CAPABILITIES[driver][
+                    'revert_to_snapshot']:
+                    return True
+            return False
 
     @property
     def run_snapshot_tests(self):
@@ -160,7 +410,17 @@
 
     @property
     def run_shrink_tests(self):
-        pass
+        c = conditions.BaseRule('manila.share.enabled', 'eq', True)
+        manila_version = self.get_item_when_condition_match(
+            'manila.share.version', c)
+        backends = self.get_item_when_condition_match(
+            'manila.share.enabled_share_backends', c)
+        if backends:
+            for item, value in backends.items():
+                driver = value.get('type')
+                if manila_version >= FEATURE_SUPPORT[driver]['shrink_share']:
+                    return True
+            return False
 
     @property
     def run_quota_tests(self):
@@ -169,9 +429,11 @@
     # Defines number of retries for share creation.
     @property
     def share_creation_retry_number(self):
-        pass
+        if conditions.BaseRule('manila.api.enabled', 'eq', True):
+            return 2
 
     # Whether to suppress errors with clean up operation or not.
     @property
     def suppress_errors_in_cleanup(self):
-        pass
+        if conditions.BaseRule('manila.api.enabled', 'eq', True):
+            return False
\ No newline at end of file