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
This commit is contained in:
jichenjc 2017-01-23 23:31:24 +08:00
parent edf51119fa
commit 17b9f83778
2 changed files with 12 additions and 0 deletions

View File

@ -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:

View File

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