create_role at keystone.logic.service calls get instead of get_by_name

Bug #910069 reported by Rafael Durán Castañeda
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
OpenStack Identity (keystone)
Fix Released
Medium
Dolph Mathews

Bug Description

Hi,

At keystone.logic.service line 892 a call to get instead of get_by_name using role.name:

        if api.ROLE.get(role.name) is not None:
            raise fault.RoleConflictFault(
                "A role with that name '" + role.name + "' already exists")

I think this error is hidden on tests by SQLite since running after applying attached patch on SQLite in memory:

OK (SKIP=3)
Slowest 5 tests took 9.26 secs:
    2.52 test_authenticate_for_a_tenant_xml_on_admin_api (keystone.test.functional.test_d5_compat_calls.D5_AuthenticationTest)
    1.76 test_authenticate_for_a_tenant_xml (keystone.test.functional.test_authentication.AuthenticationUsingTokenTest)
    1.67 test_authenticate_for_a_tenant_xml_on_admin_api (keystone.test.functional.test_authentication.AuthenticationUsingTokenTest)
    1.66 test_authenticate_for_a_tenant_using_token (keystone.test.functional.test_authentication.AuthenticationUsingTokenTest)
    1.64 test_200_good_token (keystone.test.functional.test_middleware.TestQuantumMiddleware)

However after running tests unde MySQL:

======================================================================
FAIL: test_user_auth_with_role_on_tenant (keystone.test.functional.test_auth.TestServiceAuthentication)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/rafael/workspace/parallels-backend--keystone/.venv/src/keystone/keystone/test/functional/test_auth.py", line 146, in test_user_auth_with_role_on_tenant
    self.assertEqual(len(tenants), 1, tenants)
AssertionError: 2 != 1 : [{u'id': u'19', u'enabled': True, u'description': u'892a358a-1d60-451e-a2f2-a92483714886', u'name': u'5f85e86a-4dfe-4c29-82ad-7f840024ffc2'}, {u'id': u'10', u'enabled': True, u'description': u'0710fe89-516a-4c37-9589-1cbcc57b1988', u'name': u'760966b6-999a-4cf8-b48e-b9bd677ad2eb'}]

======================================================================
FAIL: test_user_auth_with_role_on_tenant_xml (keystone.test.functional.test_auth.TestServiceAuthentication)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/rafael/workspace/parallels-backend--keystone/.venv/src/keystone/keystone/test/functional/test_auth.py", line 218, in test_user_auth_with_role_on_tenant_xml
    self.assertEqual(len(tenants), 1, tenants)
AssertionError: 2 != 1 : [<Element '{http://docs.openstack.org/identity/api/v2.0}tenant' at 0x39b3190>, <Element '{http://docs.openstack.org/identity/api/v2.0}tenant' at 0x39b3d10>]

======================================================================
FAIL: test_get_role_bad (keystone.test.functional.test_roles.GetRoleTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/rafael/workspace/parallels-backend--keystone/.venv/src/keystone/keystone/test/functional/test_roles.py", line 198, in test_get_role_bad
    self.fetch_role(common.unique_str(), assert_status=404)
  File "/home/rafael/workspace/parallels-backend--keystone/.venv/src/keystone/keystone/test/functional/common.py", line 867, in fetch_role
    return self.get_role(role_id, **kwargs)
  File "/home/rafael/workspace/parallels-backend--keystone/.venv/src/keystone/keystone/test/functional/common.py", line 397, in get_role
    path='/OS-KSADM/roles/%s' % (role_id,), **kwargs)
  File "/home/rafael/workspace/parallels-backend--keystone/.venv/src/keystone/keystone/test/functional/common.py", line 220, in admin_request
    **kwargs)
  File "/home/rafael/workspace/parallels-backend--keystone/.venv/src/keystone/keystone/test/functional/common.py", line 135, in restful_request
    response = self.request(headers=headers, body=body, **kwargs)
  File "/home/rafael/workspace/parallels-backend--keystone/.venv/src/keystone/keystone/test/functional/common.py", line 54, in request
    self.assertResponseStatus(response, assert_status)
  File "/home/rafael/workspace/parallels-backend--keystone/.venv/src/keystone/keystone/test/functional/common.py", line 87, in assertResponseStatus
    (response.status, assert_status, response.body))
AssertionError: 200 != 404 : Status code 200 is not 404, as expected)

{"role": {"description": "e2e9453f-612e-4125-9b36-387bd4a3d880", "id": "27", "name": "67d6c2ef-06f9-4e20-a715-4ef5c3f00045"}}

======================================================================
FAIL: test_delete_tenant_not_found (keystone.test.functional.test_tenants.DeleteTenantTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/rafael/workspace/parallels-backend--keystone/.venv/src/keystone/keystone/test/functional/test_tenants.py", line 385, in test_delete_tenant_not_found
    self.remove_tenant(common.unique_str(), assert_status=404)
  File "/home/rafael/workspace/parallels-backend--keystone/.venv/src/keystone/keystone/test/functional/common.py", line 735, in remove_tenant
    return self.delete_tenant(tenant_id, **kwargs)
  File "/home/rafael/workspace/parallels-backend--keystone/.venv/src/keystone/keystone/test/functional/common.py", line 310, in delete_tenant
    path='/tenants/%s' % (tenant_id,), **kwargs)
  File "/home/rafael/workspace/parallels-backend--keystone/.venv/src/keystone/keystone/test/functional/common.py", line 220, in admin_request
    **kwargs)
  File "/home/rafael/workspace/parallels-backend--keystone/.venv/src/keystone/keystone/test/functional/common.py", line 135, in restful_request
    response = self.request(headers=headers, body=body, **kwargs)
  File "/home/rafael/workspace/parallels-backend--keystone/.venv/src/keystone/keystone/test/functional/common.py", line 54, in request
    self.assertResponseStatus(response, assert_status)
  File "/home/rafael/workspace/parallels-backend--keystone/.venv/src/keystone/keystone/test/functional/common.py", line 87, in assertResponseStatus
    (response.status, assert_status, response.body))
AssertionError: 403 != 404 : Status code 403 is not 404, as expected)

{"forbidden": {"message": "You may not delete a tenant that contains get_users", "code": "403"}}

======================================================================
FAIL: test_update_tenant_not_found (keystone.test.functional.test_tenants.UpdateTenantTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/rafael/workspace/parallels-backend--keystone/.venv/src/keystone/keystone/test/functional/test_tenants.py", line 359, in test_update_tenant_not_found
    self.update_tenant(assert_status=404)
  File "/home/rafael/workspace/parallels-backend--keystone/.venv/src/keystone/keystone/test/functional/common.py", line 724, in update_tenant
    return self.post_tenant_for_update(tenant_id, as_json=data, **kwargs)
  File "/home/rafael/workspace/parallels-backend--keystone/.venv/src/keystone/keystone/test/functional/common.py", line 294, in post_tenant_for_update
    path='/tenants/%s' % (tenant_id,), **kwargs)
  File "/home/rafael/workspace/parallels-backend--keystone/.venv/src/keystone/keystone/test/functional/common.py", line 220, in admin_request
    **kwargs)
  File "/home/rafael/workspace/parallels-backend--keystone/.venv/src/keystone/keystone/test/functional/common.py", line 135, in restful_request
    response = self.request(headers=headers, body=body, **kwargs)
  File "/home/rafael/workspace/parallels-backend--keystone/.venv/src/keystone/keystone/test/functional/common.py", line 54, in request
    self.assertResponseStatus(response, assert_status)
  File "/home/rafael/workspace/parallels-backend--keystone/.venv/src/keystone/keystone/test/functional/common.py", line 87, in assertResponseStatus
    (response.status, assert_status, response.body))
AssertionError: 400 != 404 : Status code 400 is not 404, as expected)

{"badRequest": {"message": "Expecting a unique Tenant Name", "code": "400"}}

----------------------------------------------------------------------
Ran 505 tests in 102.383s

FAILED (SKIP=3, failures=5)
Slowest 5 tests took 8.68 secs:
    1.92 test_endpoint_create_xml_using_expired_token (keystone.test.functional.test_endpoints.CreateEndpointRefsTest)
    1.75 test_authenticate_for_a_tenant_xml_on_admin_api (keystone.test.functional.test_authentication.AuthenticationUsingTokenTest)
    1.74 test_authenticate_user_wrong_xml (keystone.test.functional.test_d5_compat_calls.D5_AuthenticationTest)
    1.65 test_authenticate_for_a_tenant_xml (keystone.test.functional.test_authentication.AuthenticationUsingTokenTest)
    1.63 test_authenticate_for_a_tenant_using_token (keystone.test.functional.test_authentication.AuthenticationUsingTokenTest)

Changing debug and verbose flags to True I've noticed under MySQL some warnings due to comparing uuids and integers (names and ids):

.venv/local/lib/python2.7/site-packages/sqlalchemy/engine/default.py:330: Warning: Truncated incorrect DOUBLE value: '5c5c9204-a4f3-40f5-88d0-d4019c8dd48b'

Looking at test.functional.common I can see how optional_str lambda is used on integer ids, example at line 826:

        user_id = optional_str(user_id)
        role_id = optional_str(role_id)
        tenant_id = optional_str(tenant_id)

I'm using milestone-proposed branch but as far as I know master doesn't fix this issues, and test command was:

      python run_tests.py -O test.SQLTest

Links:
https://github.com/openstack/keystone/blob/master/keystone/logic/service.py#L892
https://github.com/openstack/keystone/blob/milestone-proposed/keystone/test/functional/common.py#L824

HTH,
Rafael from BVOX

Tags: role
Revision history for this message
Rafael Durán Castañeda (rafadurancastaneda) wrote :
Revision history for this message
Dolph Mathews (dolph) wrote :

I fixed/tested this against postgresql, in commit b1581a1852142548814d72deb0eebee238b4fdbf

You can find the recommended fix to service.py in:
https://github.com/openstack/keystone/commit/b1581a1852142548814d72deb0eebee238b4fdbf

Changed in keystone:
assignee: nobody → Dolph Mathews (dolph)
importance: Undecided → Medium
milestone: none → essex-3
status: New → Fix Released
Thierry Carrez (ttx)
Changed in keystone:
milestone: essex-3 → 2012.1
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.