Mock isfile in test_ssh_missing_hosts_key_file
test_ssh_missing_hosts_key_file tests that when the ssh_hosts_key_file is missing an InvalidInput exception is raised. It does this by setting CONF.ssh_hosts_key_file to, what is assumed to be, the location of a non-existant file. If the file, /tmp/blah, exists the test fails. This test should not be dependent on what is on the filesystem. This commit adds a mock for os.path.isfile so that when ssh_utils.SSHPool checks for existance of CONF.ssh_hosts_key_file it always gets False regardless of the state of the filesystem. Change-Id: I6bf797301a0829797d55d4442088f9ef944aec2c Closes-bug: #1392628
This commit is contained in:
parent
60ffd142a1
commit
c71c30c40a
@ -997,13 +997,16 @@ class SSHPoolTestCase(test.TestCase):
|
||||
mock_open.assert_called_once_with(default_file, 'a')
|
||||
ssh_pool.remove(ssh)
|
||||
|
||||
@mock.patch('os.path.isfile', return_value=False)
|
||||
@mock.patch('__builtin__.open')
|
||||
@mock.patch('paramiko.SSHClient')
|
||||
def test_ssh_missing_hosts_key_file(self, mock_sshclient, mock_open):
|
||||
def test_ssh_missing_hosts_key_file(self, mock_sshclient, mock_open,
|
||||
mock_isfile):
|
||||
mock_sshclient.return_value = FakeSSHClient()
|
||||
|
||||
CONF.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,
|
||||
|
Loading…
x
Reference in New Issue
Block a user