Merge "Add port parameter to ssh Client"
This commit is contained in:
commit
1ac2bd6958
|
@ -0,0 +1,4 @@
|
||||||
|
---
|
||||||
|
features:
|
||||||
|
- A new optional parameter `port` for ssh client (`tempest.lib.common.ssh.Client`)
|
||||||
|
to specify destination port for a host. The default value is 22.
|
|
@ -36,9 +36,11 @@ LOG = logging.getLogger(__name__)
|
||||||
class Client(object):
|
class Client(object):
|
||||||
|
|
||||||
def __init__(self, host, username, password=None, timeout=300, pkey=None,
|
def __init__(self, host, username, password=None, timeout=300, pkey=None,
|
||||||
channel_timeout=10, look_for_keys=False, key_filename=None):
|
channel_timeout=10, look_for_keys=False, key_filename=None,
|
||||||
|
port=22):
|
||||||
self.host = host
|
self.host = host
|
||||||
self.username = username
|
self.username = username
|
||||||
|
self.port = port
|
||||||
self.password = password
|
self.password = password
|
||||||
if isinstance(pkey, six.string_types):
|
if isinstance(pkey, six.string_types):
|
||||||
pkey = paramiko.RSAKey.from_private_key(
|
pkey = paramiko.RSAKey.from_private_key(
|
||||||
|
@ -58,17 +60,17 @@ class Client(object):
|
||||||
paramiko.AutoAddPolicy())
|
paramiko.AutoAddPolicy())
|
||||||
_start_time = time.time()
|
_start_time = time.time()
|
||||||
if self.pkey is not None:
|
if self.pkey is not None:
|
||||||
LOG.info("Creating ssh connection to '%s' as '%s'"
|
LOG.info("Creating ssh connection to '%s:%d' as '%s'"
|
||||||
" with public key authentication",
|
" with public key authentication",
|
||||||
self.host, self.username)
|
self.host, self.port, self.username)
|
||||||
else:
|
else:
|
||||||
LOG.info("Creating ssh connection to '%s' as '%s'"
|
LOG.info("Creating ssh connection to '%s:%d' as '%s'"
|
||||||
" with password %s",
|
" with password %s",
|
||||||
self.host, self.username, str(self.password))
|
self.host, self.port, self.username, str(self.password))
|
||||||
attempts = 0
|
attempts = 0
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
ssh.connect(self.host, username=self.username,
|
ssh.connect(self.host, port=self.port, username=self.username,
|
||||||
password=self.password,
|
password=self.password,
|
||||||
look_for_keys=self.look_for_keys,
|
look_for_keys=self.look_for_keys,
|
||||||
key_filename=self.key_filename,
|
key_filename=self.key_filename,
|
||||||
|
|
|
@ -69,6 +69,7 @@ class TestSshClient(base.TestCase):
|
||||||
mock.sentinel.aa)
|
mock.sentinel.aa)
|
||||||
expected_connect = [mock.call(
|
expected_connect = [mock.call(
|
||||||
'localhost',
|
'localhost',
|
||||||
|
port=22,
|
||||||
username='root',
|
username='root',
|
||||||
pkey=None,
|
pkey=None,
|
||||||
key_filename=None,
|
key_filename=None,
|
||||||
|
|
Loading…
Reference in New Issue