Failing to update tenants (bug 953678, bug 954673)

- GET /tenants: Enabled attribute was being overridden
- "POST" /tenants/{tenant_id}: was failing to update KVS

Change-Id: Icc1efef52d35777d73e6010bdfc0409e24570aa2
This commit is contained in:
Dolph Mathews 2012-03-13 16:11:27 -05:00
parent e65a22c43a
commit dc41cb5c11
3 changed files with 46 additions and 14 deletions

View File

@ -204,11 +204,12 @@ class Identity(kvs.Base, identity.Driver):
# get the old name and delete it too
old_tenant = self.db.get('tenant-%s' % tenant_id)
new_tenant = old_tenant.copy()
new_tenant.update(tenant)
new_tenant['id'] = tenant_id
self.db.delete('tenant_name-%s' % old_tenant['name'])
self.db.set('tenant-%s' % tenant_id, new_tenant)
self.db.set('tenant_name-%s' % new_tenant['name'], new_tenant)
return tenant
return new_tenant
def delete_tenant(self, tenant_id):
old_tenant = self.db.get('tenant-%s' % tenant_id)

View File

@ -343,7 +343,8 @@ class TenantController(wsgi.Application):
tenant_refs = tenant_refs[page_idx:limit]
for x in tenant_refs:
x['enabled'] = True
if 'enabled' not in x:
x['enabled'] = True
o = {'tenants': tenant_refs,
'tenants_links': []}
return o

View File

@ -191,27 +191,57 @@ class KeystoneClientTests(object):
def test_tenant_create_update_and_delete(self):
from keystoneclient import exceptions as client_exceptions
test_tenant = 'new_tenant'
tenant_name = 'original_tenant'
tenant_description = 'My original tenant!'
tenant_enabled = True
client = self.get_client(admin=True)
tenant = client.tenants.create(tenant_name=test_tenant,
description="My new tenant!",
enabled=True)
self.assertEquals(tenant.name, test_tenant)
# create, get, and list a tenant
tenant = client.tenants.create(tenant_name=tenant_name,
description=tenant_description,
enabled=tenant_enabled)
self.assertEquals(tenant.name, tenant_name)
self.assertEquals(tenant.description, tenant_description)
self.assertEquals(tenant.enabled, tenant_enabled)
tenant = client.tenants.get(tenant_id=tenant.id)
self.assertEquals(tenant.name, test_tenant)
self.assertEquals(tenant.name, tenant_name)
self.assertEquals(tenant.description, tenant_description)
self.assertEquals(tenant.enabled, tenant_enabled)
tenant = [t for t in client.tenants.list() if t.id == tenant.id].pop()
self.assertEquals(tenant.name, tenant_name)
self.assertEquals(tenant.description, tenant_description)
self.assertEquals(tenant.enabled, tenant_enabled)
# update, get, and list a tenant
tenant_name = 'updated_tenant'
tenant_description = 'Updated tenant!'
tenant_enabled = False
tenant = client.tenants.update(tenant_id=tenant.id,
tenant_name='new_tenant2',
enabled=False,
description='new description')
self.assertEquals(tenant.name, 'new_tenant2')
self.assertFalse(tenant.enabled)
self.assertEquals(tenant.description, 'new description')
tenant_name=tenant_name,
enabled=tenant_enabled,
description=tenant_description)
self.assertEquals(tenant.name, tenant_name)
self.assertEquals(tenant.description, tenant_description)
self.assertEquals(tenant.enabled, tenant_enabled)
tenant = client.tenants.get(tenant_id=tenant.id)
self.assertEquals(tenant.name, tenant_name)
self.assertEquals(tenant.description, tenant_description)
self.assertEquals(tenant.enabled, tenant_enabled)
tenant = [t for t in client.tenants.list() if t.id == tenant.id].pop()
self.assertEquals(tenant.name, tenant_name)
self.assertEquals(tenant.description, tenant_description)
self.assertEquals(tenant.enabled, tenant_enabled)
# delete, get, and list a tenant
client.tenants.delete(tenant=tenant.id)
self.assertRaises(client_exceptions.NotFound, client.tenants.get,
tenant.id)
self.assertFalse([t for t in client.tenants.list()
if t.id == tenant.id])
def test_tenant_list(self):
client = self.get_client()