summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2017-06-12 10:55:10 +0000
committerGerrit Code Review <review@openstack.org>2017-06-12 10:55:10 +0000
commit05bf65d2c95a755c9bca7ab1711be6e7eb02451a (patch)
tree38a6f25e3a20cc0798a60b5cdc0bd8a5a2841fa8
parent677ef33d6536f0803a8497d5394c382919835b84 (diff)
parenta272023aa8a29db064f6a22b867fff2bf15089f1 (diff)
Merge "Add strict option to discover_hosts" into stable/ocata
-rw-r--r--doc/source/man/nova-manage.rst6
-rw-r--r--nova/cmd/manage.py11
-rw-r--r--nova/tests/unit/test_nova_manage.py13
3 files changed, 26 insertions, 4 deletions
diff --git a/doc/source/man/nova-manage.rst b/doc/source/man/nova-manage.rst
index f6258c5..3073665 100644
--- a/doc/source/man/nova-manage.rst
+++ b/doc/source/man/nova-manage.rst
@@ -141,14 +141,16 @@ Nova Cells v2
141 transport url or database connection was missing, and 2 if a cell is 141 transport url or database connection was missing, and 2 if a cell is
142 already using that transport url and database connection combination. 142 already using that transport url and database connection combination.
143 143
144``nova-manage cell_v2 discover_hosts [--cell_uuid <cell_uuid>] [--verbose]`` 144``nova-manage cell_v2 discover_hosts [--cell_uuid <cell_uuid>] [--verbose] [--strict]``
145 145
146 Searches cells, or a single cell, and maps found hosts. This command will 146 Searches cells, or a single cell, and maps found hosts. This command will
147 check the database for each cell (or a single one if passed in) and map 147 check the database for each cell (or a single one if passed in) and map
148 any hosts which are not currently mapped. If a host is already mapped 148 any hosts which are not currently mapped. If a host is already mapped
149 nothing will be done. You need to re-run this command each time you add 149 nothing will be done. You need to re-run this command each time you add
150 more compute hosts to a cell (otherwise the scheduler will never place 150 more compute hosts to a cell (otherwise the scheduler will never place
151 instances there). 151 instances there). If the strict option is provided the command will only
152 be considered successful if an unmapped host is discovered (exit code 0).
153 Any other case is considered a failure (exit code 1).
152 154
153``nova-manage cell_v2 list_cells [--verbose]`` 155``nova-manage cell_v2 list_cells [--verbose]``
154 156
diff --git a/nova/cmd/manage.py b/nova/cmd/manage.py
index b760290..df58d04 100644
--- a/nova/cmd/manage.py
+++ b/nova/cmd/manage.py
@@ -1381,7 +1381,11 @@ class CellV2Commands(object):
1381 'map.') 1381 'map.')
1382 @args('--verbose', action='store_true', 1382 @args('--verbose', action='store_true',
1383 help=_('Provide detailed output when discovering hosts.')) 1383 help=_('Provide detailed output when discovering hosts.'))
1384 def discover_hosts(self, cell_uuid=None, verbose=False): 1384 @args('--strict', action='store_true',
1385 help=_('Considered successful (exit code 0) only when an unmapped '
1386 'host is discovered. Any other outcome will be considered a '
1387 'failure (exit code 1).'))
1388 def discover_hosts(self, cell_uuid=None, verbose=False, strict=False):
1385 """Searches cells, or a single cell, and maps found hosts. 1389 """Searches cells, or a single cell, and maps found hosts.
1386 1390
1387 When a new host is added to a deployment it will add a service entry 1391 When a new host is added to a deployment it will add a service entry
@@ -1394,7 +1398,10 @@ class CellV2Commands(object):
1394 print(msg) 1398 print(msg)
1395 1399
1396 ctxt = context.RequestContext() 1400 ctxt = context.RequestContext()
1397 host_mapping_obj.discover_hosts(ctxt, cell_uuid, status_fn) 1401 hosts = host_mapping_obj.discover_hosts(ctxt, cell_uuid, status_fn)
1402 # discover_hosts will return an empty list if no hosts are discovered
1403 if strict:
1404 return int(not hosts)
1398 1405
1399 @action_description( 1406 @action_description(
1400 _("Add a new cell to nova API database. " 1407 _("Add a new cell to nova API database. "
diff --git a/nova/tests/unit/test_nova_manage.py b/nova/tests/unit/test_nova_manage.py
index cc7cba3..25d250a 100644
--- a/nova/tests/unit/test_nova_manage.py
+++ b/nova/tests/unit/test_nova_manage.py
@@ -1387,6 +1387,19 @@ class CellV2CommandsTestCase(test.NoDBTestCase):
1387 1387
1388 mock_cell_mapping_get_by_uuid.assert_not_called() 1388 mock_cell_mapping_get_by_uuid.assert_not_called()
1389 1389
1390 @mock.patch('nova.objects.host_mapping.discover_hosts')
1391 def test_discover_hosts_strict(self, mock_discover_hosts):
1392 # Check for exit code 0 if unmapped hosts found
1393 mock_discover_hosts.return_value = ['fake']
1394 self.assertEqual(self.commands.discover_hosts(strict=True), 0)
1395
1396 # Check for exit code 1 if no unmapped hosts are found
1397 mock_discover_hosts.return_value = []
1398 self.assertEqual(self.commands.discover_hosts(strict=True), 1)
1399
1400 # Check the return when strict=False
1401 self.assertIsNone(self.commands.discover_hosts())
1402
1390 def test_validate_transport_url_in_conf(self): 1403 def test_validate_transport_url_in_conf(self):
1391 from_conf = 'fake://user:pass@host:port/' 1404 from_conf = 'fake://user:pass@host:port/'
1392 self.flags(transport_url=from_conf) 1405 self.flags(transport_url=from_conf)