Split domains_client from keystone V3 client

Partially implements blueprint consistent-service-method-names

Change-Id: I52bebd667f21adddaf41b6159d9b0d0dc9753db6
diff --git a/tempest/api/identity/admin/v3/test_default_project_id.py b/tempest/api/identity/admin/v3/test_default_project_id.py
index 3dc3cb6..b2bef6e 100644
--- a/tempest/api/identity/admin/v3/test_default_project_id.py
+++ b/tempest/api/identity/admin/v3/test_default_project_id.py
@@ -32,14 +32,14 @@
     def _delete_domain(self, domain_id):
         # It is necessary to disable the domain before deleting,
         # or else it would result in unauthorized error
-        self.client.update_domain(domain_id, enabled=False)
-        self.client.delete_domain(domain_id)
+        self.domains_client.update_domain(domain_id, enabled=False)
+        self.domains_client.delete_domain(domain_id)
 
     @test.idempotent_id('d6110661-6a71-49a7-a453-b5e26640ff6d')
     def test_default_project_id(self):
         # create a domain
         dom_name = data_utils.rand_name('dom')
-        domain_body = self.client.create_domain(dom_name)['domain']
+        domain_body = self.domains_client.create_domain(dom_name)['domain']
         dom_id = domain_body['id']
         self.addCleanup(self._delete_domain, dom_id)
 
diff --git a/tempest/api/identity/admin/v3/test_domains.py b/tempest/api/identity/admin/v3/test_domains.py
index 1729dc9..27ff15d 100644
--- a/tempest/api/identity/admin/v3/test_domains.py
+++ b/tempest/api/identity/admin/v3/test_domains.py
@@ -26,11 +26,11 @@
     def _delete_domain(self, domain_id):
         # It is necessary to disable the domain before deleting,
         # or else it would result in unauthorized error
-        self.client.update_domain(domain_id, enabled=False)
-        self.client.delete_domain(domain_id)
+        self.domains_client.update_domain(domain_id, enabled=False)
+        self.domains_client.delete_domain(domain_id)
         # Asserting that the domain is not found in the list
         # after deletion
-        body = self.client.list_domains()['domains']
+        body = self.domains_client.list_domains()['domains']
         domains_list = [d['id'] for d in body]
         self.assertNotIn(domain_id, domains_list)
 
@@ -40,14 +40,14 @@
         domain_ids = list()
         fetched_ids = list()
         for _ in range(3):
-            domain = self.client.create_domain(
+            domain = self.domains_client.create_domain(
                 data_utils.rand_name('domain'),
                 description=data_utils.rand_name('domain-desc'))['domain']
             # Delete the domain at the end of this method
             self.addCleanup(self._delete_domain, domain['id'])
             domain_ids.append(domain['id'])
         # List and Verify Domains
-        body = self.client.list_domains()['domains']
+        body = self.domains_client.list_domains()['domains']
         for d in body:
             fetched_ids.append(d['id'])
         missing_doms = [d for d in domain_ids if d not in fetched_ids]
@@ -58,7 +58,7 @@
     def test_create_update_delete_domain(self):
         d_name = data_utils.rand_name('domain')
         d_desc = data_utils.rand_name('domain-desc')
-        domain = self.client.create_domain(
+        domain = self.domains_client.create_domain(
             d_name, description=d_desc)['domain']
         self.addCleanup(self._delete_domain, domain['id'])
         self.assertIn('id', domain)
@@ -73,7 +73,7 @@
         new_desc = data_utils.rand_name('new-desc')
         new_name = data_utils.rand_name('new-name')
 
-        updated_domain = self.client.update_domain(
+        updated_domain = self.domains_client.update_domain(
             domain['id'], name=new_name, description=new_desc)['domain']
         self.assertIn('id', updated_domain)
         self.assertIn('description', updated_domain)
@@ -85,7 +85,8 @@
         self.assertEqual(new_desc, updated_domain['description'])
         self.assertEqual(True, updated_domain['enabled'])
 
-        fetched_domain = self.client.show_domain(domain['id'])['domain']
+        fetched_domain = self.domains_client.show_domain(
+            domain['id'])['domain']
         self.assertEqual(new_name, fetched_domain['name'])
         self.assertEqual(new_desc, fetched_domain['description'])
         self.assertEqual(True, fetched_domain['enabled'])
@@ -95,9 +96,9 @@
         # Create domain with enabled status as false
         d_name = data_utils.rand_name('domain')
         d_desc = data_utils.rand_name('domain-desc')
-        domain = self.client.create_domain(
+        domain = self.domains_client.create_domain(
             d_name, description=d_desc, enabled=False)['domain']
-        self.addCleanup(self.client.delete_domain, domain['id'])
+        self.addCleanup(self.domains_client.delete_domain, domain['id'])
         self.assertEqual(d_name, domain['name'])
         self.assertFalse(domain['enabled'])
         self.assertEqual(d_desc, domain['description'])
@@ -106,7 +107,7 @@
     def test_create_domain_without_description(self):
         # Create domain only with name
         d_name = data_utils.rand_name('domain')
-        domain = self.client.create_domain(d_name)['domain']
+        domain = self.domains_client.create_domain(d_name)['domain']
         self.addCleanup(self._delete_domain, domain['id'])
         self.assertIn('id', domain)
         expected_data = {'name': d_name, 'enabled': True}
@@ -124,6 +125,6 @@
     @test.attr(type='smoke')
     @test.idempotent_id('17a5de24-e6a0-4e4a-a9ee-d85b6e5612b5')
     def test_default_domain_exists(self):
-        domain = self.client.show_domain(self.domain_id)['domain']
+        domain = self.domains_client.show_domain(self.domain_id)['domain']
 
         self.assertTrue(domain['enabled'])
diff --git a/tempest/api/identity/admin/v3/test_domains_negative.py b/tempest/api/identity/admin/v3/test_domains_negative.py
index 9eb3149..253aeca 100644
--- a/tempest/api/identity/admin/v3/test_domains_negative.py
+++ b/tempest/api/identity/admin/v3/test_domains_negative.py
@@ -28,45 +28,46 @@
     def test_delete_active_domain(self):
         d_name = data_utils.rand_name('domain')
         d_desc = data_utils.rand_name('domain-desc')
-        domain = self.client.create_domain(d_name,
-                                           description=d_desc)['domain']
+        domain = self.domains_client.create_domain(
+            d_name,
+            description=d_desc)['domain']
         domain_id = domain['id']
 
         self.addCleanup(self.delete_domain, domain_id)
 
         # domain need to be disabled before deleting
-        self.assertRaises(lib_exc.Forbidden, self.client.delete_domain,
+        self.assertRaises(lib_exc.Forbidden, self.domains_client.delete_domain,
                           domain_id)
 
     @test.attr(type=['negative'])
     @test.idempotent_id('9018461d-7d24-408d-b3fe-ae37e8cd5c9e')
     def test_create_domain_with_empty_name(self):
         # Domain name should not be empty
-        self.assertRaises(lib_exc.BadRequest, self.client.create_domain,
-                          name='')
+        self.assertRaises(lib_exc.BadRequest,
+                          self.domains_client.create_domain, name='')
 
     @test.attr(type=['negative'])
     @test.idempotent_id('37b1bbf2-d664-4785-9a11-333438586eae')
     def test_create_domain_with_name_length_over_64(self):
         # Domain name length should not ne greater than 64 characters
         d_name = 'a' * 65
-        self.assertRaises(lib_exc.BadRequest, self.client.create_domain,
-                          d_name)
+        self.assertRaises(lib_exc.BadRequest,
+                          self.domains_client.create_domain, d_name)
 
     @test.attr(type=['negative'])
     @test.idempotent_id('43781c07-764f-4cf2-a405-953c1916f605')
     def test_delete_non_existent_domain(self):
         # Attempt to delete a non existent domain should fail
-        self.assertRaises(lib_exc.NotFound, self.client.delete_domain,
+        self.assertRaises(lib_exc.NotFound, self.domains_client.delete_domain,
                           data_utils.rand_uuid_hex())
 
     @test.attr(type=['negative'])
     @test.idempotent_id('e6f9e4a2-4f36-4be8-bdbc-4e199ae29427')
     def test_domain_create_duplicate(self):
         domain_name = data_utils.rand_name('domain-dup')
-        domain = self.client.create_domain(domain_name)['domain']
+        domain = self.domains_client.create_domain(domain_name)['domain']
         domain_id = domain['id']
         self.addCleanup(self.delete_domain, domain_id)
         # Domain name should be unique
         self.assertRaises(
-            lib_exc.Conflict, self.client.create_domain, domain_name)
+            lib_exc.Conflict, self.domains_client.create_domain, domain_name)
diff --git a/tempest/api/identity/admin/v3/test_roles.py b/tempest/api/identity/admin/v3/test_roles.py
index 468f169..a0a842c 100644
--- a/tempest/api/identity/admin/v3/test_roles.py
+++ b/tempest/api/identity/admin/v3/test_roles.py
@@ -32,7 +32,7 @@
         u_desc = '%s description' % u_name
         u_email = '%s@testmail.tm' % u_name
         cls.u_password = data_utils.rand_password()
-        cls.domain = cls.client.create_domain(
+        cls.domain = cls.domains_client.create_domain(
             data_utils.rand_name('domain'),
             description=data_utils.rand_name('domain-desc'))['domain']
         cls.project = cls.projects_client.create_project(
@@ -57,8 +57,8 @@
         cls.projects_client.delete_project(cls.project['id'])
         # NOTE(harika-vakadi): It is necessary to disable the domain
         # before deleting,or else it would result in unauthorized error
-        cls.client.update_domain(cls.domain['id'], enabled=False)
-        cls.client.delete_domain(cls.domain['id'])
+        cls.domains_client.update_domain(cls.domain['id'], enabled=False)
+        cls.domains_client.delete_domain(cls.domain['id'])
         super(RolesV3TestJSON, cls).resource_cleanup()
 
     def _list_assertions(self, body, fetched_role_ids, role_id):
diff --git a/tempest/api/identity/base.py b/tempest/api/identity/base.py
index 1025de7..5ba0fcb 100644
--- a/tempest/api/identity/base.py
+++ b/tempest/api/identity/base.py
@@ -146,6 +146,7 @@
     def setup_clients(cls):
         super(BaseIdentityV3AdminTest, cls).setup_clients()
         cls.client = cls.os_adm.identity_v3_client
+        cls.domains_client = cls.os_adm.domains_client
         cls.users_client = cls.os_adm.users_v3_client
         cls.token = cls.os_adm.token_v3_client
         cls.endpoints_client = cls.os_adm.endpoints_client
@@ -160,7 +161,7 @@
     def resource_setup(cls):
         super(BaseIdentityV3AdminTest, cls).resource_setup()
         cls.data = DataGeneratorV3(cls.client, cls.projects_client,
-                                   cls.users_client)
+                                   cls.users_client, None, cls.domains_client)
 
     @classmethod
     def resource_cleanup(cls):
@@ -182,18 +183,19 @@
     def delete_domain(self, domain_id):
         # NOTE(mpavlase) It is necessary to disable the domain before deleting
         # otherwise it raises Forbidden exception
-        self.client.update_domain(domain_id, enabled=False)
-        self.client.delete_domain(domain_id)
+        self.domains_client.update_domain(domain_id, enabled=False)
+        self.domains_client.delete_domain(domain_id)
 
 
 class BaseDataGenerator(object):
 
     def __init__(self, client, projects_client,
-                 users_client, roles_client=None):
+                 users_client, roles_client=None, domains_client=None):
         self.client = client
         self.projects_client = projects_client
         self.users_client = users_client
         self.roles_client = roles_client or client
+        self.domains_client = domains_client
 
         self.user_password = None
         self.user = None
@@ -242,8 +244,9 @@
         for role in self.roles:
             self._try_wrapper(self.roles_client.delete_role, role)
         for domain in self.domains:
-            self._try_wrapper(self.client.update_domain, domain, enabled=False)
-            self._try_wrapper(self.client.delete_domain, domain)
+            self._try_wrapper(self.domains_client.update_domain, domain,
+                              enabled=False)
+            self._try_wrapper(self.domains_client.delete_domain, domain)
 
 
 class DataGeneratorV2(BaseDataGenerator):
@@ -277,7 +280,7 @@
 
     def setup_test_domain(self):
         """Set up a test domain."""
-        self.domain = self.client.create_domain(
+        self.domain = self.domains_client.create_domain(
             name=data_utils.rand_name('test_domain'),
             description=data_utils.rand_name('desc'))['domain']
         self.domains.append(self.domain)
diff --git a/tempest/clients.py b/tempest/clients.py
index 2a8a4ae..1e4522e 100644
--- a/tempest/clients.py
+++ b/tempest/clients.py
@@ -117,6 +117,7 @@
     UsersClient
 from tempest.services.identity.v3.json.credentials_client import \
     CredentialsClient as CredentialsV3Client
+from tempest.services.identity.v3.json.domains_client import DomainsClient
 from tempest.services.identity.v3.json.endpoints_client import \
     EndPointClient as EndPointV3Client
 from tempest.services.identity.v3.json.groups_client import \
@@ -527,6 +528,8 @@
         # Clients below use the endpoint type of Keystone API v3
         params_v3 = params.copy()
         params_v3['endpoint_type'] = CONF.identity.v3_endpoint_type
+        self.domains_client = DomainsClient(self.auth_provider,
+                                            **params_v3)
         self.identity_v3_client = IdentityV3Client(self.auth_provider,
                                                    **params_v3)
         self.users_v3_client = UsersV3Client(self.auth_provider, **params_v3)
diff --git a/tempest/cmd/cleanup_service.py b/tempest/cmd/cleanup_service.py
index 33f19b1..6f395fc 100644
--- a/tempest/cmd/cleanup_service.py
+++ b/tempest/cmd/cleanup_service.py
@@ -940,7 +940,7 @@
 
     def __init__(self, manager, **kwargs):
         super(DomainService, self).__init__(kwargs)
-        self.client = manager.identity_v3_client
+        self.client = manager.domains_client
 
     def list(self):
         client = self.client
diff --git a/tempest/common/cred_client.py b/tempest/common/cred_client.py
index 5aa794c..494bcee 100644
--- a/tempest/common/cred_client.py
+++ b/tempest/common/cred_client.py
@@ -130,13 +130,15 @@
 class V3CredsClient(CredsClient):
 
     def __init__(self, identity_client, projects_client, users_client,
-                 domain_name):
-        super(V3CredsClient, self).__init__(identity_client,
-                                            projects_client, users_client)
+                 domains_client, domain_name):
+        super(V3CredsClient, self).__init__(identity_client, projects_client,
+                                            users_client)
+        self.domains_client = domains_client
+
         try:
             # Domain names must be unique, in any case a list is returned,
             # selecting the first (and only) element
-            self.creds_domain = self.identity_client.list_domains(
+            self.creds_domain = self.domains_client.list_domains(
                 params={'name': domain_name})['domains'][0]
         except lib_exc.NotFound:
             # TODO(andrea) we could probably create the domain on the fly
@@ -179,10 +181,11 @@
                      projects_client,
                      users_client,
                      roles_client=None,
+                     domains_client=None,
                      project_domain_name=None):
     if isinstance(identity_client, v2_identity.IdentityClient):
         return V2CredsClient(identity_client, projects_client, users_client,
                              roles_client)
     else:
         return V3CredsClient(identity_client, projects_client, users_client,
-                             project_domain_name)
+                             domains_client, project_domain_name)
diff --git a/tempest/common/dynamic_creds.py b/tempest/common/dynamic_creds.py
index 1810c57..a758a32 100644
--- a/tempest/common/dynamic_creds.py
+++ b/tempest/common/dynamic_creds.py
@@ -61,6 +61,7 @@
          self.tenants_admin_client,
          self.users_admin_client,
          self.roles_admin_client,
+         self.domains_admin_client,
          self.network_admin_client,
          self.networks_admin_client,
          self.subnets_admin_client,
@@ -78,6 +79,7 @@
             self.tenants_admin_client,
             self.users_admin_client,
             self.roles_admin_client,
+            self.domains_admin_client,
             self.creds_domain_name)
 
     def _get_admin_clients(self):
@@ -90,14 +92,14 @@
         os = clients.Manager(self.default_admin_creds)
         if self.identity_version == 'v2':
             return (os.identity_client, os.tenants_client, os.users_client,
-                    os.roles_client, os.network_client, os.networks_client,
-                    os.subnets_client, os.ports_client,
+                    os.roles_client, None, os.network_client,
+                    os.networks_client, os.subnets_client, os.ports_client,
                     os.security_groups_client)
         else:
             return (os.identity_v3_client, os.projects_client,
-                    os.users_v3_client, None, os.network_client,
-                    os.networks_client, os.subnets_client, os.ports_client,
-                    os.security_groups_client)
+                    os.users_v3_client, None, os.domains_client,
+                    os.network_client, os.networks_client, os.subnets_client,
+                    os.ports_client, os.security_groups_client)
 
     def _create_creds(self, suffix="", admin=False, roles=None):
         """Create random credentials under the following schema.
diff --git a/tempest/services/identity/v3/json/domains_client.py b/tempest/services/identity/v3/json/domains_client.py
new file mode 100644
index 0000000..626a474
--- /dev/null
+++ b/tempest/services/identity/v3/json/domains_client.py
@@ -0,0 +1,77 @@
+# Copyright 2016 Red Hat, Inc.
+#
+# 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 oslo_serialization import jsonutils as json
+from six.moves.urllib import parse as urllib
+
+from tempest.common import service_client
+
+
+class DomainsClient(service_client.ServiceClient):
+    api_version = "v3"
+
+    def create_domain(self, name, **kwargs):
+        """Creates a domain."""
+        description = kwargs.get('description', None)
+        en = kwargs.get('enabled', True)
+        post_body = {
+            'description': description,
+            'enabled': en,
+            'name': name
+        }
+        post_body = json.dumps({'domain': post_body})
+        resp, body = self.post('domains', post_body)
+        self.expected_success(201, resp.status)
+        body = json.loads(body)
+        return service_client.ResponseBody(resp, body)
+
+    def delete_domain(self, domain_id):
+        """Deletes a domain."""
+        resp, body = self.delete('domains/%s' % str(domain_id))
+        self.expected_success(204, resp.status)
+        return service_client.ResponseBody(resp, body)
+
+    def list_domains(self, params=None):
+        """List Domains."""
+        url = 'domains'
+        if params:
+            url += '?%s' % urllib.urlencode(params)
+        resp, body = self.get(url)
+        self.expected_success(200, resp.status)
+        body = json.loads(body)
+        return service_client.ResponseBody(resp, body)
+
+    def update_domain(self, domain_id, **kwargs):
+        """Updates a domain."""
+        body = self.show_domain(domain_id)['domain']
+        description = kwargs.get('description', body['description'])
+        en = kwargs.get('enabled', body['enabled'])
+        name = kwargs.get('name', body['name'])
+        post_body = {
+            'description': description,
+            'enabled': en,
+            'name': name
+        }
+        post_body = json.dumps({'domain': post_body})
+        resp, body = self.patch('domains/%s' % domain_id, post_body)
+        self.expected_success(200, resp.status)
+        body = json.loads(body)
+        return service_client.ResponseBody(resp, body)
+
+    def show_domain(self, domain_id):
+        """Get Domain details."""
+        resp, body = self.get('domains/%s' % domain_id)
+        self.expected_success(200, resp.status)
+        body = json.loads(body)
+        return service_client.ResponseBody(resp, body)
diff --git a/tempest/services/identity/v3/json/identity_client.py b/tempest/services/identity/v3/json/identity_client.py
index 809d0b5..8cd8dca 100644
--- a/tempest/services/identity/v3/json/identity_client.py
+++ b/tempest/services/identity/v3/json/identity_client.py
@@ -14,7 +14,6 @@
 #    under the License.
 
 from oslo_serialization import jsonutils as json
-from six.moves.urllib import parse as urllib
 
 from tempest.common import service_client
 
@@ -74,61 +73,6 @@
         self.expected_success(204, resp.status)
         return service_client.ResponseBody(resp, body)
 
-    def create_domain(self, name, **kwargs):
-        """Creates a domain."""
-        description = kwargs.get('description', None)
-        en = kwargs.get('enabled', True)
-        post_body = {
-            'description': description,
-            'enabled': en,
-            'name': name
-        }
-        post_body = json.dumps({'domain': post_body})
-        resp, body = self.post('domains', post_body)
-        self.expected_success(201, resp.status)
-        body = json.loads(body)
-        return service_client.ResponseBody(resp, body)
-
-    def delete_domain(self, domain_id):
-        """Delete a domain."""
-        resp, body = self.delete('domains/%s' % str(domain_id))
-        self.expected_success(204, resp.status)
-        return service_client.ResponseBody(resp, body)
-
-    def list_domains(self, params=None):
-        """List Domains."""
-        url = 'domains'
-        if params:
-            url += '?%s' % urllib.urlencode(params)
-        resp, body = self.get(url)
-        self.expected_success(200, resp.status)
-        body = json.loads(body)
-        return service_client.ResponseBody(resp, body)
-
-    def update_domain(self, domain_id, **kwargs):
-        """Updates a domain."""
-        body = self.show_domain(domain_id)['domain']
-        description = kwargs.get('description', body['description'])
-        en = kwargs.get('enabled', body['enabled'])
-        name = kwargs.get('name', body['name'])
-        post_body = {
-            'description': description,
-            'enabled': en,
-            'name': name
-        }
-        post_body = json.dumps({'domain': post_body})
-        resp, body = self.patch('domains/%s' % domain_id, post_body)
-        self.expected_success(200, resp.status)
-        body = json.loads(body)
-        return service_client.ResponseBody(resp, body)
-
-    def show_domain(self, domain_id):
-        """Get Domain details."""
-        resp, body = self.get('domains/%s' % domain_id)
-        self.expected_success(200, resp.status)
-        body = json.loads(body)
-        return service_client.ResponseBody(resp, body)
-
     def show_token(self, resp_token):
         """Get token details."""
         headers = {'X-Subject-Token': resp_token}
diff --git a/tempest/stress/driver.py b/tempest/stress/driver.py
index 3c69a8b..2ebb11d 100644
--- a/tempest/stress/driver.py
+++ b/tempest/stress/driver.py
@@ -149,16 +149,18 @@
                     projects_client = admin_manager.tenants_client
                     roles_client = admin_manager.roles_client
                     users_client = admin_manager.users_client
+                    domains_client = None
                 else:
                     identity_client = admin_manager.identity_v3_client
                     projects_client = admin_manager.projects_client
                     roles_client = None
                     users_client = admin_manager.users_v3_client
+                    domains_client = admin_manager.domains_client
                 domain = (identity_client.auth_provider.credentials.
                           get('project_domain_name', 'Default'))
                 credentials_client = cred_client.get_creds_client(
                     identity_client, projects_client, users_client,
-                    roles_client, project_domain_name=domain)
+                    roles_client, domains_client, project_domain_name=domain)
                 project = credentials_client.create_project(
                     name=tenant_name, description=tenant_name)
                 user = credentials_client.create_user(username, password,
diff --git a/tempest/test.py b/tempest/test.py
index ee3288c..9dbcb68 100644
--- a/tempest/test.py
+++ b/tempest/test.py
@@ -443,11 +443,13 @@
             users_client = self.os_admin.users_client
             project_client = self.os_admin.tenants_client
             roles_client = self.os_admin.roles_client
+            domains_client = None
         else:
             client = self.os_admin.identity_v3_client
             project_client = self.os_adm.projects_client
             users_client = self.os_admin.users_v3_client
             roles_client = None
+            domains_client = self.os_admin.domains_client
 
         try:
             domain = client.auth_provider.credentials.project_domain_name
@@ -457,6 +459,7 @@
         return cred_client.get_creds_client(client, project_client,
                                             users_client,
                                             roles_client,
+                                            domains_client,
                                             project_domain_name=domain)
 
     @classmethod