Merge "Make v2,v3 create_role use **kwargs & doc string"
diff --git a/tempest/api/identity/admin/v2/test_roles.py b/tempest/api/identity/admin/v2/test_roles.py
index e547bdd..3f3d16e 100644
--- a/tempest/api/identity/admin/v2/test_roles.py
+++ b/tempest/api/identity/admin/v2/test_roles.py
@@ -27,7 +27,7 @@
         super(RolesTestJSON, cls).resource_setup()
         for _ in moves.xrange(5):
             role_name = data_utils.rand_name(name='role')
-            role = cls.roles_client.create_role(role_name)['role']
+            role = cls.roles_client.create_role(name=role_name)['role']
             cls.data.roles.append(role)
 
     def _get_role_params(self):
@@ -57,7 +57,7 @@
     def test_role_create_delete(self):
         """Role should be created, verified, and deleted."""
         role_name = data_utils.rand_name(name='role-test')
-        body = self.roles_client.create_role(role_name)['role']
+        body = self.roles_client.create_role(name=role_name)['role']
         self.assertEqual(role_name, body['name'])
 
         body = self.roles_client.list_roles()['roles']
diff --git a/tempest/api/identity/admin/v2/test_roles_negative.py b/tempest/api/identity/admin/v2/test_roles_negative.py
index a57163d..c9af7c6 100644
--- a/tempest/api/identity/admin/v2/test_roles_negative.py
+++ b/tempest/api/identity/admin/v2/test_roles_negative.py
@@ -53,7 +53,7 @@
     def test_role_create_blank_name(self):
         # Should not be able to create a role with a blank name
         self.assertRaises(lib_exc.BadRequest, self.roles_client.create_role,
-                          '')
+                          name='')
 
     @test.attr(type=['negative'])
     @test.idempotent_id('585c8998-a8a4-4641-a5dd-abef7a8ced00')
@@ -61,7 +61,8 @@
         # Non-administrator user should not be able to create role
         role_name = data_utils.rand_name(name='role')
         self.assertRaises(lib_exc.Forbidden,
-                          self.non_admin_roles_client.create_role, role_name)
+                          self.non_admin_roles_client.create_role,
+                          name=role_name)
 
     @test.attr(type=['negative'])
     @test.idempotent_id('a7edd17a-e34a-4aab-8bb7-fa6f498645b8')
@@ -71,7 +72,7 @@
         self.client.delete_token(token)
         role_name = data_utils.rand_name(name='role')
         self.assertRaises(lib_exc.Unauthorized,
-                          self.roles_client.create_role, role_name)
+                          self.roles_client.create_role, name=role_name)
         self.client.auth_provider.clear_auth()
 
     @test.attr(type=['negative'])
@@ -79,18 +80,18 @@
     def test_role_create_duplicate(self):
         # Role names should be unique
         role_name = data_utils.rand_name(name='role-dup')
-        body = self.roles_client.create_role(role_name)['role']
+        body = self.roles_client.create_role(name=role_name)['role']
         role1_id = body.get('id')
         self.addCleanup(self.roles_client.delete_role, role1_id)
         self.assertRaises(lib_exc.Conflict, self.roles_client.create_role,
-                          role_name)
+                          name=role_name)
 
     @test.attr(type=['negative'])
     @test.idempotent_id('15347635-b5b1-4a87-a280-deb2bd6d865e')
     def test_delete_role_by_unauthorized_user(self):
         # Non-administrator user should not be able to delete role
         role_name = data_utils.rand_name(name='role')
-        body = self.roles_client.create_role(role_name)['role']
+        body = self.roles_client.create_role(name=role_name)['role']
         self.data.roles.append(body)
         role_id = body.get('id')
         self.assertRaises(lib_exc.Forbidden,
@@ -101,7 +102,7 @@
     def test_delete_role_request_without_token(self):
         # Request to delete role without a valid token should fail
         role_name = data_utils.rand_name(name='role')
-        body = self.roles_client.create_role(role_name)['role']
+        body = self.roles_client.create_role(name=role_name)['role']
         self.data.roles.append(body)
         role_id = body.get('id')
         token = self.client.auth_provider.get_token()
diff --git a/tempest/api/identity/admin/v2/test_tokens.py b/tempest/api/identity/admin/v2/test_tokens.py
index e752b02..fdb5a5a 100644
--- a/tempest/api/identity/admin/v2/test_tokens.py
+++ b/tempest/api/identity/admin/v2/test_tokens.py
@@ -77,7 +77,7 @@
 
         # Create a role
         role_name = data_utils.rand_name(name='role')
-        role = self.roles_client.create_role(role_name)['role']
+        role = self.roles_client.create_role(name=role_name)['role']
         self.data.roles.append(role)
 
         # Grant the user the role on the tenants.
diff --git a/tempest/api/identity/admin/v3/test_roles.py b/tempest/api/identity/admin/v3/test_roles.py
index f194d9c..8f48704 100644
--- a/tempest/api/identity/admin/v3/test_roles.py
+++ b/tempest/api/identity/admin/v3/test_roles.py
@@ -25,7 +25,7 @@
         super(RolesV3TestJSON, cls).resource_setup()
         for _ in range(3):
             role_name = data_utils.rand_name(name='role')
-            role = cls.client.create_role(role_name)['role']
+            role = cls.client.create_role(name=role_name)['role']
             cls.data.v3_roles.append(role)
         cls.fetched_role_ids = list()
         u_name = data_utils.rand_name('user')
@@ -47,7 +47,7 @@
             email=u_email, project_id=cls.project['id'],
             domain_id=cls.domain['id'])['user']
         cls.role = cls.client.create_role(
-            data_utils.rand_name('Role'))['role']
+            name=data_utils.rand_name('Role'))['role']
 
     @classmethod
     def resource_cleanup(cls):
@@ -69,7 +69,7 @@
     @test.idempotent_id('18afc6c0-46cf-4911-824e-9989cc056c3a')
     def test_role_create_update_get_list(self):
         r_name = data_utils.rand_name('Role')
-        role = self.client.create_role(r_name)['role']
+        role = self.client.create_role(name=r_name)['role']
         self.addCleanup(self.client.delete_role, role['id'])
         self.assertIn('name', role)
         self.assertEqual(role['name'], r_name)
diff --git a/tempest/api/identity/admin/v3/test_tokens.py b/tempest/api/identity/admin/v3/test_tokens.py
index f5b20d5..b1446cf 100644
--- a/tempest/api/identity/admin/v3/test_tokens.py
+++ b/tempest/api/identity/admin/v3/test_tokens.py
@@ -76,7 +76,7 @@
 
         # Create a role
         role_name = data_utils.rand_name(name='role')
-        role = self.client.create_role(role_name)['role']
+        role = self.client.create_role(name=role_name)['role']
         self.addCleanup(self.client.delete_role, role['id'])
 
         # Grant the user the role on both projects.
diff --git a/tempest/api/identity/admin/v3/test_trusts.py b/tempest/api/identity/admin/v3/test_trusts.py
index bf7ad71..85961b4 100644
--- a/tempest/api/identity/admin/v3/test_trusts.py
+++ b/tempest/api/identity/admin/v3/test_trusts.py
@@ -69,10 +69,10 @@
         self.delegated_role = data_utils.rand_name('DelegatedRole')
         self.not_delegated_role = data_utils.rand_name('NotDelegatedRole')
 
-        role = self.client.create_role(self.delegated_role)['role']
+        role = self.client.create_role(name=self.delegated_role)['role']
         self.delegated_role_id = role['id']
 
-        role = self.client.create_role(self.not_delegated_role)['role']
+        role = self.client.create_role(name=self.not_delegated_role)['role']
         self.not_delegated_role_id = role['id']
 
         # Assign roles to trustor
diff --git a/tempest/api/identity/admin/v3/test_users.py b/tempest/api/identity/admin/v3/test_users.py
index 6dbd443..a402b3f 100644
--- a/tempest/api/identity/admin/v3/test_users.py
+++ b/tempest/api/identity/admin/v3/test_users.py
@@ -117,7 +117,7 @@
         self.addCleanup(self.client.delete_user, user_body['id'])
         # Creating Role
         role_body = self.client.create_role(
-            data_utils.rand_name('role'))['role']
+            name=data_utils.rand_name('role'))['role']
         # Delete the Role at the end of this method
         self.addCleanup(self.client.delete_role, role_body['id'])
 
diff --git a/tempest/api/identity/base.py b/tempest/api/identity/base.py
index 05d1fab..c6d1ac7 100644
--- a/tempest/api/identity/base.py
+++ b/tempest/api/identity/base.py
@@ -237,7 +237,8 @@
         def setup_test_role(self):
             """Set up a test role."""
             self.test_role = data_utils.rand_name('role')
-            self.role = self.roles_client.create_role(self.test_role)['role']
+            self.role = self.roles_client.create_role(
+                name=self.test_role)['role']
             self.roles.append(self.role)
 
         def setup_test_v3_user(self):
@@ -265,7 +266,7 @@
         def setup_test_v3_role(self):
             """Set up a test v3 role."""
             self.test_role = data_utils.rand_name('role')
-            self.v3_role = self.client.create_role(self.test_role)['role']
+            self.v3_role = self.client.create_role(name=self.test_role)['role']
             self.v3_roles.append(self.v3_role)
 
         def setup_test_domain(self):
diff --git a/tempest/common/cred_client.py b/tempest/common/cred_client.py
index a33732e..5d15988 100644
--- a/tempest/common/cred_client.py
+++ b/tempest/common/cred_client.py
@@ -61,7 +61,7 @@
 
     def create_user_role(self, role_name):
         if not self._check_role_exists(role_name):
-            self.roles_client.create_role(role_name)
+            self.roles_client.create_role(name=role_name)
 
     def assign_user_role(self, user, project, role_name):
         role = self._check_role_exists(role_name)
diff --git a/tempest/services/identity/v2/json/roles_client.py b/tempest/services/identity/v2/json/roles_client.py
index de8f9cb..ef6dfe9 100644
--- a/tempest/services/identity/v2/json/roles_client.py
+++ b/tempest/services/identity/v2/json/roles_client.py
@@ -18,12 +18,13 @@
 class RolesClient(service_client.ServiceClient):
     api_version = "v2.0"
 
-    def create_role(self, name):
-        """Create a role."""
-        post_body = {
-            'name': name,
-        }
-        post_body = json.dumps({'role': post_body})
+    def create_role(self, **kwargs):
+        """Create a role.
+
+        Available params: see http://developer.openstack.org/
+                              api-ref-identity-v2-ext.html#createRole
+        """
+        post_body = json.dumps({'role': kwargs})
         resp, body = self.post('OS-KSADM/roles', post_body)
         self.expected_success(200, resp.status)
         body = json.loads(body)
diff --git a/tempest/services/identity/v3/json/identity_client.py b/tempest/services/identity/v3/json/identity_client.py
index 972db99..8f2cdf2 100644
--- a/tempest/services/identity/v3/json/identity_client.py
+++ b/tempest/services/identity/v3/json/identity_client.py
@@ -180,12 +180,13 @@
         self.expected_success(204, resp.status)
         return service_client.ResponseBody(resp, body)
 
-    def create_role(self, name):
-        """Create a Role."""
-        post_body = {
-            'name': name
-        }
-        post_body = json.dumps({'role': post_body})
+    def create_role(self, **kwargs):
+        """Create a Role.
+
+        Available params: see http://developer.openstack.org/
+                              api-ref-identity-v3.html#createRole
+        """
+        post_body = json.dumps({'role': kwargs})
         resp, body = self.post('roles', post_body)
         self.expected_success(201, resp.status)
         body = json.loads(body)