diff options
author | Zuul <zuul@review.openstack.org> | 2019-03-15 06:09:59 +0000 |
---|---|---|
committer | Gerrit Code Review <review@openstack.org> | 2019-03-15 06:09:59 +0000 |
commit | e607a3e3db2bef5b48f214816c4824978e19fd63 (patch) | |
tree | 970c4b09e4827831a5ede0d87618c4cc71b825ec /ironic | |
parent | d1fdf64313c0cd398554e3ff5d4572a7667974b5 (diff) | |
parent | b5d44d3aaf9bff8ac3224a820cbe6514ca506e56 (diff) | |
download | ironic-e607a3e3db2bef5b48f214816c4824978e19fd63.tar.gz |
Merge "Make metrics usable"
Diffstat (limited to 'ironic')
-rw-r--r-- | ironic/conductor/manager.py | 15 | ||||
-rw-r--r-- | ironic/tests/unit/conductor/test_manager.py | 20 |
2 files changed, 31 insertions, 4 deletions
diff --git a/ironic/conductor/manager.py b/ironic/conductor/manager.py index 8a453c51b..0d32eadaf 100644 --- a/ironic/conductor/manager.py +++ b/ironic/conductor/manager.py @@ -2832,8 +2832,7 @@ class ConductorManager(base_manager.BaseConductorManager): message = {'message_id': uuidutils.generate_uuid(), 'instance_uuid': instance_uuid, 'node_uuid': node_uuid, - 'timestamp': datetime.datetime.utcnow(), - 'event_type': 'hardware.ipmi.metrics.update'} + 'timestamp': datetime.datetime.utcnow()} try: lock_purpose = 'getting sensors data' @@ -2846,6 +2845,16 @@ class ConductorManager(base_manager.BaseConductorManager): '%s as it is in maintenance mode', task.node.uuid) continue + # Add the node name, as the name would be hand for other + # notifier plugins + message['node_name'] = task.node.name + # We should convey the proper hardware type, + # which previously was hard coded to ipmi, but other + # drivers were transmitting other values under the + # guise of ipmi. + ev_type = 'hardware.{driver}.metrics'.format( + driver=task.node.driver) + message['event_type'] = ev_type + '.update' task.driver.management.validate(task) sensors_data = task.driver.management.get_sensors_data( @@ -2879,7 +2888,7 @@ class ConductorManager(base_manager.BaseConductorManager): self._filter_out_unsupported_types(sensors_data)) if message['payload']: self.sensors_notifier.info( - context, "hardware.ipmi.metrics", message) + context, ev_type, message) finally: # Yield on every iteration eventlet.sleep(0) diff --git a/ironic/tests/unit/conductor/test_manager.py b/ironic/tests/unit/conductor/test_manager.py index e99a156cf..79fdca061 100644 --- a/ironic/tests/unit/conductor/test_manager.py +++ b/ironic/tests/unit/conductor/test_manager.py @@ -5592,8 +5592,9 @@ class SensorsTestCase(mgr_utils.ServiceSetUpMixin, db_base.DbTestCase): expected_result = {} self.assertEqual(expected_result, actual_result) + @mock.patch.object(messaging.Notifier, 'info', autospec=True) @mock.patch.object(task_manager, 'acquire') - def test_send_sensor_task(self, acquire_mock): + def test_send_sensor_task(self, acquire_mock, notifier_mock): nodes = queue.Queue() for i in range(5): nodes.put_nowait(('fake_uuid-%d' % i, 'fake-hardware', '', None)) @@ -5602,6 +5603,8 @@ class SensorsTestCase(mgr_utils.ServiceSetUpMixin, db_base.DbTestCase): task = acquire_mock.return_value.__enter__.return_value task.node.maintenance = False + task.node.driver = 'fake' + task.node.name = 'fake_node' get_sensors_data_mock = task.driver.management.get_sensors_data validate_mock = task.driver.management.validate get_sensors_data_mock.return_value = 'fake-sensor-data' @@ -5609,6 +5612,21 @@ class SensorsTestCase(mgr_utils.ServiceSetUpMixin, db_base.DbTestCase): self.assertEqual(5, acquire_mock.call_count) self.assertEqual(5, validate_mock.call_count) self.assertEqual(5, get_sensors_data_mock.call_count) + self.assertEqual(5, notifier_mock.call_count) + if six.PY2: + # bail out if python2 as matching fails to match the + # data structure becasue it requires the order to be consistent + # but the mock also records the call dictionary contents in + # random order changing with every invocation. :\ + return + n_call = mock.call(mock.ANY, mock.ANY, 'hardware.fake.metrics', + {'event_type': 'hardware.fake.metrics.update', + 'node_name': 'fake_node', 'timestamp': mock.ANY, + 'message_id': mock.ANY, + 'payload': 'fake-sensor-data', + 'node_uuid': mock.ANY, 'instance_uuid': None}) + notifier_mock.assert_has_calls([n_call, n_call, n_call, + n_call, n_call]) @mock.patch.object(task_manager, 'acquire') def test_send_sensor_task_shutdown(self, acquire_mock): |