Add strict option to discover_hosts
This adds a --strict option that can be passed in when calling the
nova-manage cell_v2 discover_hosts command. When this option is used,
the command will only return success if a new host has been found.
In any other case it is considered a failure.
Closes-Bug: #1692982
Change-Id: I942af11a3987e1edce67423c66931ad9ece65587
(cherry picked from commit aaae213bf3
)
This commit is contained in:
parent
47774935ac
commit
a272023aa8
|
@ -141,14 +141,16 @@ Nova Cells v2
|
||||||
transport url or database connection was missing, and 2 if a cell is
|
transport url or database connection was missing, and 2 if a cell is
|
||||||
already using that transport url and database connection combination.
|
already using that transport url and database connection combination.
|
||||||
|
|
||||||
``nova-manage cell_v2 discover_hosts [--cell_uuid <cell_uuid>] [--verbose]``
|
``nova-manage cell_v2 discover_hosts [--cell_uuid <cell_uuid>] [--verbose] [--strict]``
|
||||||
|
|
||||||
Searches cells, or a single cell, and maps found hosts. This command will
|
Searches cells, or a single cell, and maps found hosts. This command will
|
||||||
check the database for each cell (or a single one if passed in) and map
|
check the database for each cell (or a single one if passed in) and map
|
||||||
any hosts which are not currently mapped. If a host is already mapped
|
any hosts which are not currently mapped. If a host is already mapped
|
||||||
nothing will be done. You need to re-run this command each time you add
|
nothing will be done. You need to re-run this command each time you add
|
||||||
more compute hosts to a cell (otherwise the scheduler will never place
|
more compute hosts to a cell (otherwise the scheduler will never place
|
||||||
instances there).
|
instances there). If the strict option is provided the command will only
|
||||||
|
be considered successful if an unmapped host is discovered (exit code 0).
|
||||||
|
Any other case is considered a failure (exit code 1).
|
||||||
|
|
||||||
``nova-manage cell_v2 list_cells [--verbose]``
|
``nova-manage cell_v2 list_cells [--verbose]``
|
||||||
|
|
||||||
|
|
|
@ -1384,7 +1384,11 @@ class CellV2Commands(object):
|
||||||
'map.')
|
'map.')
|
||||||
@args('--verbose', action='store_true',
|
@args('--verbose', action='store_true',
|
||||||
help=_('Provide detailed output when discovering hosts.'))
|
help=_('Provide detailed output when discovering hosts.'))
|
||||||
def discover_hosts(self, cell_uuid=None, verbose=False):
|
@args('--strict', action='store_true',
|
||||||
|
help=_('Considered successful (exit code 0) only when an unmapped '
|
||||||
|
'host is discovered. Any other outcome will be considered a '
|
||||||
|
'failure (exit code 1).'))
|
||||||
|
def discover_hosts(self, cell_uuid=None, verbose=False, strict=False):
|
||||||
"""Searches cells, or a single cell, and maps found hosts.
|
"""Searches cells, or a single cell, and maps found hosts.
|
||||||
|
|
||||||
When a new host is added to a deployment it will add a service entry
|
When a new host is added to a deployment it will add a service entry
|
||||||
|
@ -1397,7 +1401,10 @@ class CellV2Commands(object):
|
||||||
print(msg)
|
print(msg)
|
||||||
|
|
||||||
ctxt = context.RequestContext()
|
ctxt = context.RequestContext()
|
||||||
host_mapping_obj.discover_hosts(ctxt, cell_uuid, status_fn)
|
hosts = host_mapping_obj.discover_hosts(ctxt, cell_uuid, status_fn)
|
||||||
|
# discover_hosts will return an empty list if no hosts are discovered
|
||||||
|
if strict:
|
||||||
|
return int(not hosts)
|
||||||
|
|
||||||
@action_description(
|
@action_description(
|
||||||
_("Add a new cell to nova API database. "
|
_("Add a new cell to nova API database. "
|
||||||
|
|
|
@ -1386,6 +1386,19 @@ class CellV2CommandsTestCase(test.NoDBTestCase):
|
||||||
|
|
||||||
mock_cell_mapping_get_by_uuid.assert_not_called()
|
mock_cell_mapping_get_by_uuid.assert_not_called()
|
||||||
|
|
||||||
|
@mock.patch('nova.objects.host_mapping.discover_hosts')
|
||||||
|
def test_discover_hosts_strict(self, mock_discover_hosts):
|
||||||
|
# Check for exit code 0 if unmapped hosts found
|
||||||
|
mock_discover_hosts.return_value = ['fake']
|
||||||
|
self.assertEqual(self.commands.discover_hosts(strict=True), 0)
|
||||||
|
|
||||||
|
# Check for exit code 1 if no unmapped hosts are found
|
||||||
|
mock_discover_hosts.return_value = []
|
||||||
|
self.assertEqual(self.commands.discover_hosts(strict=True), 1)
|
||||||
|
|
||||||
|
# Check the return when strict=False
|
||||||
|
self.assertIsNone(self.commands.discover_hosts())
|
||||||
|
|
||||||
def test_validate_transport_url_in_conf(self):
|
def test_validate_transport_url_in_conf(self):
|
||||||
from_conf = 'fake://user:pass@host:port/'
|
from_conf = 'fake://user:pass@host:port/'
|
||||||
self.flags(transport_url=from_conf)
|
self.flags(transport_url=from_conf)
|
||||||
|
|
Loading…
Reference in New Issue