From 9cafd3d045b6253a6821e38857ebfd9f3675aeda Mon Sep 17 00:00:00 2001
From: Leticia Wanderley <leticiafwanderley@gmail.com>
Date: Fri, 4 Aug 2017 00:22:34 -0300
Subject: [PATCH] Fix identity tests when domain specific drivers are enabled

This updates users and groups identity tests to check the existence
of domain specific drivers and, therefore, the existence of users
and groups on different domain drivers.

This adds a new feature flag to be used when domain specific drivers
are enabled.

Change-Id: Iedb470c51fa2174ab7651e6b7e22eff1f25f7aac
---
 ...ntity-tests-domain-drivers-76235f6672221e45.yaml |  7 +++++++
 tempest/api/identity/admin/v3/test_groups.py        | 12 +++++++++++-
 tempest/api/identity/admin/v3/test_list_users.py    | 21 ++++++++++++++++++++-
 tempest/config.py                                   |  6 ++++++
 4 files changed, 44 insertions(+), 2 deletions(-)
 create mode 100644 releasenotes/notes/identity-tests-domain-drivers-76235f6672221e45.yaml

Index: tempest-12.2.1.dev177/releasenotes/notes/identity-tests-domain-drivers-76235f6672221e45.yaml
===================================================================
--- /dev/null
+++ tempest-12.2.1.dev177/releasenotes/notes/identity-tests-domain-drivers-76235f6672221e45.yaml
@@ -0,0 +1,7 @@
+---
+features:
+  - |
+    A new boolean config option ``domain_specific_drivers``
+    is added to the section ``identity-feature-enabled``.
+    This option must be enabled when testing an environment that
+    is configured to use domain-specific identity drivers.
Index: tempest-12.2.1.dev177/tempest/api/identity/admin/v3/test_groups.py
===================================================================
--- tempest-12.2.1.dev177.orig/tempest/api/identity/admin/v3/test_groups.py
+++ tempest-12.2.1.dev177/tempest/api/identity/admin/v3/test_groups.py
@@ -14,9 +14,12 @@
 #    under the License.
 
 from tempest.api.identity import base
+from tempest import config
 from tempest.common.utils import data_utils
 from tempest import test
 
+CONF = config.CONF
+
 
 class GroupsV3TestJSON(base.BaseIdentityV3AdminTest):
 
@@ -137,7 +140,14 @@ class GroupsV3TestJSON(base.BaseIdentity
             self.addCleanup(self.groups_client.delete_group, group['id'])
             group_ids.append(group['id'])
         # List and Verify Groups
-        body = self.groups_client.list_groups()['groups']
+        # When domain specific drivers are enabled the operations
+        # of listing all users and listing all groups are not supported,
+        # they need a domain filter to be specified
+        if CONF.identity_feature_enabled.domain_specific_drivers:
+            body = self.groups_client.list_groups(
+                domain_id=self.domain['id'])['groups']
+        else:
+            body = self.groups_client.list_groups()['groups']
         for g in body:
             fetched_ids.append(g['id'])
         missing_groups = [g for g in group_ids if g not in fetched_ids]
Index: tempest-12.2.1.dev177/tempest/api/identity/admin/v3/test_list_users.py
===================================================================
--- tempest-12.2.1.dev177.orig/tempest/api/identity/admin/v3/test_list_users.py
+++ tempest-12.2.1.dev177/tempest/api/identity/admin/v3/test_list_users.py
@@ -14,9 +14,12 @@
 #    under the License.
 
 from tempest.api.identity import base
+from tempest import config
 from tempest.common.utils import data_utils
 from tempest import test
 
+CONF = config.CONF
+
 
 class UsersV3TestJSON(base.BaseIdentityV3AdminTest):
 
@@ -82,6 +85,11 @@ class UsersV3TestJSON(base.BaseIdentityV
     def test_list_users_with_name(self):
         # List users with name
         params = {'name': self.domain_enabled_user['name']}
+        # When domain specific drivers are enabled the operations
+        # of listing all users and listing all groups are not supported,
+        # they need a domain filter to be specified
+        if CONF.identity_feature_enabled.domain_specific_drivers:
+            params['domain_id'] = self.domain_enabled_user['domain_id']
         self._list_users_with_params(params, 'name',
                                      self.domain_enabled_user,
                                      self.non_domain_enabled_user)
@@ -89,7 +97,18 @@ class UsersV3TestJSON(base.BaseIdentityV
     @test.idempotent_id('b30d4651-a2ea-4666-8551-0c0e49692635')
     def test_list_users(self):
         # List users
-        body = self.users_client.list_users()['users']
+        # When domain specific drivers are enabled the operations
+        # of listing all users and listing all groups are not supported,
+        # they need a domain filter to be specified
+        if CONF.identity_feature_enabled.domain_specific_drivers:
+            body_enabled_user = self.users_client.list_users(
+                domain_id=self.domain_enabled_user['domain_id'])['users']
+            body_non_enabled_user = self.users_client.list_users(
+                domain_id=self.non_domain_enabled_user['domain_id'])['users']
+            body = (body_enabled_user + body_non_enabled_user)
+        else:
+            body = self.users_client.list_users()['users']
+
         fetched_ids = [u['id'] for u in body]
         missing_users = [u['id'] for u in self.users
                          if u['id'] not in fetched_ids]
Index: tempest-12.2.1.dev177/tempest/config.py
===================================================================
--- tempest-12.2.1.dev177.orig/tempest/config.py
+++ tempest-12.2.1.dev177/tempest/config.py
@@ -202,6 +202,12 @@ IdentityFeatureGroup = [
     cfg.BoolOpt('api_v3',
                 default=True,
                 help='Is the v3 identity API enabled'),
+    cfg.BoolOpt('domain_specific_drivers',
+                default=False,
+                help='Are domain specific drivers enabled? '
+                     'This configuration value should be same as '
+                     '[identity]->domain_specific_drivers_enabled '
+                     'in keystone.conf.'),
     cfg.ListOpt('api_extensions',
                 default=['all'],
                 help="A list of enabled identity extensions with a special "
