Add scatter-gather-single-cell utility
This patch adds the method to query a single cell using the scatter-gather utility. Although we do have the target_cell function to target a specific cell, in situations where we need to handle a down cell (like for nova show), it is advantageous to have this wrapper which in turn only calls the scatter-gather-cells utility. Change-Id: I31f2ab499aed795812a99b116cec3663760297e3
This commit is contained in:
parent
85b36cd2f8
commit
1997de3b77
|
@ -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.
|
||||
|
||||
|
|
|
@ -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')
|
||||
|
|
Loading…
Reference in New Issue