Merge "Add scatter-gather-single-cell utility"

This commit is contained in:
Zuul 2018-10-11 22:09:51 +00:00 committed by Gerrit Code Review
commit e1749f2897
2 changed files with 39 additions and 0 deletions

View File

@ -512,6 +512,29 @@ def scatter_gather_skip_cell0(context, fn, *args, **kwargs):
fn, *args, **kwargs)
def scatter_gather_single_cell(context, cell_mapping, fn, *args, **kwargs):
"""Target the provided cell and return its results or sentinels in case of
failure.
The first parameter in the signature of the function to call for each cell
should be of type RequestContext.
:param context: The RequestContext for querying cells
:param cell_mapping: The CellMapping to target
:param fn: The function to call for each cell
:param args: The args for the function to call for each cell, not including
the RequestContext
:param kwargs: The kwargs for the function to call for this cell
:returns: A dict {cell_uuid: result} containing the joined results. The
did_not_respond_sentinel will be returned if the cell did not
respond within the timeout. The raised_exception_sentinel will
be returned if the call to the cell raised an exception. The
exception will be logged.
"""
return scatter_gather_cells(context, [cell_mapping], CELL_TIMEOUT, fn,
*args, **kwargs)
def scatter_gather_all_cells(context, fn, *args, **kwargs):
"""Target all cells in parallel and return their results.

View File

@ -466,3 +466,19 @@ class ContextTestCase(test.NoDBTestCase):
mock_scatter.assert_called_once_with(
ctxt, [mapping1], 60, objects.InstanceList.get_by_filters, filters,
sort_dir='foo')
@mock.patch('nova.context.scatter_gather_cells')
def test_scatter_gather_single_cell(self, mock_scatter):
ctxt = context.get_context()
mapping0 = objects.CellMapping(database_connection='fake://db0',
transport_url='none:///',
uuid=objects.CellMapping.CELL0_UUID)
filters = {'deleted': False}
context.scatter_gather_single_cell(ctxt, mapping0,
objects.InstanceList.get_by_filters, filters, sort_dir='foo')
mock_scatter.assert_called_once_with(
ctxt, [mapping0], context.CELL_TIMEOUT,
objects.InstanceList.get_by_filters, filters,
sort_dir='foo')