Enable Deletion of Services with Endpoints

fixes Bug #1019475

Allows the user to delete a service that has endpoints.

Change-Id: If2d669e50f73ea5bb7b269f941a3b2710808a98a
This commit is contained in:
sathish-nagappan 2012-10-23 23:18:20 -07:00
parent 7db2f6aa59
commit f9a9e7f327
2 changed files with 14 additions and 0 deletions

View File

@ -95,6 +95,7 @@ class Catalog(sql.Base, catalog.Driver):
def delete_service(self, service_id):
session = self.get_session()
with session.begin():
session.query(Endpoint).filter_by(service_id=service_id).delete()
if not session.query(Service).filter_by(id=service_id).delete():
raise exception.ServiceNotFound(service_id=service_id)
session.flush()

View File

@ -209,3 +209,16 @@ class SqlCatalog(SqlTests, test_backend.CatalogTests):
None)
self.assertEqual(catalog[region][service_type]['internalURL'],
None)
def test_delete_service_with_endpoints(self):
self.catalog_api.create_service('c', {"id": "c", "desc": "a1",
"name": "d"})
self.catalog_api.create_endpoint('d', {"id": "d", "region": None,
"service_id": "c", "adminurl": None,
"internalurl": None,
"publicurl": None})
self.catalog_api.delete_service("c")
self.assertRaises(exception.ServiceNotFound,
self.catalog_man.delete_service, {}, "c")
self.assertRaises(exception.EndpointNotFound,
self.catalog_man.delete_endpoint, {}, "d")