Fix behaviour of split_cell_and_item
If you try to split a cell and item, with no path!to!cell@ in it, it'll now return None for the cell, instead causing a ValueError when trying to split the result. Change-Id: I228b9f3b0f63f8c7a6004b3206f5312ed2a878bc Fixes: bug #1153841
This commit is contained in:
@@ -277,12 +277,11 @@ class CellsManager(manager.Manager):
|
||||
if host is None:
|
||||
cell_name = None
|
||||
else:
|
||||
result = cells_utils.split_cell_and_item(host)
|
||||
cell_name = result[0]
|
||||
if len(result) > 1:
|
||||
host = result[1]
|
||||
else:
|
||||
host = None
|
||||
cell_name, host = cells_utils.split_cell_and_item(host)
|
||||
# If no cell name was given, assume that the host name is the
|
||||
# cell_name and that the target is all hosts
|
||||
if cell_name is None:
|
||||
cell_name, host = host, cell_name
|
||||
responses = self.msg_runner.task_log_get_all(ctxt, cell_name,
|
||||
task_name, period_beginning, period_ending,
|
||||
host=host, state=state)
|
||||
|
||||
@@ -56,12 +56,18 @@ def get_instances_to_sync(context, updated_since=None, project_id=None,
|
||||
|
||||
def cell_with_item(cell_name, item):
|
||||
"""Turn cell_name and item into <cell_name>@<item>."""
|
||||
if cell_name is None:
|
||||
return item
|
||||
return cell_name + _CELL_ITEM_SEP + str(item)
|
||||
|
||||
|
||||
def split_cell_and_item(cell_and_item):
|
||||
"""Split a combined cell@item and return them."""
|
||||
return cell_and_item.rsplit(_CELL_ITEM_SEP, 1)
|
||||
result = cell_and_item.rsplit(_CELL_ITEM_SEP, 1)
|
||||
if len(result) == 1:
|
||||
return (None, cell_and_item)
|
||||
else:
|
||||
return result
|
||||
|
||||
|
||||
def _add_cell_to_service(service, cell_name):
|
||||
|
||||
@@ -615,10 +615,7 @@ class HostAPI(compute_api.HostAPI):
|
||||
this call to cells, as we have instance information here in
|
||||
the API cell.
|
||||
"""
|
||||
try:
|
||||
cell_name, host_name = cells_utils.split_cell_and_item(host_name)
|
||||
except ValueError:
|
||||
cell_name = None
|
||||
cell_name, host_name = cells_utils.split_cell_and_item(host_name)
|
||||
instances = super(HostAPI, self).instance_get_all_by_host(context,
|
||||
host_name)
|
||||
if cell_name:
|
||||
|
||||
@@ -80,3 +80,26 @@ class CellsUtilsTestCase(test.TestCase):
|
||||
{'changes-since': 'fake-updated-since',
|
||||
'project_id': 'fake-project'})
|
||||
self.assertEqual(call_info['shuffle'], 2)
|
||||
|
||||
def test_split_cell_and_item(self):
|
||||
path = 'australia', 'queensland', 'gold_coast'
|
||||
cell = cells_utils._PATH_CELL_SEP.join(path)
|
||||
item = 'host_5'
|
||||
together = cells_utils.cell_with_item(cell, item)
|
||||
self.assertEqual(cells_utils._CELL_ITEM_SEP.join([cell, item]),
|
||||
together)
|
||||
|
||||
# Test normal usage
|
||||
result_cell, result_item = cells_utils.split_cell_and_item(together)
|
||||
self.assertEqual(cell, result_cell)
|
||||
self.assertEqual(item, result_item)
|
||||
|
||||
# Test with no cell
|
||||
cell = None
|
||||
together = cells_utils.cell_with_item(cell, item)
|
||||
self.assertEqual(item, together)
|
||||
print together
|
||||
result_cell, result_item = cells_utils.split_cell_and_item(together)
|
||||
print result_cell, result_item
|
||||
self.assertEqual(cell, result_cell)
|
||||
self.assertEqual(item, result_item)
|
||||
|
||||
Reference in New Issue
Block a user