Merge "Clean up cell handling in nova-manage cell_v2 map_instances"
This commit is contained in:
@@ -1114,14 +1114,16 @@ class CellCommands(object):
|
||||
class CellV2Commands(object):
|
||||
"""Commands for managing cells v2."""
|
||||
|
||||
@args('--cell_uuid', metavar='<cell_uuid>', help='The cell uuid')
|
||||
@args('--cell_uuid', metavar='<cell_uuid>', required=True,
|
||||
help='Unmigrated instances will be mapped to the cell with the '
|
||||
'uuid provided.')
|
||||
@args('--limit', metavar='<limit>',
|
||||
help='Maximum number of instances to map')
|
||||
@args('--marker', metavar='<marker',
|
||||
help='The last updated instance UUID')
|
||||
@args('--verbose', metavar='<verbose>',
|
||||
help='Provide output for the registration')
|
||||
def map_instances(self, cell_uuid=None, limit=None,
|
||||
def map_instances(self, cell_uuid, limit=None,
|
||||
marker=None, verbose=0):
|
||||
if limit is not None:
|
||||
limit = int(limit)
|
||||
@@ -1129,11 +1131,8 @@ class CellV2Commands(object):
|
||||
print('Must supply a positive value for limit')
|
||||
return(1)
|
||||
ctxt = context.get_admin_context(read_deleted='yes')
|
||||
if cell_uuid is None:
|
||||
raise Exception(_("cell_uuid must be set"))
|
||||
else:
|
||||
# Validate the cell exists
|
||||
cell_mapping = objects.CellMapping.get_by_uuid(ctxt, cell_uuid)
|
||||
# Validate the cell exists
|
||||
cell_mapping = objects.CellMapping.get_by_uuid(ctxt, cell_uuid)
|
||||
filters = {}
|
||||
instances = objects.InstanceList.get_by_filters(
|
||||
ctxt, filters, sort_key='created_at', sort_dir='asc',
|
||||
@@ -1147,7 +1146,7 @@ class CellV2Commands(object):
|
||||
try:
|
||||
mapping = objects.InstanceMapping(ctxt)
|
||||
mapping.instance_uuid = instance.uuid
|
||||
mapping.cell_id = cell_mapping.id
|
||||
mapping.cell_mapping = cell_mapping
|
||||
mapping.project_id = instance.project_id
|
||||
mapping.create()
|
||||
except db_exc.DBDuplicateEntry:
|
||||
|
@@ -832,3 +832,53 @@ class CellV2CommandsTestCase(test.TestCase):
|
||||
output = sys.stdout.getvalue().strip()
|
||||
expected = 'No hosts found to map to cell, exiting.'
|
||||
self.assertEqual(expected, output)
|
||||
|
||||
def test_map_instances(self):
|
||||
ctxt = context.RequestContext('fake-user', 'fake_project')
|
||||
cell_uuid = uuidutils.generate_uuid()
|
||||
cell_mapping = objects.CellMapping(
|
||||
ctxt, uuid=cell_uuid, name='fake',
|
||||
transport_url='fake://', database_connection='fake://')
|
||||
cell_mapping.create()
|
||||
instance_uuids = []
|
||||
for i in range(3):
|
||||
uuid = uuidutils.generate_uuid()
|
||||
instance_uuids.append(uuid)
|
||||
objects.Instance(ctxt, project_id=ctxt.project_id,
|
||||
uuid=uuid).create()
|
||||
|
||||
self.commands.map_instances(cell_uuid)
|
||||
|
||||
for uuid in instance_uuids:
|
||||
inst_mapping = objects.InstanceMapping.get_by_instance_uuid(ctxt,
|
||||
uuid)
|
||||
self.assertEqual(ctxt.project_id, inst_mapping.project_id)
|
||||
self.assertEqual(cell_mapping.uuid, inst_mapping.cell_mapping.uuid)
|
||||
|
||||
def test_map_instances_duplicates(self):
|
||||
ctxt = context.RequestContext('fake-user', 'fake_project')
|
||||
cell_uuid = uuidutils.generate_uuid()
|
||||
cell_mapping = objects.CellMapping(
|
||||
ctxt, uuid=cell_uuid, name='fake',
|
||||
transport_url='fake://', database_connection='fake://')
|
||||
cell_mapping.create()
|
||||
instance_uuids = []
|
||||
for i in range(3):
|
||||
uuid = uuidutils.generate_uuid()
|
||||
instance_uuids.append(uuid)
|
||||
objects.Instance(ctxt, project_id=ctxt.project_id,
|
||||
uuid=uuid).create()
|
||||
|
||||
objects.InstanceMapping(ctxt, project_id=ctxt.project_id,
|
||||
instance_uuid=instance_uuids[0],
|
||||
cell_mapping=cell_mapping).create()
|
||||
|
||||
self.commands.map_instances(cell_uuid, verbose=True)
|
||||
output = sys.stdout.getvalue().strip()
|
||||
|
||||
self.assertIn('%s already mapped to cell' % instance_uuids[0], output)
|
||||
|
||||
for uuid in instance_uuids:
|
||||
inst_mapping = objects.InstanceMapping.get_by_instance_uuid(ctxt,
|
||||
uuid)
|
||||
self.assertEqual(ctxt.project_id, inst_mapping.project_id)
|
||||
|
Reference in New Issue
Block a user