From 7d0c5998cbb3677d619cb14e6ce1631eab297f34 Mon Sep 17 00:00:00 2001 From: Corey Bryant Date: Wed, 15 Feb 2017 16:43:50 -0500 Subject: [PATCH] Enable defaults for cell_v2 update_cell command Initialize optional parameters for update_cell() to None and enable getting the transport_url and db_connection from nova.conf if not specified as arguments. Change-Id: Ib20cfeb7b17dba06f9f2db5eca1fa194d2795767 Closes-Bug: 1665145 (cherry picked from commit b276e84103333c91c32b6ccb229104dd87b8167d) --- doc/source/man/nova-manage.rst | 12 ++++++++---- nova/cmd/manage.py | 7 ++++++- nova/tests/unit/test_nova_manage.py | 16 ++++++++++++++++ 3 files changed, 30 insertions(+), 5 deletions(-) diff --git a/doc/source/man/nova-manage.rst b/doc/source/man/nova-manage.rst index 67797f23b407..f6258c5e4b2b 100644 --- a/doc/source/man/nova-manage.rst +++ b/doc/source/man/nova-manage.rst @@ -165,10 +165,14 @@ Nova Cells v2 ``nova-manage cell_v2 update_cell --cell_uuid [--name ] [--transport-url ] [--database_connection ]`` - Updates the properties of a cell by the given uuid. If the cell is not - found by uuid, this command will return an exit code of 1. If the - properties cannot be set, this will return 2. Otherwise, the exit code - will be 0. + Updates the properties of a cell by the given uuid. If a + database_connection is not specified, it will attempt to use the one + defined by ``[database]/connection`` in the configuration file. If a + transport_url is not specified, it will attempt to use the one defined + by ``[DEFAULT]/transport_url`` in the configuration file. If the cell + is not found by uuid, this command will return an exit code of 1. If + the properties cannot be set, this will return 2. Otherwise, the exit + code will be 0. NOTE: Updating the transport_url or database_connection fields on a running system will NOT result in all nodes immediately using the diff --git a/nova/cmd/manage.py b/nova/cmd/manage.py index 3954a2594b03..9e4e74151e82 100644 --- a/nova/cmd/manage.py +++ b/nova/cmd/manage.py @@ -1506,7 +1506,8 @@ class CellV2Commands(object): @args('--database_connection', metavar='', dest='db_connection', help=_('Set the cell database_connection. NOTE that running nodes ' 'will not see the change until restart!')) - def update_cell(self, cell_uuid, name, transport_url, db_connection): + def update_cell(self, cell_uuid, name=None, transport_url=None, + db_connection=None): """Updates the properties of a cell by the given uuid. If the cell is not found by uuid, this command will return an exit @@ -1526,8 +1527,12 @@ class CellV2Commands(object): if name: cell_mapping.name = name + + transport_url = transport_url or CONF.transport_url if transport_url: cell_mapping.transport_url = transport_url + + db_connection = db_connection or CONF.database.connection if db_connection: cell_mapping.database_connection = db_connection diff --git a/nova/tests/unit/test_nova_manage.py b/nova/tests/unit/test_nova_manage.py index a6f6cd83f559..8d8e3df882f1 100644 --- a/nova/tests/unit/test_nova_manage.py +++ b/nova/tests/unit/test_nova_manage.py @@ -1564,6 +1564,22 @@ class CellV2CommandsTestCase(test.NoDBTestCase): output = self.output.getvalue().strip() self.assertEqual('', output) + def test_update_cell_success_defaults(self): + ctxt = context.get_admin_context() + objects.CellMapping(context=ctxt, uuid=uuidsentinel.cell1, + name='cell1', + transport_url='fake://mq', + database_connection='fake:///db').create() + self.assertEqual(0, self.commands.update_cell(uuidsentinel.cell1)) + cm = objects.CellMapping.get_by_uuid(ctxt, uuidsentinel.cell1) + self.assertEqual('cell1', cm.name) + expected_transport_url = CONF.transport_url or 'fake://mq' + self.assertEqual(expected_transport_url, cm.transport_url) + expected_db_connection = CONF.database.connection or 'fake:///db' + self.assertEqual(expected_db_connection, cm.database_connection) + output = self.output.getvalue().strip() + self.assertEqual('', output) + class TestNovaManageMain(test.NoDBTestCase): """Tests the nova-manage:main() setup code."""