diff options
author | Zuul <zuul@review.opendev.org> | 2023-04-17 17:30:55 +0000 |
---|---|---|
committer | Gerrit Code Review <review@openstack.org> | 2023-04-17 17:30:55 +0000 |
commit | 8f5373ac3c88926be59161df82723018f217e6a1 (patch) | |
tree | 7306857cff49bc4b074fb7466b5599be4796161a | |
parent | 78fac2960d28e97f42454bb5f385b46fbae23a3c (diff) | |
parent | 69497b151ee35aa626be6ddccb40742528241d45 (diff) | |
download | cinder-8f5373ac3c88926be59161df82723018f217e6a1.tar.gz |
Merge "Make paramiko import optional"
-rw-r--r-- | cinder/exception.py | 4 | ||||
-rw-r--r-- | cinder/ssh_utils.py | 9 | ||||
-rw-r--r-- | cinder/tests/unit/test_ssh_utils.py | 8 |
3 files changed, 20 insertions, 1 deletions
diff --git a/cinder/exception.py b/cinder/exception.py index 906ed3923..dddcbc68a 100644 --- a/cinder/exception.py +++ b/cinder/exception.py @@ -1092,3 +1092,7 @@ class DriverInitiatorDataExists(Duplicate): "Driver initiator data for initiator '%(initiator)s' and backend " "'%(namespace)s' with key '%(key)s' already exists." ) + + +class RequirementMissing(CinderException): + message = _('Requirement %(req)s is not installed.') diff --git a/cinder/ssh_utils.py b/cinder/ssh_utils.py index 6bd3fb731..bef393e28 100644 --- a/cinder/ssh_utils.py +++ b/cinder/ssh_utils.py @@ -24,7 +24,11 @@ from eventlet import pools from oslo_config import cfg from oslo_log import log as logging from oslo_utils import excutils -import paramiko + +try: + import paramiko +except ImportError: + paramiko = None from cinder import exception from cinder.i18n import _ @@ -65,6 +69,9 @@ class SSHPool(pools.Pool): self.hosts_key_file = None self.current_size = 0 + if paramiko is None: + raise exception.RequirementMissing(req='paramiko') + # Validate good config setting here. # Paramiko handles the case where the file is inaccessible. if not CONF.ssh_hosts_key_file: diff --git a/cinder/tests/unit/test_ssh_utils.py b/cinder/tests/unit/test_ssh_utils.py index 3d4dd6225..67091179f 100644 --- a/cinder/tests/unit/test_ssh_utils.py +++ b/cinder/tests/unit/test_ssh_utils.py @@ -405,3 +405,11 @@ class SSHPoolTestCase(test.TestCase): sshpool = None self.assertEqual(fake_close.mock_calls, close_expect_calls + close_expect_calls) + + @mock.patch('cinder.ssh_utils.paramiko', new=None) + def test_missing_paramiko(self): + self.assertRaises(exception.RequirementMissing, + ssh_utils.SSHPool, + '192.0.2.1', 22, 10, + 'test', + password='hello') |