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()