Replace manually changing CONF options
Changing config parameters by one test can lead to wrong behavior other tests in race conditions. Use a mechanism for overwriting config options (self.flags and self.override_config methods of TestCase). Change-Id: I97c58c08104e4da6f3f0386d9396224e71461856
This commit is contained in:
parent
8091e9f737
commit
7da93eb660
|
@ -357,10 +357,8 @@ class HDSHNASBendTest(test.TestCase):
|
|||
@mock.patch.object(time, 'sleep')
|
||||
def test_run_cmd(self, m_sleep, m_utl, m_ssh, m_ssh_cli, m_pvt_key,
|
||||
m_file, m_open):
|
||||
save_hkey_file = CONF.ssh_hosts_key_file
|
||||
save_spath = CONF.state_path
|
||||
CONF.ssh_hosts_key_file = '/var/lib/cinder/ssh_known_hosts'
|
||||
CONF.state_path = '/var/lib/cinder'
|
||||
self.flags(ssh_hosts_key_file='/var/lib/cinder/ssh_known_hosts',
|
||||
state_path='/var/lib/cinder')
|
||||
|
||||
# Test main flow
|
||||
self.hnas_bend.drv_configs['ssh_enabled'] = 'True'
|
||||
|
@ -396,9 +394,6 @@ class HDSHNASBendTest(test.TestCase):
|
|||
'ssh', '0.0.0.0', 'supervisor', 'supervisor',
|
||||
'df', '-a')
|
||||
|
||||
CONF.state_path = save_spath
|
||||
CONF.ssh_hosts_key_file = save_hkey_file
|
||||
|
||||
@mock.patch.object(hnas_backend.HnasBackend, 'run_cmd',
|
||||
side_effect=m_run_cmd)
|
||||
@mock.patch.object(utils, 'execute', return_value=UTILS_EXEC_OUT)
|
||||
|
|
|
@ -656,18 +656,13 @@ class HPE3PARBaseDriver(object):
|
|||
def test_ssh_options(self):
|
||||
|
||||
expected_hosts_key_file = "test_hosts_key_file"
|
||||
orig_ssh_hosts_key_file = CONF.ssh_hosts_key_file
|
||||
orig_strict_ssh_host_key_policy = CONF.strict_ssh_host_key_policy
|
||||
CONF.ssh_hosts_key_file = expected_hosts_key_file
|
||||
CONF.strict_ssh_host_key_policy = False
|
||||
self.flags(ssh_hosts_key_file=expected_hosts_key_file,
|
||||
strict_ssh_host_key_policy=False)
|
||||
|
||||
self.ctxt = context.get_admin_context()
|
||||
mock_client = self.setup_mock_client(
|
||||
driver=hpefcdriver.HPE3PARFCDriver)
|
||||
|
||||
CONF.ssh_hosts_key_file = orig_ssh_hosts_key_file
|
||||
CONF.strict_ssh_host_key_policy = orig_strict_ssh_host_key_policy
|
||||
|
||||
expected = [
|
||||
mock.call.login(HPE3PAR_USER_NAME, HPE3PAR_USER_PASS),
|
||||
mock.call.setSSHOptions(
|
||||
|
@ -688,18 +683,13 @@ class HPE3PARBaseDriver(object):
|
|||
def test_ssh_options_strict(self):
|
||||
|
||||
expected_hosts_key_file = "test_hosts_key_file"
|
||||
orig_ssh_hosts_key_file = CONF.ssh_hosts_key_file
|
||||
orig_strict_ssh_host_key_policy = CONF.strict_ssh_host_key_policy
|
||||
CONF.ssh_hosts_key_file = expected_hosts_key_file
|
||||
CONF.strict_ssh_host_key_policy = True
|
||||
self.flags(ssh_hosts_key_file=expected_hosts_key_file,
|
||||
strict_ssh_host_key_policy=True)
|
||||
|
||||
self.ctxt = context.get_admin_context()
|
||||
mock_client = self.setup_mock_client(
|
||||
driver=hpefcdriver.HPE3PARFCDriver)
|
||||
|
||||
CONF.ssh_hosts_key_file = orig_ssh_hosts_key_file
|
||||
CONF.strict_ssh_host_key_policy = orig_strict_ssh_host_key_policy
|
||||
|
||||
expected = [
|
||||
mock.call.login(HPE3PAR_USER_NAME, HPE3PAR_USER_PASS),
|
||||
mock.call.setSSHOptions(
|
||||
|
|
|
@ -171,14 +171,14 @@ class SSHPoolTestCase(test.TestCase):
|
|||
|
||||
mock_ssh.assert_has_calls(expected, any_order=True)
|
||||
|
||||
@mock.patch('cinder.ssh_utils.CONF')
|
||||
@mock.patch('six.moves.builtins.open')
|
||||
@mock.patch('os.path.isfile', return_value=True)
|
||||
@mock.patch('paramiko.RSAKey.from_private_key_file')
|
||||
@mock.patch('paramiko.SSHClient')
|
||||
def test_single_ssh_connect(self, mock_sshclient, mock_pkey, mock_isfile,
|
||||
mock_open, mock_conf):
|
||||
mock_conf.ssh_hosts_key_file = '/var/lib/cinder/ssh_known_hosts'
|
||||
mock_open):
|
||||
self.override_config(
|
||||
'ssh_hosts_key_file', '/var/lib/cinder/ssh_known_hosts')
|
||||
|
||||
# create with password
|
||||
sshpool = ssh_utils.SSHPool("127.0.0.1", 22, 10,
|
||||
|
@ -261,8 +261,8 @@ class SSHPoolTestCase(test.TestCase):
|
|||
mock_open):
|
||||
mock_sshclient.return_value = FakeSSHClient()
|
||||
|
||||
CONF.state_path = '/var/lib/cinder'
|
||||
CONF.ssh_hosts_key_file = '/var/lib/cinder/ssh_known_hosts'
|
||||
self.flags(state_path='/var/lib/cinder',
|
||||
ssh_hosts_key_file='/var/lib/cinder/ssh_known_hosts')
|
||||
|
||||
default_file = '/var/lib/cinder/ssh_known_hosts'
|
||||
|
||||
|
@ -283,9 +283,9 @@ class SSHPoolTestCase(test.TestCase):
|
|||
mock_isfile):
|
||||
mock_sshclient.return_value = FakeSSHClient()
|
||||
|
||||
CONF.ssh_hosts_key_file = '/tmp/blah'
|
||||
self.flags(state_path='/var/lib/cinder',
|
||||
ssh_hosts_key_file='/tmp/blah')
|
||||
|
||||
self.assertNotIn(CONF.state_path, CONF.ssh_hosts_key_file)
|
||||
self.assertRaises(exception.InvalidInput,
|
||||
ssh_utils.SSHPool,
|
||||
"127.0.0.1", 22, 10,
|
||||
|
@ -322,7 +322,7 @@ class SSHPoolTestCase(test.TestCase):
|
|||
mock_open):
|
||||
mock_sshclient.return_value = FakeSSHClient()
|
||||
|
||||
CONF.strict_ssh_host_key_policy = False
|
||||
self.override_config('strict_ssh_host_key_policy', False)
|
||||
|
||||
# create with customized setting
|
||||
sshpool = ssh_utils.SSHPool("127.0.0.1", 22, 10,
|
||||
|
|
Loading…
Reference in New Issue