diff options
| author | Matthew Sherborne <msherborne@gmail.com> | 2013-03-12 11:24:20 +1000 |
|---|---|---|
| committer | Matthew Sherborne <msherborne@gmail.com> | 2013-03-12 13:25:31 +1000 |
| commit | e4e0d37f8a487d562d95a1ab37b4a90d861eb1d5 (patch) | |
| tree | e3811a529df061c1d13ba8d12adb8d1ab97e482a | |
| parent | 782dd69de4c6661eeb889b4e5b3b1b8df9d228b6 (diff) | |
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
| -rw-r--r-- | nova/cells/manager.py | 11 | ||||
| -rw-r--r-- | nova/cells/utils.py | 8 | ||||
| -rw-r--r-- | nova/compute/cells_api.py | 5 | ||||
| -rw-r--r-- | nova/tests/cells/test_cells_utils.py | 23 |
4 files changed, 36 insertions, 11 deletions
diff --git a/nova/cells/manager.py b/nova/cells/manager.py index ec4bc447f..c08dfe835 100644 --- a/nova/cells/manager.py +++ b/nova/cells/manager.py @@ -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) diff --git a/nova/cells/utils.py b/nova/cells/utils.py index e9560969a..7c297e341 100644 --- a/nova/cells/utils.py +++ b/nova/cells/utils.py @@ -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): diff --git a/nova/compute/cells_api.py b/nova/compute/cells_api.py index d5a07490b..6f974f9c5 100644 --- a/nova/compute/cells_api.py +++ b/nova/compute/cells_api.py @@ -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: diff --git a/nova/tests/cells/test_cells_utils.py b/nova/tests/cells/test_cells_utils.py index 84f60a796..871df0372 100644 --- a/nova/tests/cells/test_cells_utils.py +++ b/nova/tests/cells/test_cells_utils.py @@ -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) |
