summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2017-06-14 22:49:15 +0000
committerGerrit Code Review <review@openstack.org>2017-06-14 22:49:15 +0000
commit28769f999041ac1d4b24a2a34d23575b12a6291f (patch)
tree08241acf5955be7f6d8e5f365c60a931df554bf9
parenteaec381d53508ccc15f5736dd550450f783447f5 (diff)
parent5fc1dfc0f468fd24ecbdbe967d422c05e7add1a5 (diff)
Merge "Make compute_node_statistics() work across cells"
-rw-r--r--nova/compute/api.py16
-rw-r--r--nova/tests/unit/compute/test_host_api.py18
2 files changed, 33 insertions, 1 deletions
diff --git a/nova/compute/api.py b/nova/compute/api.py
index 4d364b2..9f22532 100644
--- a/nova/compute/api.py
+++ b/nova/compute/api.py
@@ -4638,7 +4638,21 @@ class HostAPI(base.Base):
4638 return objects.ComputeNodeList(objects=computes) 4638 return objects.ComputeNodeList(objects=computes)
4639 4639
4640 def compute_node_statistics(self, context): 4640 def compute_node_statistics(self, context):
4641 return self.db.compute_node_statistics(context) 4641 load_cells()
4642
4643 cell_stats = []
4644 for cell in CELLS:
4645 if cell.uuid == objects.CellMapping.CELL0_UUID:
4646 continue
4647 with nova_context.target_cell(context, cell) as cctxt:
4648 cell_stats.append(self.db.compute_node_statistics(cctxt))
4649
4650 if cell_stats:
4651 keys = cell_stats[0].keys()
4652 return {k: sum(stats[k] for stats in cell_stats)
4653 for k in keys}
4654 else:
4655 return {}
4642 4656
4643 4657
4644class InstanceActionAPI(base.Base): 4658class InstanceActionAPI(base.Base):
diff --git a/nova/tests/unit/compute/test_host_api.py b/nova/tests/unit/compute/test_host_api.py
index 02c7fe3..c337dcf 100644
--- a/nova/tests/unit/compute/test_host_api.py
+++ b/nova/tests/unit/compute/test_host_api.py
@@ -422,6 +422,20 @@ class ComputeHostAPITestCase(test.TestCase):
422 aggregate.id).hosts 422 aggregate.id).hosts
423 self.assertEqual([], result) 423 self.assertEqual([], result)
424 424
425 @mock.patch('nova.db.compute_node_statistics')
426 def test_compute_node_statistics(self, mock_cns):
427 # Note this should only be called twice
428 mock_cns.side_effect = [
429 {'stat1': 1, 'stat2': 4.0},
430 {'stat1': 5, 'stat2': 1.2},
431 ]
432 compute_api.CELLS = [objects.CellMapping(uuid=uuids.cell1),
433 objects.CellMapping(
434 uuid=objects.CellMapping.CELL0_UUID),
435 objects.CellMapping(uuid=uuids.cell2)]
436 stats = self.host_api.compute_node_statistics(self.ctxt)
437 self.assertEqual({'stat1': 6, 'stat2': 5.2}, stats)
438
425 439
426class ComputeHostAPICellsTestCase(ComputeHostAPITestCase): 440class ComputeHostAPICellsTestCase(ComputeHostAPITestCase):
427 def setUp(self): 441 def setUp(self):
@@ -579,3 +593,7 @@ class ComputeHostAPICellsTestCase(ComputeHostAPITestCase):
579 self.assertEqual('fake-response', result) 593 self.assertEqual('fake-response', result)
580 594
581 _do_test() 595 _do_test()
596
597 def test_compute_node_statistics(self):
598 # Not implementing cross-cellsv2 for cellsv1
599 pass