From af7c6c4c2411627885ea65095c400a8c658cb3d4 Mon Sep 17 00:00:00 2001 From: Zenghui Shi Date: Mon, 14 May 2018 13:45:55 +0800 Subject: [PATCH] Change exception msg of BIOS caching Indicate the continuation of cleaning steps in BIOS caching exception msg. Fix the unit test coverage for test__do_node_clean_cache_bios. This is a follow-up patch to address outstanding comments in d01715321a484c24767f64edf77514b9609c279c Change-Id: Ic7c61ce68319808ea7194fa8c656598a91b4394c Story: #1712032 --- ironic/conductor/manager.py | 3 +- ironic/tests/unit/conductor/test_manager.py | 40 ++++++++++++++++----- 2 files changed, 33 insertions(+), 10 deletions(-) diff --git a/ironic/conductor/manager.py b/ironic/conductor/manager.py index f6266c129c..5c878f53da 100644 --- a/ironic/conductor/manager.py +++ b/ironic/conductor/manager.py @@ -1190,7 +1190,8 @@ class ConductorManager(base_manager.BaseConductorManager): try: task.driver.bios.cache_bios_settings(task) except Exception as e: - msg = (_('Caching of bios settings failed on node %(node)s.') + msg = (_('Caching of bios settings failed on node %(node)s. ' + 'Continuing with node cleaning.') % {'node': node.uuid}) LOG.exception(msg) diff --git a/ironic/tests/unit/conductor/test_manager.py b/ironic/tests/unit/conductor/test_manager.py index 03833859dd..28fd343996 100644 --- a/ironic/tests/unit/conductor/test_manager.py +++ b/ironic/tests/unit/conductor/test_manager.py @@ -2420,33 +2420,55 @@ class DoNodeCleanTestCase(mgr_utils.ServiceSetUpMixin, db_base.DbTestCase): def test__do_node_clean_manual_network_validate_fail(self, mock_validate): self.__do_node_clean_validate_fail(mock_validate, clean_steps=[]) + @mock.patch.object(manager, 'LOG', autospec=True) + @mock.patch.object(conductor_utils, 'set_node_cleaning_steps') + @mock.patch('ironic.conductor.manager.ConductorManager.' + '_do_next_clean_step') + @mock.patch('ironic.drivers.modules.fake.FakeDeploy.prepare_cleaning') @mock.patch('ironic.drivers.modules.network.flat.FlatNetwork.validate') @mock.patch('ironic.drivers.modules.fake.FakeBIOS.cache_bios_settings') - def test__do_node_clean_cache_bios(self, mock_bios, mock_validate, - clean_steps=None): + def _test__do_node_clean_cache_bios(self, mock_bios, mock_validate, + mock_prep, mock_next_step, mock_steps, + mock_log, clean_steps=None, + enable_exception=False): + if enable_exception: + mock_bios.side_effect = exception.IronicException('test') + mock_prep.return_value = states.NOSTATE tgt_prov_state = states.MANAGEABLE if clean_steps else states.AVAILABLE node = obj_utils.create_test_node( - self.context, driver='fake', + self.context, driver='fake-hardware', provision_state=states.CLEANING, target_provision_state=tgt_prov_state) with task_manager.acquire( self.context, node.uuid, shared=False) as task: self.service._do_node_clean(task, clean_steps=clean_steps) node.refresh() - self.assertFalse(mock_bios.called) + mock_bios.assert_called_once_with(task) if clean_steps: - self.assertEqual(states.CLEANFAIL, node.provision_state) + self.assertEqual(states.CLEANING, node.provision_state) self.assertEqual(tgt_prov_state, node.target_provision_state) else: - self.assertEqual(states.AVAILABLE, node.provision_state) - self.assertEqual(states.NOSTATE, node.target_provision_state) + self.assertEqual(states.CLEANING, node.provision_state) + self.assertEqual(states.AVAILABLE, node.target_provision_state) mock_validate.assert_called_once_with(task) + if enable_exception: + mock_log.exception.assert_called_once_with( + 'Caching of bios settings failed on node {}. ' + 'Continuing with node cleaning.' + .format(node.uuid)) def test__do_node_clean_manual_cache_bios(self): - self.test__do_node_clean_cache_bios(clean_steps=[self.deploy_raid]) + self._test__do_node_clean_cache_bios(clean_steps=[self.deploy_raid]) def test__do_node_clean_automated_cache_bios(self): - self.test__do_node_clean_cache_bios() + self._test__do_node_clean_cache_bios() + + def test__do_node_clean_manual_cache_bios_exception(self): + self._test__do_node_clean_cache_bios(clean_steps=[self.deploy_raid], + enable_exception=True) + + def test__do_node_clean_automated_cache_bios_exception(self): + self._test__do_node_clean_cache_bios(enable_exception=True) @mock.patch('ironic.drivers.modules.fake.FakePower.validate') def test__do_node_clean_automated_disabled(self, mock_validate):