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
This commit is contained in:
parent
712da6c465
commit
8f6870b451
|
@ -18,6 +18,7 @@
|
||||||
import subprocess
|
import subprocess
|
||||||
|
|
||||||
from oslo_concurrency import processutils
|
from oslo_concurrency import processutils
|
||||||
|
from oslo_config import fixture as config_fixture
|
||||||
from oslotest import base as test_base
|
from oslotest import base as test_base
|
||||||
|
|
||||||
from ironic_lib import utils
|
from ironic_lib import utils
|
||||||
|
@ -36,6 +37,9 @@ class IronicLibTestCase(test_base.BaseTestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(IronicLibTestCase, self).setUp()
|
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
|
# Ban running external processes via 'execute' like functions. If the
|
||||||
# patched function is called, an exception is raised to warn the
|
# patched function is called, an exception is raised to warn the
|
||||||
# tester.
|
# tester.
|
||||||
|
|
|
@ -467,6 +467,13 @@ class MatchRootDeviceTestCase(base.IronicLibTestCase):
|
||||||
|
|
||||||
class WaitForDisk(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)
|
@mock.patch.object(utils, 'execute', autospec=True)
|
||||||
def test_wait_for_disk_to_become_available(self, mock_exc):
|
def test_wait_for_disk_to_become_available(self, mock_exc):
|
||||||
mock_exc.return_value = ('', '')
|
mock_exc.return_value = ('', '')
|
||||||
|
@ -481,8 +488,6 @@ class WaitForDisk(base.IronicLibTestCase):
|
||||||
side_effect=processutils.ProcessExecutionError(
|
side_effect=processutils.ProcessExecutionError(
|
||||||
stderr='fake'))
|
stderr='fake'))
|
||||||
def test_wait_for_disk_to_become_available_no_fuser(self, mock_exc):
|
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,
|
self.assertRaises(exception.IronicException,
|
||||||
utils.wait_for_disk_to_become_available,
|
utils.wait_for_disk_to_become_available,
|
||||||
'fake-dev')
|
'fake-dev')
|
||||||
|
@ -500,8 +505,6 @@ class WaitForDisk(base.IronicLibTestCase):
|
||||||
# NOTE(TheJulia): Looks like fuser returns the actual list of pids
|
# NOTE(TheJulia): Looks like fuser returns the actual list of pids
|
||||||
# in the stdout output, where as all other text is returned in
|
# in the stdout output, where as all other text is returned in
|
||||||
# stderr.
|
# 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
|
# The 'psmisc' version has a leading space character in stdout. The
|
||||||
# filename is output to stderr
|
# filename is output to stderr
|
||||||
mock_exc.side_effect = [(' 1234 ', 'fake-dev: '),
|
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
|
# NOTE(TheJulia): Looks like fuser returns the actual list of pids
|
||||||
# in the stdout output, where as all other text is returned in
|
# in the stdout output, where as all other text is returned in
|
||||||
# stderr.
|
# 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
|
# The 'busybox' version does not have a leading space character in
|
||||||
# stdout. Also nothing is output to stderr.
|
# stdout. Also nothing is output to stderr.
|
||||||
mock_exc.side_effect = [('1234', ''),
|
mock_exc.side_effect = [('1234', ''),
|
||||||
|
@ -553,8 +554,6 @@ class WaitForDisk(base.IronicLibTestCase):
|
||||||
# NOTE(TheJulia): Looks like fuser returns the actual list of pids
|
# NOTE(TheJulia): Looks like fuser returns the actual list of pids
|
||||||
# in the stdout output, where as all other text is returned in
|
# in the stdout output, where as all other text is returned in
|
||||||
# stderr.
|
# stderr.
|
||||||
CONF.disk_partitioner.check_device_interval = .01
|
|
||||||
CONF.disk_partitioner.check_device_max_retries = 2
|
|
||||||
|
|
||||||
mock_exc.return_value = ('', 'Specified filename /dev/fake '
|
mock_exc.return_value = ('', 'Specified filename /dev/fake '
|
||||||
'does not exist.')
|
'does not exist.')
|
||||||
|
@ -579,8 +578,6 @@ class WaitForDisk(base.IronicLibTestCase):
|
||||||
# Test that initially device is not available but then becomes
|
# Test that initially device is not available but then becomes
|
||||||
# available. This version has the 'psmisc' version of 'fuser' values
|
# available. This version has the 'psmisc' version of 'fuser' values
|
||||||
# for stdout and stderr.
|
# 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
|
# The 'psmisc' version has a leading space character in stdout. The
|
||||||
# filename is output to stderr
|
# filename is output to stderr
|
||||||
mock_exc.side_effect = [(' 1234 ', 'fake-dev: '),
|
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
|
# Test that initially device is not available but then becomes
|
||||||
# available. This version has the 'busybox' version of 'fuser' values
|
# available. This version has the 'busybox' version of 'fuser' values
|
||||||
# for stdout and stderr.
|
# 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
|
# The 'busybox' version does not have a leading space character in
|
||||||
# stdout. Also nothing is output to stderr.
|
# stdout. Also nothing is output to stderr.
|
||||||
mock_exc.side_effect = [('1234 5895', ''),
|
mock_exc.side_effect = [('1234 5895', ''),
|
||||||
|
|
Loading…
Reference in New Issue