From f9a9e7f3278a3cf461acad4d688a4868c2f7ac94 Mon Sep 17 00:00:00 2001 From: sathish-nagappan Date: Tue, 23 Oct 2012 23:18:20 -0700 Subject: [PATCH] Enable Deletion of Services with Endpoints fixes Bug #1019475 Allows the user to delete a service that has endpoints. Change-Id: If2d669e50f73ea5bb7b269f941a3b2710808a98a --- keystone/catalog/backends/sql.py | 1 + tests/test_backend_sql.py | 13 +++++++++++++ 2 files changed, 14 insertions(+) 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")