diff --git a/keystone/catalog/backends/sql.py b/keystone/catalog/backends/sql.py index e6172db5bc..6876bdec32 100644 --- a/keystone/catalog/backends/sql.py +++ b/keystone/catalog/backends/sql.py @@ -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() diff --git a/tests/test_backend_sql.py b/tests/test_backend_sql.py index 13c1d3df1b..bc318d0792 100644 --- a/tests/test_backend_sql.py +++ b/tests/test_backend_sql.py @@ -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")