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 b276e84103)
This commit is contained in:
Corey Bryant 2017-02-15 16:43:50 -05:00 committed by Matt Riedemann
parent a81d2c325d
commit 7d0c5998cb
3 changed files with 30 additions and 5 deletions

View File

@ -165,10 +165,14 @@ Nova Cells v2
``nova-manage cell_v2 update_cell --cell_uuid <cell_uuid> [--name <cell_name>] [--transport-url <transport_url>] [--database_connection <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

View File

@ -1506,7 +1506,8 @@ class CellV2Commands(object):
@args('--database_connection', metavar='<database>', 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

View File

@ -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."""