From f8ae58f2a27db4efe890553952df37fe2f0da7a3 Mon Sep 17 00:00:00 2001 From: "OTSUKA, Yuanying" Date: Wed, 14 Jan 2015 13:34:27 +0900 Subject: [PATCH] Implement bay deletion on api Heat stack was not deleted when bay deleted. This fixes it. Change-Id: I52e82c3b50854f80c86b6553e99d256962a38497 Closes-bug: #1410507 --- magnum/api/controllers/v1/bay.py | 4 +--- magnum/conductor/handlers/bay_k8s_heat.py | 2 ++ magnum/tests/api/controllers/v1/test_bay.py | 7 +++++++ 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/magnum/api/controllers/v1/bay.py b/magnum/api/controllers/v1/bay.py index aa6dfb2d13..54f041c974 100644 --- a/magnum/api/controllers/v1/bay.py +++ b/magnum/api/controllers/v1/bay.py @@ -313,6 +313,4 @@ class BaysController(rest.RestController): if self.from_bays: raise exception.OperationNotPermitted - rpc_bay = objects.Bay.get_by_uuid(pecan.request.context, - bay_uuid) - rpc_bay.destroy() + pecan.request.rpcapi.bay_delete(bay_uuid) diff --git a/magnum/conductor/handlers/bay_k8s_heat.py b/magnum/conductor/handlers/bay_k8s_heat.py index ae7ecd1ef0..62d0a6a50d 100644 --- a/magnum/conductor/handlers/bay_k8s_heat.py +++ b/magnum/conductor/handlers/bay_k8s_heat.py @@ -149,7 +149,9 @@ class Handler(object): osc = clients.OpenStackClients(ctxt) bay = objects.Bay.get_by_uuid(ctxt, uuid) stack_id = bay.stack_id + # TODO(yuanying): handle stack status DELETE_IN_PROGRESS osc.heat().stacks.delete(stack_id) + # TODO(yuanying): bay.destroy will be triggered by stack status change. bay.destroy() return None diff --git a/magnum/tests/api/controllers/v1/test_bay.py b/magnum/tests/api/controllers/v1/test_bay.py index 511b6a5eef..8c031a4e75 100644 --- a/magnum/tests/api/controllers/v1/test_bay.py +++ b/magnum/tests/api/controllers/v1/test_bay.py @@ -10,6 +10,7 @@ # See the License for the specific language governing permissions and # limitations under the License. from magnum.conductor import api +from magnum import objects from magnum.tests.db import base as db_base from mock import patch @@ -20,6 +21,10 @@ class TestBayController(db_base.DbTestCase): bay.create() return bay + def mock_bay_destroy(self, bay_uuid): + bay = objects.Bay.get_by_uuid({}, bay_uuid) + bay.destroy() + def test_bay_api(self): with patch.object(api.API, 'bay_create') as mock_method: # Create a bay @@ -52,6 +57,8 @@ class TestBayController(db_base.DbTestCase): params=params) self.assertEqual(response.status_int, 200) + with patch.object(api.API, 'bay_delete') as mock_method: + mock_method.side_effect = self.mock_bay_destroy # Delete the bay we created response = self.app.delete('/v1/bays/%s' % c.get('uuid')) self.assertEqual(response.status_int, 204)