From cffb12e7b9dd29827548f38d5a17585c79e32f89 Mon Sep 17 00:00:00 2001 From: "John L. Villalovos" Date: Tue, 7 Apr 2015 21:58:27 -0700 Subject: Fix mocks not being stopped as intended Mock objects were being created that were intended to be started and stopped. But they were not actually being stopped. Fix it so they are being stopped correctly, add autospec=True to the mock objects, and update some side_effects to work with autospec=True. Change-Id: I4ced8eb8a4fe874405f0b53132a38e276eef01b5 --- ironic/tests/drivers/test_deploy_utils.py | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/ironic/tests/drivers/test_deploy_utils.py b/ironic/tests/drivers/test_deploy_utils.py index 033bd89d5..f86719028 100644 --- a/ironic/tests/drivers/test_deploy_utils.py +++ b/ironic/tests/drivers/test_deploy_utils.py @@ -1020,13 +1020,18 @@ class WorkOnDiskTestCase(tests_base.TestCase): self.swap_part = '/dev/fake-part1' self.root_part = '/dev/fake-part2' - self.mock_ibd = mock.patch.object(utils, 'is_block_device').start() - self.mock_mp = mock.patch.object(utils, 'make_partitions').start() - self.addCleanup(self.mock_ibd.stop) - self.addCleanup(self.mock_mp.stop) - self.mock_remlbl = mock.patch.object(utils, - 'destroy_disk_metadata').start() - self.addCleanup(self.mock_remlbl.stop) + self.mock_ibd_obj = mock.patch.object( + utils, 'is_block_device', autospec=True) + self.mock_ibd = self.mock_ibd_obj.start() + self.addCleanup(self.mock_ibd_obj.stop) + self.mock_mp_obj = mock.patch.object( + utils, 'make_partitions', autospec=True) + self.mock_mp = self.mock_mp_obj.start() + self.addCleanup(self.mock_mp_obj.stop) + self.mock_remlbl_obj = mock.patch.object( + utils, 'destroy_disk_metadata', autospec=True) + self.mock_remlbl = self.mock_remlbl_obj.start() + self.addCleanup(self.mock_remlbl_obj.stop) self.mock_mp.return_value = {'swap': self.swap_part, 'root': self.root_part} @@ -1044,7 +1049,7 @@ class WorkOnDiskTestCase(tests_base.TestCase): boot_mode="bios") def test_no_swap_partition(self): - self.mock_ibd.side_effect = [True, False] + self.mock_ibd.side_effect = iter([True, False]) calls = [mock.call(self.root_part), mock.call(self.swap_part)] self.assertRaises(exception.InstanceDeployFailure, @@ -1068,7 +1073,7 @@ class WorkOnDiskTestCase(tests_base.TestCase): self.mock_mp.return_value = {'ephemeral': ephemeral_part, 'swap': swap_part, 'root': root_part} - self.mock_ibd.side_effect = [True, True, False] + self.mock_ibd.side_effect = iter([True, True, False]) calls = [mock.call(root_part), mock.call(swap_part), mock.call(ephemeral_part)] @@ -1096,7 +1101,7 @@ class WorkOnDiskTestCase(tests_base.TestCase): self.mock_mp.return_value = {'swap': swap_part, 'configdrive': configdrive_part, 'root': root_part} - self.mock_ibd.side_effect = [True, True, False] + self.mock_ibd.side_effect = iter([True, True, False]) calls = [mock.call(root_part), mock.call(swap_part), mock.call(configdrive_part)] -- cgit v1.2.1