Make compute_node_statistics() work across cells

This makes us issue the stats call once per (non-cell0) cell and
summarize the results.

Related to blueprint cells-aware-api

Change-Id: I6a2782ce4a83df8d63bc4ef09b57ae8b5cfb7fbb
This commit is contained in:
Dan Smith 2017-06-13 11:27:27 -07:00
parent a43dbba2b8
commit 5fc1dfc0f4
2 changed files with 33 additions and 1 deletions

View File

@ -4629,7 +4629,21 @@ class HostAPI(base.Base):
return objects.ComputeNodeList(objects=computes)
def compute_node_statistics(self, context):
return self.db.compute_node_statistics(context)
load_cells()
cell_stats = []
for cell in CELLS:
if cell.uuid == objects.CellMapping.CELL0_UUID:
continue
with nova_context.target_cell(context, cell) as cctxt:
cell_stats.append(self.db.compute_node_statistics(cctxt))
if cell_stats:
keys = cell_stats[0].keys()
return {k: sum(stats[k] for stats in cell_stats)
for k in keys}
else:
return {}
class InstanceActionAPI(base.Base):

View File

@ -422,6 +422,20 @@ class ComputeHostAPITestCase(test.TestCase):
aggregate.id).hosts
self.assertEqual([], result)
@mock.patch('nova.db.compute_node_statistics')
def test_compute_node_statistics(self, mock_cns):
# Note this should only be called twice
mock_cns.side_effect = [
{'stat1': 1, 'stat2': 4.0},
{'stat1': 5, 'stat2': 1.2},
]
compute_api.CELLS = [objects.CellMapping(uuid=uuids.cell1),
objects.CellMapping(
uuid=objects.CellMapping.CELL0_UUID),
objects.CellMapping(uuid=uuids.cell2)]
stats = self.host_api.compute_node_statistics(self.ctxt)
self.assertEqual({'stat1': 6, 'stat2': 5.2}, stats)
class ComputeHostAPICellsTestCase(ComputeHostAPITestCase):
def setUp(self):
@ -579,3 +593,7 @@ class ComputeHostAPICellsTestCase(ComputeHostAPITestCase):
self.assertEqual('fake-response', result)
_do_test()
def test_compute_node_statistics(self):
# Not implementing cross-cellsv2 for cellsv1
pass