Merge "Make paramiko import optional"
This commit is contained in:
commit
8f5373ac3c
@ -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.')
|
||||
|
@ -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
|
||||
|
||||
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:
|
||||
|
@ -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')
|
||||
|
Loading…
Reference in New Issue
Block a user