From c71c30c40a6862b7c519736dd2e481136e7b29cf Mon Sep 17 00:00:00 2001 From: git-harry Date: Fri, 14 Nov 2014 09:09:55 +0000 Subject: [PATCH] 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 --- cinder/tests/test_utils.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/cinder/tests/test_utils.py b/cinder/tests/test_utils.py index 801e3fb0c..70437a24e 100644 --- a/cinder/tests/test_utils.py +++ b/cinder/tests/test_utils.py @@ -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, -- 2.45.2