]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Fix SSHPoolTestCase to work in parallel
authorIvan Kolodyazhny <e0ne@e0ne.info>
Fri, 30 Jan 2015 17:19:03 +0000 (19:19 +0200)
committerIvan Kolodyazhny <e0ne@e0ne.info>
Sun, 1 Feb 2015 11:53:35 +0000 (13:53 +0200)
Mock global config for tests in SSHPoolTestCase to make it
workable in a concurrency mode.

Change-Id: Ibf6f881d6dfd945abe9c7433367b0acf5b24722a
Partial-Bug: #1259463

cinder/tests/test_utils.py

index 7bfccc72b9741ef3acec9efb654e734d7541f780..ecaa497ef783038dfc497074b0fd05a1a703db95 100644 (file)
@@ -1010,13 +1010,15 @@ class FakeTransport(object):
 
 class SSHPoolTestCase(test.TestCase):
     """Unit test for SSH Connection Pool."""
+    @mock.patch('cinder.ssh_utils.CONF')
     @mock.patch('__builtin__.open')
     @mock.patch('paramiko.SSHClient')
     @mock.patch('os.path.isfile', return_value=True)
     def test_ssh_default_hosts_key_file(self, mock_isfile, mock_sshclient,
-                                        mock_open):
+                                        mock_open, mock_conf):
         mock_ssh = mock.MagicMock()
         mock_sshclient.return_value = mock_ssh
+        mock_conf.ssh_hosts_key_file = '/var/lib/cinder/ssh_known_hosts'
 
         # create with customized setting
         sshpool = ssh_utils.SSHPool("127.0.0.1", 22, 10,
@@ -1032,13 +1034,15 @@ class SSHPoolTestCase(test.TestCase):
         mock_ssh.load_host_keys.assert_called_once_with(
             '/var/lib/cinder/ssh_known_hosts')
 
+    @mock.patch('cinder.ssh_utils.CONF')
     @mock.patch('__builtin__.open')
     @mock.patch('paramiko.SSHClient')
     @mock.patch('os.path.isfile', return_value=True)
     def test_ssh_host_key_file_kwargs(self, mock_isfile, mock_sshclient,
-                                      mock_open):
+                                      mock_open, mock_conf):
         mock_ssh = mock.MagicMock()
         mock_sshclient.return_value = mock_ssh
+        mock_conf.ssh_hosts_key_file = '/var/lib/cinder/ssh_known_hosts'
 
         # create with customized setting
         sshpool = ssh_utils.SSHPool("127.0.0.1", 22, 10,
@@ -1059,13 +1063,14 @@ class SSHPoolTestCase(test.TestCase):
 
         mock_ssh.assert_has_calls(expected, any_order=True)
 
+    @mock.patch('cinder.ssh_utils.CONF')
     @mock.patch('__builtin__.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):
-        CONF.ssh_hosts_key_file = '/var/lib/cinder/ssh_known_hosts'
+                                mock_open, mock_conf):
+        mock_conf.ssh_hosts_key_file = '/var/lib/cinder/ssh_known_hosts'
 
         # create with password
         sshpool = ssh_utils.SSHPool("127.0.0.1", 22, 10,
@@ -1125,12 +1130,14 @@ class SSHPoolTestCase(test.TestCase):
 
         self.assertNotEqual(first_id, third_id)
 
+    @mock.patch('cinder.ssh_utils.CONF')
     @mock.patch('__builtin__.open')
     @mock.patch('paramiko.SSHClient')
-    def test_missing_ssh_hosts_key_config(self, mock_sshclient, mock_open):
+    def test_missing_ssh_hosts_key_config(self, mock_sshclient, mock_open,
+                                          mock_conf):
         mock_sshclient.return_value = FakeSSHClient()
 
-        CONF.ssh_hosts_key_file = None
+        mock_conf.ssh_hosts_key_file = None
         # create with password
         self.assertRaises(exception.ParameterNotFound,
                           ssh_utils.SSHPool,
@@ -1179,6 +1186,9 @@ class SSHPoolTestCase(test.TestCase):
                           min_size=1,
                           max_size=1)
 
+    @mock.patch.multiple('cinder.ssh_utils.CONF',
+                         strict_ssh_host_key_policy=True,
+                         ssh_hosts_key_file='/var/lib/cinder/ssh_known_hosts')
     @mock.patch('__builtin__.open')
     @mock.patch('paramiko.SSHClient')
     @mock.patch('os.path.isfile', return_value=True)
@@ -1186,8 +1196,6 @@ class SSHPoolTestCase(test.TestCase):
                                         mock_open):
         mock_sshclient.return_value = FakeSSHClient()
 
-        CONF.strict_ssh_host_key_policy = True
-
         # create with customized setting
         sshpool = ssh_utils.SSHPool("127.0.0.1", 22, 10,
                                     "test",