]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Mock isfile in test_ssh_missing_hosts_key_file
authorgit-harry <git-harry@live.co.uk>
Fri, 14 Nov 2014 09:09:55 +0000 (09:09 +0000)
committergit-harry <git-harry@live.co.uk>
Fri, 14 Nov 2014 15:57:50 +0000 (15:57 +0000)
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

index 801e3fb0cea84673bec894760fdd4516ad20613b..70437a24e2ea4b654de7fa8b94823ccab97ef8f0 100644 (file)
@@ -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,