From 8f6870b451fd0858f50146f52e50c7315527013a Mon Sep 17 00:00:00 2001 From: Dmitry Tantsur Date: Thu, 27 Sep 2018 12:52:31 +0200 Subject: [PATCH] Prevent configuration changes in unit tests from affecting each other Currently some of our tests set overrides, but nothing restores them. This changes adds a config fixture to the bass class and also switches some tests to using set_override instead of direct assignment. Change-Id: I178061608e407047fb87d547c277ea38db353c26 Story: #2003891 Task: #26758 --- ironic_lib/tests/base.py | 4 ++++ ironic_lib/tests/test_utils.py | 19 +++++++------------ 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/ironic_lib/tests/base.py b/ironic_lib/tests/base.py index 6aaeacaa..06eba30d 100644 --- a/ironic_lib/tests/base.py +++ b/ironic_lib/tests/base.py @@ -18,6 +18,7 @@ import subprocess from oslo_concurrency import processutils +from oslo_config import fixture as config_fixture from oslotest import base as test_base from ironic_lib import utils @@ -36,6 +37,9 @@ class IronicLibTestCase(test_base.BaseTestCase): def setUp(self): super(IronicLibTestCase, self).setUp() + # Make sure config overrides do not leak for test to test. + self.cfg_fixture = self.useFixture(config_fixture.Config()) + # Ban running external processes via 'execute' like functions. If the # patched function is called, an exception is raised to warn the # tester. diff --git a/ironic_lib/tests/test_utils.py b/ironic_lib/tests/test_utils.py index d95112ad..e8d49b4b 100644 --- a/ironic_lib/tests/test_utils.py +++ b/ironic_lib/tests/test_utils.py @@ -467,6 +467,13 @@ class MatchRootDeviceTestCase(base.IronicLibTestCase): class WaitForDisk(base.IronicLibTestCase): + def setUp(self): + super(WaitForDisk, self).setUp() + CONF.set_override('check_device_interval', .01, + group='disk_partitioner') + CONF.set_override('check_device_max_retries', 2, + group='disk_partitioner') + @mock.patch.object(utils, 'execute', autospec=True) def test_wait_for_disk_to_become_available(self, mock_exc): mock_exc.return_value = ('', '') @@ -481,8 +488,6 @@ class WaitForDisk(base.IronicLibTestCase): side_effect=processutils.ProcessExecutionError( stderr='fake')) def test_wait_for_disk_to_become_available_no_fuser(self, mock_exc): - CONF.disk_partitioner.check_device_interval = .01 - CONF.disk_partitioner.check_device_max_retries = 2 self.assertRaises(exception.IronicException, utils.wait_for_disk_to_become_available, 'fake-dev') @@ -500,8 +505,6 @@ class WaitForDisk(base.IronicLibTestCase): # NOTE(TheJulia): Looks like fuser returns the actual list of pids # in the stdout output, where as all other text is returned in # stderr. - CONF.disk_partitioner.check_device_interval = .01 - CONF.disk_partitioner.check_device_max_retries = 2 # The 'psmisc' version has a leading space character in stdout. The # filename is output to stderr mock_exc.side_effect = [(' 1234 ', 'fake-dev: '), @@ -528,8 +531,6 @@ class WaitForDisk(base.IronicLibTestCase): # NOTE(TheJulia): Looks like fuser returns the actual list of pids # in the stdout output, where as all other text is returned in # stderr. - CONF.disk_partitioner.check_device_interval = .01 - CONF.disk_partitioner.check_device_max_retries = 2 # The 'busybox' version does not have a leading space character in # stdout. Also nothing is output to stderr. mock_exc.side_effect = [('1234', ''), @@ -553,8 +554,6 @@ class WaitForDisk(base.IronicLibTestCase): # NOTE(TheJulia): Looks like fuser returns the actual list of pids # in the stdout output, where as all other text is returned in # stderr. - CONF.disk_partitioner.check_device_interval = .01 - CONF.disk_partitioner.check_device_max_retries = 2 mock_exc.return_value = ('', 'Specified filename /dev/fake ' 'does not exist.') @@ -579,8 +578,6 @@ class WaitForDisk(base.IronicLibTestCase): # Test that initially device is not available but then becomes # available. This version has the 'psmisc' version of 'fuser' values # for stdout and stderr. - CONF.disk_partitioner.check_device_interval = .01 - CONF.disk_partitioner.check_device_max_retries = 2 # The 'psmisc' version has a leading space character in stdout. The # filename is output to stderr mock_exc.side_effect = [(' 1234 ', 'fake-dev: '), @@ -598,8 +595,6 @@ class WaitForDisk(base.IronicLibTestCase): # Test that initially device is not available but then becomes # available. This version has the 'busybox' version of 'fuser' values # for stdout and stderr. - CONF.disk_partitioner.check_device_interval = .01 - CONF.disk_partitioner.check_device_max_retries = 2 # The 'busybox' version does not have a leading space character in # stdout. Also nothing is output to stderr. mock_exc.side_effect = [('1234 5895', ''),