summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Harney <eharney@redhat.com>2023-04-11 09:13:59 -0400
committerEric Harney <eharney@redhat.com>2023-04-11 10:50:15 -0400
commit69497b151ee35aa626be6ddccb40742528241d45 (patch)
tree16980d235392940d19c3d891cecdd77a94648883
parentdfef52f3a6e6ba6fde0e985621673064c8c86356 (diff)
downloadcinder-69497b151ee35aa626be6ddccb40742528241d45.tar.gz
Make paramiko import optional
Since paramiko does not support FIPS, some deployments may run without paramiko installed. Handle this in ssh_utils. (This does not handle the paramiko requirement for drivers that import it directly.) Change-Id: Id87876543df825f9d84938c615c5976abdebd8f4
-rw-r--r--cinder/exception.py4
-rw-r--r--cinder/ssh_utils.py9
-rw-r--r--cinder/tests/unit/test_ssh_utils.py8
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')