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
This commit is contained in:
Eric Harney 2023-04-11 09:13:59 -04:00
parent dfef52f3a6
commit 69497b151e
3 changed files with 20 additions and 1 deletions

View File

@ -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.')

View File

@ -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:

View File

@ -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')