Skip to content

Commit

Permalink
Merge "Let nova-manage cell_v2 commands use transport_url from CONF" …
Browse files Browse the repository at this point in the history
…into stable/newton
  • Loading branch information
Jenkins authored and openstack-gerrit committed Jan 14, 2017
2 parents 13ba33a + ed1ebaa commit c6743ca
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 8 deletions.
21 changes: 13 additions & 8 deletions nova/cmd/manage.py
Expand Up @@ -1201,12 +1201,16 @@ def list(self):
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='<transport url>', required=True,
dest='transport_url',
def _validate_transport_url(self, transport_url):
transport_url = transport_url or CONF.transport_url
if not transport_url:
print('Must specify --transport-url if [DEFAULT]/transport_url '
'is not set in the configuration file.')
return transport_url

@args('--transport-url', metavar='<transport url>', dest='transport_url',
help='The transport url for the cell message queue')
def simple_cell_setup(self, transport_url):
def simple_cell_setup(self, transport_url=None):
"""Simple cellsv2 setup.
This simplified command is for use by existing non-cells users to
Expand All @@ -1218,6 +1222,9 @@ def simple_cell_setup(self, transport_url):
if CONF.cells.enable:
print('CellsV1 users cannot use this simplified setup command')
return 2
transport_url = self._validate_transport_url(transport_url)
if not transport_url:
return 1
ctxt = context.RequestContext()
try:
cell0_mapping = self.map_cell0()
Expand Down Expand Up @@ -1430,10 +1437,8 @@ def map_cell_and_hosts(self, transport_url=None, name=None, verbose=False):
nova-manage cell_v2 map_cell_and_hosts --config-file <cell nova.conf>
"""
transport_url = CONF.transport_url or transport_url
transport_url = self._validate_transport_url(transport_url)
if not transport_url:
print('Must specify --transport-url if [DEFAULT]/transport_url '
'is not set in the configuration file.')
return 1
self._map_cell_and_hosts(transport_url, name, verbose)
# online_data_migrations established a pattern of 0 meaning everything
Expand Down
20 changes: 20 additions & 0 deletions nova/tests/unit/test_nova_manage.py
Expand Up @@ -1348,3 +1348,23 @@ def test_discover_hosts_multiple_cells(self, mock_cell_mapping_get_by_uuid,
mock_cell_mapping_get_by_uuid.assert_not_called()
mock_cell_mapping_get_all.assert_called_once_with(
test.MatchType(context.RequestContext))

def test_validate_transport_url_in_conf(self):
from_conf = 'fake://user:pass@host:port/'
self.flags(transport_url=from_conf)
self.assertEqual(from_conf,
self.commands._validate_transport_url(None))

def test_validate_transport_url_on_command_line(self):
from_cli = 'fake://user:pass@host:port/'
self.assertEqual(from_cli,
self.commands._validate_transport_url(from_cli))

def test_validate_transport_url_missing(self):
self.assertIsNone(self.commands._validate_transport_url(None))

def test_validate_transport_url_favors_command_line(self):
self.flags(transport_url='fake://user:pass@host:port/')
from_cli = 'fake://otheruser:otherpass@otherhost:otherport'
self.assertEqual(from_cli,
self.commands._validate_transport_url(from_cli))

0 comments on commit c6743ca

Please sign in to comment.