diff --git a/nova/cmd/manage.py b/nova/cmd/manage.py index 2d19ec264f10..fbc0dc280049 100644 --- a/nova/cmd/manage.py +++ b/nova/cmd/manage.py @@ -1181,6 +1181,21 @@ class CellCommands(object): class CellV2Commands(object): """Commands for managing cells v2.""" + # TODO(melwitt): Remove this when the oslo.messaging function + # for assembling a transport url from ConfigOpts is available + @args('--transport-url', metavar='', required=True, + dest='transport_url', + help='The transport url for the cell message queue') + def simple_cell_setup(self, transport_url): + cell_uuid = self._map_cell_and_hosts(transport_url) + if cell_uuid is None: + # There are no compute hosts which means no cell_mapping was + # created. This should also mean that there are no instances. + return 1 + self.map_cell0() + self.map_instances(cell_uuid) + return 0 + @args('--database_connection', metavar='', help='The database connection url for cell0. ' diff --git a/nova/tests/unit/test_nova_manage.py b/nova/tests/unit/test_nova_manage.py index ca1473ccad19..cd3ccd6b2a91 100644 --- a/nova/tests/unit/test_nova_manage.py +++ b/nova/tests/unit/test_nova_manage.py @@ -1088,3 +1088,47 @@ class CellV2CommandsTestCase(test.TestCase): self.assertEqual('none:///', cell_mapping.transport_url) self.assertEqual('fake://netloc/nova_api_cell0', cell_mapping.database_connection) + + def test_migrate_single_command(self): + ctxt = context.RequestContext() + CONF.set_default('connection', + 'fake://netloc/nova_api', + group='api_database') + values = { + 'vcpus': 4, + 'memory_mb': 4096, + 'local_gb': 1024, + 'vcpus_used': 2, + 'memory_mb_used': 2048, + 'local_gb_used': 512, + 'hypervisor_type': 'Hyper-Dan-VM-ware', + 'hypervisor_version': 1001, + 'cpu_info': 'Schmintel i786', + } + for i in range(3): + host = 'host%s' % i + compute_node = objects.ComputeNode(ctxt, host=host, **values) + compute_node.create() + + transport_url = "fake://guest:devstack@127.0.0.1:9999/" + cell_uuid = uuidutils.generate_uuid() + with mock.patch.object(uuidutils, 'generate_uuid', + return_value=cell_uuid): + self.commands.simple_cell_setup(transport_url) + + # Check cell0 from default + cell_mapping = objects.CellMapping.get_by_uuid(ctxt, + objects.CellMapping.CELL0_UUID) + self.assertEqual('cell0', cell_mapping.name) + self.assertEqual('none:///', cell_mapping.transport_url) + self.assertEqual('fake://netloc/nova_api_cell0', + cell_mapping.database_connection) + + # Verify the cell mapping + cell_mapping = objects.CellMapping.get_by_uuid(ctxt, cell_uuid) + self.assertEqual(transport_url, cell_mapping.transport_url) + # Verify the host mappings + for i in range(3): + host = 'host%s' % i + host_mapping = objects.HostMapping.get_by_host(ctxt, host) + self.assertEqual(cell_mapping.uuid, host_mapping.cell_mapping.uuid) diff --git a/releasenotes/notes/cells-single-migration-command-0e98d66e31e02a50.yaml b/releasenotes/notes/cells-single-migration-command-0e98d66e31e02a50.yaml new file mode 100644 index 000000000000..def0454664b1 --- /dev/null +++ b/releasenotes/notes/cells-single-migration-command-0e98d66e31e02a50.yaml @@ -0,0 +1,13 @@ +--- +upgrade: + - A new nova-manage command has been added which will upgrade a deployment to + cells v2. Running the command will setup a single cell containing the + existing hosts and instances. No data or instances will be moved during + this operation, but new data will be added to the nova_api database. New + instances booted after this point will be placed into the cell. Please + note that this does not mean that cells v2 is fully functional at this + time, but this is a significant part of the effort to get there. + The new command is + "nova-manage cell_v2 simple_cell_setup --transport_url " + where transport_url is the connection information for the current message + queue used by Nova.