From 8fff98a6f95ce4bd14e562ec69951680b8a12ac3 Mon Sep 17 00:00:00 2001 From: Shivanand Tendulker Date: Tue, 25 Aug 2020 07:04:29 -0400 Subject: [PATCH] Enforce autospec in ilo tests And remove corresponding filter in tox.ini Change-Id: Ib47a5894d7b05346726c5b8ae8668dc8512cc322 --- .../unit/drivers/modules/ilo/test_bios.py | 9 ++-- .../modules/ilo/test_firmware_processor.py | 2 +- .../drivers/modules/ilo/test_management.py | 25 +++++----- .../unit/drivers/modules/ilo/test_power.py | 16 +++---- .../unit/drivers/modules/ilo/test_raid.py | 47 ++++++++++++------- tox.ini | 1 - 6 files changed, 56 insertions(+), 44 deletions(-) diff --git a/ironic/tests/unit/drivers/modules/ilo/test_bios.py b/ironic/tests/unit/drivers/modules/ilo/test_bios.py index b65df2f88b..806ef09031 100644 --- a/ironic/tests/unit/drivers/modules/ilo/test_bios.py +++ b/ironic/tests/unit/drivers/modules/ilo/test_bios.py @@ -601,10 +601,11 @@ class IloBiosTestCase(test_common.BaseIloTest): self.node.save() self._test__execute_post_boot_bios_get_settings_failed() - @mock.patch.object(objects.BIOSSettingList, 'create') - @mock.patch.object(objects.BIOSSettingList, 'save') - @mock.patch.object(objects.BIOSSettingList, 'delete') - @mock.patch.object(objects.BIOSSettingList, 'sync_node_setting') + @mock.patch.object(objects.BIOSSettingList, 'create', autospec=True) + @mock.patch.object(objects.BIOSSettingList, 'save', autospec=True) + @mock.patch.object(objects.BIOSSettingList, 'delete', autospec=True) + @mock.patch.object(objects.BIOSSettingList, 'sync_node_setting', + autospec=True) @mock.patch.object(ilo_common, 'get_ilo_object', autospec=True) def test_cache_bios_settings(self, get_ilo_object_mock, sync_node_mock, delete_mock, save_mock, create_mock): diff --git a/ironic/tests/unit/drivers/modules/ilo/test_firmware_processor.py b/ironic/tests/unit/drivers/modules/ilo/test_firmware_processor.py index 2182e2b9a6..b944ef7d30 100644 --- a/ironic/tests/unit/drivers/modules/ilo/test_firmware_processor.py +++ b/ironic/tests/unit/drivers/modules/ilo/test_firmware_processor.py @@ -177,7 +177,7 @@ class FirmwareProcessorTestCase(base.TestCase): self.assertEqual(ret_val, result) - @mock.patch.object(ilo_fw_processor, 'LOG') + @mock.patch.object(ilo_fw_processor, 'LOG', autospec=True) def test__validate_sum_components_fails(self, LOG_mock): components = ['INVALID'] diff --git a/ironic/tests/unit/drivers/modules/ilo/test_management.py b/ironic/tests/unit/drivers/modules/ilo/test_management.py index 26b6830581..684c50c362 100644 --- a/ironic/tests/unit/drivers/modules/ilo/test_management.py +++ b/ironic/tests/unit/drivers/modules/ilo/test_management.py @@ -388,7 +388,7 @@ class IloManagementTestCase(test_common.BaseIloTest): spec_set=True, autospec=True) @mock.patch.object(ilo_boot.IloVirtualMediaBoot, 'prepare_ramdisk', spec_set=True, autospec=True) - @mock.patch.object(ilo_management, 'LOG') + @mock.patch.object(ilo_management, 'LOG', autospec=True) @mock.patch.object(ilo_management, '_execute_ilo_step', spec_set=True, autospec=True) @mock.patch.object(ilo_management.firmware_processor, 'FirmwareProcessor', @@ -621,7 +621,7 @@ class IloManagementTestCase(test_common.BaseIloTest): self.node.save() self._test_update_firmware_throws_error_for_invalid_component_type() - @mock.patch.object(ilo_management, 'LOG') + @mock.patch.object(ilo_management, 'LOG', autospec=True) @mock.patch.object(ilo_management.firmware_processor.FirmwareProcessor, 'process_fw_on', spec_set=True, autospec=True) def _test_update_firmware_throws_error_for_checksum_validation_error( @@ -744,7 +744,7 @@ class IloManagementTestCase(test_common.BaseIloTest): self.node.save() self._test_update_firmware_doesnt_update_any_if_any_url_fails() - @mock.patch.object(ilo_management, 'LOG') + @mock.patch.object(ilo_management, 'LOG', autospec=True) @mock.patch.object(ilo_management, '_execute_ilo_step', spec_set=True, autospec=True) @mock.patch.object(ilo_management.firmware_processor, 'FirmwareProcessor', @@ -983,7 +983,7 @@ class IloManagementTestCase(test_common.BaseIloTest): self._test_write_firmware_sum_mode_invalid_component( step_type='deploy') - @mock.patch.object(driver_utils, 'store_ramdisk_logs') + @mock.patch.object(driver_utils, 'store_ramdisk_logs', autospec=True) def _test__write_firmware_sum_final_with_logs(self, store_mock, step_type='clean'): self.config(deploy_logs_collect='always', group='agent') @@ -1028,7 +1028,7 @@ class IloManagementTestCase(test_common.BaseIloTest): def test__write_firmware_sum_final_with_logs_deploy(self): self._test__write_firmware_sum_final_with_logs(step_type='deploy') - @mock.patch.object(driver_utils, 'store_ramdisk_logs') + @mock.patch.object(driver_utils, 'store_ramdisk_logs', autospec=True) def _test__write_firmware_sum_final_without_logs(self, store_mock, step_type='clean'): self.config(deploy_logs_collect='on_failure', group='agent') @@ -1068,7 +1068,7 @@ class IloManagementTestCase(test_common.BaseIloTest): self._test__write_firmware_sum_final_without_logs(step_type='deploy') @mock.patch.object(ilo_management, 'LOG', spec_set=True, autospec=True) - @mock.patch.object(driver_utils, 'store_ramdisk_logs') + @mock.patch.object(driver_utils, 'store_ramdisk_logs', autospec=True) def _test__write_firmware_sum_final_swift_error(self, store_mock, log_mock, step_type='clean'): @@ -1114,7 +1114,7 @@ class IloManagementTestCase(test_common.BaseIloTest): self._test__write_firmware_sum_final_swift_error(step_type='deploy') @mock.patch.object(ilo_management, 'LOG', spec_set=True, autospec=True) - @mock.patch.object(driver_utils, 'store_ramdisk_logs') + @mock.patch.object(driver_utils, 'store_ramdisk_logs', autospec=True) def _test__write_firmware_sum_final_environment_error(self, store_mock, log_mock, step_type='clean'): @@ -1162,7 +1162,7 @@ class IloManagementTestCase(test_common.BaseIloTest): step_type='deploy') @mock.patch.object(ilo_management, 'LOG', spec_set=True, autospec=True) - @mock.patch.object(driver_utils, 'store_ramdisk_logs') + @mock.patch.object(driver_utils, 'store_ramdisk_logs', autospec=True) def _test__write_firmware_sum_final_unknown_exception(self, store_mock, log_mock, step_type='clean'): @@ -1584,7 +1584,7 @@ class Ilo5ManagementTestCase(db_base.DbTestCase): self.assertEqual(states.CLEANWAIT, result) mock_power.assert_called_once_with(task, states.REBOOT) - @mock.patch.object(ilo_management.LOG, 'info') + @mock.patch.object(ilo_management.LOG, 'info', autospec=True) @mock.patch.object(ilo_management.Ilo5Management, '_wait_for_disk_erase_status', autospec=True) @mock.patch.object(ilo_common, 'get_ilo_object', autospec=True) @@ -1634,7 +1634,7 @@ class Ilo5ManagementTestCase(db_base.DbTestCase): self.assertEqual(states.CLEANWAIT, result) mock_power.assert_called_once_with(task, states.REBOOT) - @mock.patch.object(ilo_management.LOG, 'info') + @mock.patch.object(ilo_management.LOG, 'info', autospec=True) @mock.patch.object(ilo_common, 'get_ilo_object', autospec=True) def test_erase_devices_when_no_drive_available( self, ilo_mock, log_mock): @@ -1670,7 +1670,8 @@ class Ilo5ManagementTestCase(db_base.DbTestCase): task, erase_pattern={'ssd': 'xyz'}) @mock.patch.object(ilo_common, 'get_ilo_object', autospec=True) - @mock.patch.object(ilo_management.Ilo5Management, '_set_clean_failed') + @mock.patch.object(ilo_management.Ilo5Management, '_set_clean_failed', + autospec=True) def test_erase_devices_hdd_ilo_error(self, set_clean_failed_mock, ilo_mock): ilo_mock_object = ilo_mock.return_value @@ -1691,4 +1692,4 @@ class Ilo5ManagementTestCase(db_base.DbTestCase): self.assertNotIn('skip_current_clean_step', task.node.driver_internal_info) set_clean_failed_mock.assert_called_once_with( - task, exc) + mock.ANY, task, exc) diff --git a/ironic/tests/unit/drivers/modules/ilo/test_power.py b/ironic/tests/unit/drivers/modules/ilo/test_power.py index ded22bd6c1..e7e264418e 100644 --- a/ironic/tests/unit/drivers/modules/ilo/test_power.py +++ b/ironic/tests/unit/drivers/modules/ilo/test_power.py @@ -141,7 +141,7 @@ class IloPowerInternalMethodsTestCase(test_common.BaseIloTest): get_post_mock.assert_called_with(task.node) ilo_mock_object.set_host_power.assert_called_once_with('ON') - @mock.patch.object(ilo_power.LOG, 'info') + @mock.patch.object(ilo_power.LOG, 'info', autospec=True) @mock.patch.object(ilo_power, '_attach_boot_iso_if_needed', spec_set=True, autospec=True) @mock.patch.object(ilo_common, 'get_server_post_state', spec_set=True, @@ -169,7 +169,7 @@ class IloPowerInternalMethodsTestCase(test_common.BaseIloTest): {'state': 'soft rebooting', 'node_id': task.node.uuid, 'time_consumed': 2}) - @mock.patch.object(ilo_power.LOG, 'info') + @mock.patch.object(ilo_power.LOG, 'info', autospec=True) @mock.patch.object(ilo_power, '_attach_boot_iso_if_needed', spec_set=True, autospec=True) @mock.patch.object(ilo_common, 'get_server_post_state', spec_set=True, @@ -195,7 +195,7 @@ class IloPowerInternalMethodsTestCase(test_common.BaseIloTest): {'state': 'power on', 'node_id': task.node.uuid, 'time_consumed': 1}) - @mock.patch.object(ilo_power.LOG, 'info') + @mock.patch.object(ilo_power.LOG, 'info', autospec=True) @mock.patch.object(ilo_power, '_attach_boot_iso_if_needed', spec_set=True, autospec=True) @mock.patch.object(ilo_common, 'get_server_post_state', spec_set=True, @@ -219,7 +219,7 @@ class IloPowerInternalMethodsTestCase(test_common.BaseIloTest): self.assertFalse(attach_boot_iso_mock.called) self.assertFalse(log_mock.called) - @mock.patch.object(ilo_power.LOG, 'info') + @mock.patch.object(ilo_power.LOG, 'info', autospec=True) @mock.patch.object(ilo_power, '_attach_boot_iso_if_needed', spec_set=True, autospec=True) @mock.patch.object(ilo_common, 'get_server_post_state', spec_set=True, @@ -247,7 +247,7 @@ class IloPowerInternalMethodsTestCase(test_common.BaseIloTest): attach_boot_iso_mock.assert_called_once_with(task) self.assertFalse(log_mock.called) - @mock.patch.object(ilo_power.LOG, 'info') + @mock.patch.object(ilo_power.LOG, 'info', autospec=True) @mock.patch.object(ilo_power, '_attach_boot_iso_if_needed', spec_set=True, autospec=True) @mock.patch.object(ilo_common, 'get_server_post_state', spec_set=True, @@ -273,7 +273,7 @@ class IloPowerInternalMethodsTestCase(test_common.BaseIloTest): attach_boot_iso_mock.assert_called_once_with(task) self.assertFalse(log_mock.called) - @mock.patch.object(ilo_power.LOG, 'info') + @mock.patch.object(ilo_power.LOG, 'info', autospec=True) @mock.patch.object(ilo_common, 'get_server_post_state', spec_set=True, autospec=True) def test__set_power_state_soft_power_off_ok( @@ -294,7 +294,7 @@ class IloPowerInternalMethodsTestCase(test_common.BaseIloTest): {'state': 'soft power off', 'node_id': task.node.uuid, 'time_consumed': 2}) - @mock.patch.object(ilo_power.LOG, 'info') + @mock.patch.object(ilo_power.LOG, 'info', autospec=True) @mock.patch.object(ilo_common, 'get_server_post_state', spec_set=True, autospec=True) def test__set_power_state_soft_power_off_fail( @@ -314,7 +314,7 @@ class IloPowerInternalMethodsTestCase(test_common.BaseIloTest): self.assertFalse(get_post_mock.called) self.assertFalse(log_mock.called) - @mock.patch.object(ilo_power.LOG, 'info') + @mock.patch.object(ilo_power.LOG, 'info', autospec=True) @mock.patch.object(ilo_common, 'get_server_post_state', spec_set=True, autospec=True) def test__set_power_state_soft_power_off_timeout( diff --git a/ironic/tests/unit/drivers/modules/ilo/test_raid.py b/ironic/tests/unit/drivers/modules/ilo/test_raid.py index 6485b5d1e9..4865e5664c 100644 --- a/ironic/tests/unit/drivers/modules/ilo/test_raid.py +++ b/ironic/tests/unit/drivers/modules/ilo/test_raid.py @@ -136,8 +136,9 @@ class Ilo5RAIDTestCase(db_base.DbTestCase): self.node.save() self._test__prepare_for_read_raid_delete_raid() - @mock.patch.object(ilo_raid.Ilo5RAID, '_prepare_for_read_raid') - @mock.patch.object(raid, 'filter_target_raid_config') + @mock.patch.object(ilo_raid.Ilo5RAID, '_prepare_for_read_raid', + autospec=True) + @mock.patch.object(raid, 'filter_target_raid_config', autospec=True) @mock.patch.object(ilo_common, 'get_ilo_object', autospec=True) def _test_create_configuration( self, ilo_mock, filter_target_raid_config_mock, prepare_raid_mock): @@ -146,7 +147,8 @@ class Ilo5RAIDTestCase(db_base.DbTestCase): filter_target_raid_config_mock.return_value = ( self.target_raid_config) result = task.driver.raid.create_configuration(task) - prepare_raid_mock.assert_called_once_with(task, 'create_raid') + prepare_raid_mock.assert_called_once_with( + mock.ANY, task, 'create_raid') if task.node.clean_step: self.assertEqual(states.CLEANWAIT, result) else: @@ -167,7 +169,7 @@ class Ilo5RAIDTestCase(db_base.DbTestCase): self._test_create_configuration() @mock.patch.object(raid, 'update_raid_info', autospec=True) - @mock.patch.object(raid, 'filter_target_raid_config') + @mock.patch.object(raid, 'filter_target_raid_config', autospec=True) @mock.patch.object(ilo_common, 'get_ilo_object', autospec=True) def _test_create_configuration_with_read_raid( self, ilo_mock, filter_target_raid_config_mock, update_raid_mock): @@ -215,7 +217,7 @@ class Ilo5RAIDTestCase(db_base.DbTestCase): self.node.save() self._test_create_configuration_with_read_raid() - @mock.patch.object(raid, 'filter_target_raid_config') + @mock.patch.object(raid, 'filter_target_raid_config', autospec=True) @mock.patch.object(ilo_common, 'get_ilo_object', autospec=True) def _test_create_configuration_with_read_raid_failed( self, ilo_mock, filter_target_raid_config_mock): @@ -257,7 +259,7 @@ class Ilo5RAIDTestCase(db_base.DbTestCase): self.node.save() self._test_create_configuration_with_read_raid_failed() - @mock.patch.object(raid, 'filter_target_raid_config') + @mock.patch.object(raid, 'filter_target_raid_config', autospec=True) @mock.patch.object(ilo_common, 'get_ilo_object', autospec=True) def _test_create_configuration_empty_target_raid_config( self, ilo_mock, filter_target_raid_config_mock): @@ -284,8 +286,9 @@ class Ilo5RAIDTestCase(db_base.DbTestCase): self.node.save() self._test_create_configuration_empty_target_raid_config() - @mock.patch.object(ilo_raid.Ilo5RAID, '_prepare_for_read_raid') - @mock.patch.object(raid, 'filter_target_raid_config') + @mock.patch.object(ilo_raid.Ilo5RAID, '_prepare_for_read_raid', + autospec=True) + @mock.patch.object(raid, 'filter_target_raid_config', autospec=True) @mock.patch.object(ilo_common, 'get_ilo_object', autospec=True) def _test_create_configuration_skip_root( self, ilo_mock, filter_target_raid_config_mock, @@ -306,7 +309,8 @@ class Ilo5RAIDTestCase(db_base.DbTestCase): self.assertEqual(states.CLEANWAIT, result) else: self.assertEqual(states.DEPLOYWAIT, result) - prepare_raid_mock.assert_called_once_with(task, 'create_raid') + prepare_raid_mock.assert_called_once_with( + mock.ANY, task, 'create_raid') self.assertEqual( exp_target_raid_config, task.node.driver_internal_info['target_raid_config']) @@ -323,8 +327,9 @@ class Ilo5RAIDTestCase(db_base.DbTestCase): self.node.save() self._test_create_configuration_skip_root() - @mock.patch.object(ilo_raid.Ilo5RAID, '_prepare_for_read_raid') - @mock.patch.object(raid, 'filter_target_raid_config') + @mock.patch.object(ilo_raid.Ilo5RAID, '_prepare_for_read_raid', + autospec=True) + @mock.patch.object(raid, 'filter_target_raid_config', autospec=True) @mock.patch.object(ilo_common, 'get_ilo_object', autospec=True) def _test_create_configuration_skip_non_root( self, ilo_mock, filter_target_raid_config_mock, prepare_raid_mock): @@ -340,7 +345,8 @@ class Ilo5RAIDTestCase(db_base.DbTestCase): task, create_nonroot_volumes=False) (ilo_mock_object.create_raid_configuration. assert_called_once_with(exp_target_raid_config)) - prepare_raid_mock.assert_called_once_with(task, 'create_raid') + prepare_raid_mock.assert_called_once_with( + mock.ANY, task, 'create_raid') if task.node.clean_step: self.assertEqual(states.CLEANWAIT, result) else: @@ -361,7 +367,7 @@ class Ilo5RAIDTestCase(db_base.DbTestCase): self.node.save() self._test_create_configuration_skip_non_root() - @mock.patch.object(raid, 'filter_target_raid_config') + @mock.patch.object(raid, 'filter_target_raid_config', autospec=True) @mock.patch.object(ilo_common, 'get_ilo_object', autospec=True) def _test_create_configuration_skip_root_skip_non_root( self, ilo_mock, filter_target_raid_config_mock): @@ -388,7 +394,7 @@ class Ilo5RAIDTestCase(db_base.DbTestCase): self.node.save() self._test_create_configuration_skip_root_skip_non_root() - @mock.patch.object(ilo_raid.Ilo5RAID, '_set_step_failed') + @mock.patch.object(ilo_raid.Ilo5RAID, '_set_step_failed', autospec=True) @mock.patch.object(ilo_common, 'get_ilo_object', autospec=True) def _test_create_configuration_ilo_error(self, ilo_mock, set_step_failed_mock): @@ -399,6 +405,7 @@ class Ilo5RAIDTestCase(db_base.DbTestCase): task.driver.raid.create_configuration( task, create_nonroot_volumes=False) set_step_failed_mock.assert_called_once_with( + mock.ANY, task, 'Failed to create raid configuration ' 'on node %s' % self.node.uuid, exc) @@ -423,7 +430,8 @@ class Ilo5RAIDTestCase(db_base.DbTestCase): self.node.save() self._test_create_configuration_ilo_error() - @mock.patch.object(ilo_raid.Ilo5RAID, '_prepare_for_read_raid') + @mock.patch.object(ilo_raid.Ilo5RAID, '_prepare_for_read_raid', + autospec=True) @mock.patch.object(ilo_common, 'get_ilo_object', autospec=True) def _test_delete_configuration(self, ilo_mock, prepare_raid_mock): ilo_mock_object = ilo_mock.return_value @@ -434,7 +442,8 @@ class Ilo5RAIDTestCase(db_base.DbTestCase): else: self.assertEqual(states.DEPLOYWAIT, result) ilo_mock_object.delete_raid_configuration.assert_called_once_with() - prepare_raid_mock.assert_called_once_with(task, 'delete_raid') + prepare_raid_mock.assert_called_once_with(mock.ANY, task, + 'delete_raid') def test_delete_configuration_cleaning(self): self.node.clean_step = {'step': 'create_configuration', @@ -450,7 +459,8 @@ class Ilo5RAIDTestCase(db_base.DbTestCase): @mock.patch.object(ilo_raid.LOG, 'info', spec_set=True, autospec=True) - @mock.patch.object(ilo_raid.Ilo5RAID, '_prepare_for_read_raid') + @mock.patch.object(ilo_raid.Ilo5RAID, '_prepare_for_read_raid', + autospec=True) @mock.patch.object(ilo_common, 'get_ilo_object', autospec=True) def _test_delete_configuration_no_logical_drive( self, ilo_mock, prepare_raid_mock, log_mock): @@ -547,7 +557,7 @@ class Ilo5RAIDTestCase(db_base.DbTestCase): self.node.save() self._test_delete_configuration_with_read_raid_failed() - @mock.patch.object(ilo_raid.Ilo5RAID, '_set_step_failed') + @mock.patch.object(ilo_raid.Ilo5RAID, '_set_step_failed', autospec=True) @mock.patch.object(ilo_common, 'get_ilo_object', autospec=True) def _test_delete_configuration_ilo_error(self, ilo_mock, set_step_failed_mock): @@ -564,6 +574,7 @@ class Ilo5RAIDTestCase(db_base.DbTestCase): self.assertNotIn('skip_current_clean_step', task.node.driver_internal_info) set_step_failed_mock.assert_called_once_with( + mock.ANY, task, 'Failed to delete raid configuration ' 'on node %s' % self.node.uuid, exc) diff --git a/tox.ini b/tox.ini index 96d7878414..5a95bb71e5 100644 --- a/tox.ini +++ b/tox.ini @@ -132,7 +132,6 @@ per-file-ignores = ironic/tests/base.py:E402 ironic/tests/unit/api/controllers/*:H210 ironic/tests/unit/drivers/modules/test_console_utils.py:H210 - ironic/tests/unit/drivers/modules/ilo/*:H210 [hacking] import_exceptions = testtools.matchers, ironic.common.i18n