Merge "Make compute_node_statistics() work across cells"

This commit is contained in:
Jenkins 2017-06-14 22:49:15 +00:00 committed by Gerrit Code Review
commit 28769f9990
2 changed files with 33 additions and 1 deletions

View File

@ -4638,7 +4638,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