diff --git a/ironic/conductor/manager.py b/ironic/conductor/manager.py index 0f8c37f5ce..b44165fb63 100644 --- a/ironic/conductor/manager.py +++ b/ironic/conductor/manager.py @@ -2188,6 +2188,13 @@ class ConductorManager(base_manager.BaseConductorManager): purpose=lock_purpose) as task: if not getattr(task.driver, 'management', None): continue + + if task.node.maintenance: + LOG.debug('Skipping sending sensors data for node ' + '%s as it is in maintenance mode', + task.node.uuid) + continue + task.driver.management.validate(task) sensors_data = task.driver.management.get_sensors_data( task) diff --git a/ironic/tests/unit/conductor/test_manager.py b/ironic/tests/unit/conductor/test_manager.py index a19b62bd34..9dc72d1a36 100644 --- a/ironic/tests/unit/conductor/test_manager.py +++ b/ironic/tests/unit/conductor/test_manager.py @@ -3601,7 +3601,9 @@ class UpdatePortTestCase(mgr_utils.ServiceSetUpMixin, db_base.DbTestCase): self._start_service() CONF.set_override('send_sensor_data', True, group='conductor') - acquire_mock.return_value.__enter__.return_value.driver = self.driver + task = acquire_mock.return_value.__enter__.return_value + task.driver = self.driver + task.node.maintenance = False with mock.patch.object(self.driver.management, 'get_sensors_data') as get_sensors_data_mock: with mock.patch.object(self.driver.management, @@ -3632,7 +3634,9 @@ class UpdatePortTestCase(mgr_utils.ServiceSetUpMixin, db_base.DbTestCase): self._start_service() self.driver.management = None - acquire_mock.return_value.__enter__.return_value.driver = self.driver + task = acquire_mock.return_value.__enter__.return_value + task.driver = self.driver + task.node.maintenance = False with mock.patch.object(fake.FakeManagement, 'get_sensors_data', autospec=True) as get_sensors_data_mock: @@ -3644,6 +3648,27 @@ class UpdatePortTestCase(mgr_utils.ServiceSetUpMixin, db_base.DbTestCase): self.assertFalse(get_sensors_data_mock.called) self.assertFalse(validate_mock.called) + @mock.patch.object(manager.LOG, 'debug', autospec=True) + @mock.patch.object(task_manager, 'acquire', autospec=True) + def test_send_sensor_task_maintenance(self, acquire_mock, debug_log): + nodes = queue.Queue() + nodes.put_nowait(('fake_uuid', 'fake', None)) + self._start_service() + CONF.set_override('send_sensor_data', True, group='conductor') + + task = acquire_mock.return_value.__enter__.return_value + task.driver = self.driver + task.node.maintenance = True + with mock.patch.object(self.driver.management, + 'get_sensors_data') as get_sensors_data_mock: + with mock.patch.object(self.driver.management, + 'validate') as validate_mock: + self.service._sensors_nodes_task(self.context, nodes) + self.assertTrue(acquire_mock.called) + self.assertFalse(validate_mock.called) + self.assertFalse(get_sensors_data_mock.called) + self.assertTrue(debug_log.called) + @mock.patch.object(manager.ConductorManager, '_spawn_worker') @mock.patch.object(manager.ConductorManager, '_mapped_to_this_conductor') @mock.patch.object(dbapi.IMPL, 'get_nodeinfo_list') diff --git a/releasenotes/notes/no-sensors-in-maintenance-7a0ecf418336d105.yaml b/releasenotes/notes/no-sensors-in-maintenance-7a0ecf418336d105.yaml new file mode 100644 index 0000000000..a2b55b2b93 --- /dev/null +++ b/releasenotes/notes/no-sensors-in-maintenance-7a0ecf418336d105.yaml @@ -0,0 +1,4 @@ +--- +fixes: + - No longer tries to collect or report sensors data for nodes in maintenance + mode. See `bug 1652741 `_.