From 9e9520a4b07a841595572c9084870cae12a96b78 Mon Sep 17 00:00:00 2001 From: Surya Seetharaman Date: Thu, 22 Mar 2018 19:26:05 +0100 Subject: [PATCH] Add disabled option to create_cell command Specifying this new option will create pre-disabled cells. Related to blueprint cell-disable Change-Id: I87e06eeefd48f640f42fcc5ff5a48938adc2ac22 --- doc/source/cli/nova-manage.rst | 6 ++++-- nova/cmd/manage.py | 7 +++++-- nova/tests/unit/test_nova_manage.py | 15 +++++++++++++++ ...-disabled-to-create_cell-feb1643ec4716eb2.yaml | 6 ++++++ 4 files changed, 30 insertions(+), 4 deletions(-) create mode 100644 releasenotes/notes/add-disabled-to-create_cell-feb1643ec4716eb2.yaml diff --git a/doc/source/cli/nova-manage.rst b/doc/source/cli/nova-manage.rst index ccca7f9b7ef7..423a04ced675 100644 --- a/doc/source/cli/nova-manage.rst +++ b/doc/source/cli/nova-manage.rst @@ -188,7 +188,7 @@ Nova Cells v2 instance which has instance mapping, and 4 if it is an archived instance which still has an instance mapping. -``nova-manage cell_v2 create_cell [--name ] [--transport-url ] [--database_connection ] [--verbose]`` +``nova-manage cell_v2 create_cell [--name ] [--transport-url ] [--database_connection ] [--verbose] [--disabled]`` Create a cell mapping to the database connection and message queue transport url. If a database_connection is not specified, it will use the one defined by ``[database]/connection`` in the configuration file passed @@ -197,7 +197,9 @@ Nova Cells v2 verbose option will print out the resulting cell mapping uuid. Returns 0 if the cell mapping was successfully created, 1 if the transport url or database connection was missing, and 2 if a cell is already using that - transport url and database connection combination. + transport url and database connection combination. All the cells created are + by default enabled. However passing the disabled option can create a pre-disabled + cell, meaning no scheduling will happen to this cell. ``nova-manage cell_v2 discover_hosts [--cell_uuid ] [--verbose] [--strict]`` Searches cells, or a single cell, and maps found hosts. This command will diff --git a/nova/cmd/manage.py b/nova/cmd/manage.py index 9a5975541d17..0dd7a46a46da 100644 --- a/nova/cmd/manage.py +++ b/nova/cmd/manage.py @@ -1365,8 +1365,10 @@ class CellV2Commands(object): help=_('The transport url for the cell message queue')) @args('--verbose', action='store_true', help=_('Output the uuid of the created cell')) + @args('--disabled', action='store_true', + help=_('To create a pre-disabled cell.')) def create_cell(self, name=None, database_connection=None, - transport_url=None, verbose=False): + transport_url=None, verbose=False, disabled=False): ctxt = context.get_context() transport_url = transport_url or CONF.transport_url if not transport_url: @@ -1387,7 +1389,8 @@ class CellV2Commands(object): ctxt, uuid=cell_mapping_uuid, name=name, transport_url=transport_url, - database_connection=database_connection) + database_connection=database_connection, + disabled=disabled) cell_mapping.create() if verbose: print(cell_mapping_uuid) diff --git a/nova/tests/unit/test_nova_manage.py b/nova/tests/unit/test_nova_manage.py index e4e14c7cf4b1..e84c05e4b32e 100644 --- a/nova/tests/unit/test_nova_manage.py +++ b/nova/tests/unit/test_nova_manage.py @@ -1679,6 +1679,7 @@ class CellV2CommandsTestCase(test.NoDBTestCase): self.assertEqual(kwargs['database_connection'], cell2.database_connection) self.assertEqual(kwargs['transport_url'], cell2.transport_url) + self.assertIs(cell2.disabled, False) def test_create_cell_use_config_values(self): settings = dict( @@ -1720,6 +1721,20 @@ class CellV2CommandsTestCase(test.NoDBTestCase): self.assertEqual(1, status) self.assertIn('--database_connection', self.output.getvalue()) + def test_create_cell_pre_disabled(self): + ctxt = context.get_context() + kwargs = dict( + name='fake-name1', + transport_url='fake-transport-url1', + database_connection='fake-db-connection1') + status1 = self.commands.create_cell(verbose=True, disabled=True, + **kwargs) + self.assertEqual(0, status1) + cell_uuid1 = self.output.getvalue().strip() + cell1 = objects.CellMapping.get_by_uuid(ctxt, cell_uuid1) + self.assertEqual(kwargs['name'], cell1.name) + self.assertIs(cell1.disabled, True) + def test_list_cells_no_cells_verbose_false(self): ctxt = context.RequestContext() cell_mapping0 = objects.CellMapping( diff --git a/releasenotes/notes/add-disabled-to-create_cell-feb1643ec4716eb2.yaml b/releasenotes/notes/add-disabled-to-create_cell-feb1643ec4716eb2.yaml new file mode 100644 index 000000000000..2a59ba054fe0 --- /dev/null +++ b/releasenotes/notes/add-disabled-to-create_cell-feb1643ec4716eb2.yaml @@ -0,0 +1,6 @@ +--- +features: + - | + A new option ``disabled`` has been added to nova-manage cell_v2 create_cell + command by which users can create pre-disabled cells. Hence unless such cells + are enabled, no VMs will be spawned on the hosts in these cells.