From 6ccfb45d2f9f829cfca1a2621131ca237fbf0e25 Mon Sep 17 00:00:00 2001 From: Matt Riedemann Date: Mon, 18 Sep 2017 15:30:18 -0400 Subject: [PATCH] Account for compute.metrics.update in legacy notification whitelist The compute.metrics.update legacy unversioned notification was missing from the whitelist because the only test for it was mocking out the rpc notifier call, which is what validates the entries in the whitelist. This adds the entry to the whitelist and fixes the test to actually use the notifier code. Change-Id: Ie278ca58c371b8e3bd4861e6c86ebcf30c6778ea Closes-Bug: #1717943 --- nova/rpc.py | 1 + nova/tests/unit/compute/test_resource_tracker.py | 23 ++++++++++++++++++----- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/nova/rpc.py b/nova/rpc.py index 6d5e413..6caef9d 100644 --- a/nova/rpc.py +++ b/nova/rpc.py @@ -338,6 +338,7 @@ class LegacyValidatingNotifier(object): 'compute.instance.volume.attach', 'compute.instance.volume.detach', 'compute.libvirt.error', + 'compute.metrics.update', 'compute_task.build_instances', 'compute_task.migrate_server', 'compute_task.rebuild_server', diff --git a/nova/tests/unit/compute/test_resource_tracker.py b/nova/tests/unit/compute/test_resource_tracker.py index bf85205..724adc7 100644 --- a/nova/tests/unit/compute/test_resource_tracker.py +++ b/nova/tests/unit/compute/test_resource_tracker.py @@ -33,6 +33,7 @@ from nova.objects import pci_device from nova.pci import manager as pci_manager from nova.scheduler import utils as sched_utils from nova import test +from nova.tests.unit import fake_notifier from nova.tests.unit.objects import test_pci_device as fake_pci_device from nova.tests import uuidsentinel as uuids @@ -2664,8 +2665,10 @@ class ComputeMonitorTestCase(BaseTestCase): u'Cannot get the metrics from %(mon)s; error: %(exc)s', mock.ANY) self.assertEqual(0, len(metrics)) - @mock.patch('nova.rpc.get_notifier') - def test_get_host_metrics(self, rpc_mock): + def test_get_host_metrics(self): + fake_notifier.stub_notifier(self) + self.addCleanup(fake_notifier.reset) + class FakeCPUMonitor(monitor_base.MonitorBase): NOW_TS = timeutils.utcnow() @@ -2688,7 +2691,6 @@ class ComputeMonitorTestCase(BaseTestCase): self.rt.monitors = [FakeCPUMonitor(None)] metrics = self.rt._get_host_metrics(self.context, _NODENAME) - rpc_mock.assert_called_once_with(service='compute', host=_NODENAME) expected_metrics = [ { @@ -2706,8 +2708,19 @@ class ComputeMonitorTestCase(BaseTestCase): 'nodename': _NODENAME, } - rpc_mock.return_value.info.assert_called_once_with( - self.context, 'compute.metrics.update', payload) + self.assertEqual(1, len(fake_notifier.NOTIFICATIONS)) + msg = fake_notifier.NOTIFICATIONS[0] + self.assertEqual('compute.metrics.update', msg.event_type) + for p_key in payload: + if p_key == 'metrics': + self.assertIn(p_key, msg.payload) + self.assertEqual(1, len(msg.payload['metrics'])) + # make sure the expected metrics match the actual metrics + for m_key in expected_metrics[0]: + self.assertEqual(expected_metrics[0][m_key], + msg.payload['metrics'][0][m_key]) + else: + self.assertEqual(payload[p_key], msg.payload[p_key]) self.assertEqual(metrics, expected_metrics) -- 2.7.4