From 17b9f83778fbc5e902d938c4ee5ed19beda8a9d4 Mon Sep 17 00:00:00 2001 From: jichenjc Date: Mon, 23 Jan 2017 23:31:24 +0800 Subject: [PATCH] Prevent delete cell0 in nova-manage command not allow to delete cell0 in nova-manage command as it's used by nova Change-Id: I64ddba522c34e46ac8f642af4b26a926015ab330 Closes-Bug: 1664463 --- nova/cmd/manage.py | 6 ++++++ nova/tests/unit/test_nova_manage.py | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/nova/cmd/manage.py b/nova/cmd/manage.py index f871f6265a6c..f4b41d1f7b9d 100644 --- a/nova/cmd/manage.py +++ b/nova/cmd/manage.py @@ -1464,11 +1464,17 @@ class CellV2Commands(object): def delete_cell(self, cell_uuid): """Delete an empty cell by the given uuid. + If the cell is cell0 this command will return a non-zero exit code. + If the cell is not found by uuid or it is not empty (it has host or instance mappings) this command will return a non-zero exit code. Returns 0 if the empty cell is found and deleted successfully. """ + if cell_uuid == objects.CellMapping.CELL0_UUID: + print(_('Cell 0 can not be deleted.')) + return 5 + ctxt = context.get_admin_context() # Find the CellMapping given the uuid. try: diff --git a/nova/tests/unit/test_nova_manage.py b/nova/tests/unit/test_nova_manage.py index 1af65f5df426..75f6a84118de 100644 --- a/nova/tests/unit/test_nova_manage.py +++ b/nova/tests/unit/test_nova_manage.py @@ -1484,6 +1484,12 @@ class CellV2CommandsTestCase(test.NoDBTestCase): self.assertEqual('Cell with uuid %s was not found.' % cell_uuid, output) + def test_delete_cell_cell0(self): + cell_uuid = objects.CellMapping.CELL0_UUID + self.assertEqual(5, self.commands.delete_cell(cell_uuid)) + output = self.output.getvalue().strip() + self.assertEqual('Cell 0 can not be deleted.', output) + def test_delete_cell_host_mappings_exist(self): """Tests trying to delete a cell which has host mappings.""" cell_uuid = uuidutils.generate_uuid()