Add port parameter to ssh Client
This commit adds a port parameter to the ssh.Client. We don't use it in
our test cases. However, it would be good to have it when I debug this
class because my development host ssh port is not 22. And I think
that it is natural a ssh client has this feature.
Change-Id: Id8b73108f67fe8c581dd8fba90902869b4ee776d
diff --git a/releasenotes/notes/add-ssh-port-parameter-to-client-6d16c374ac4456c1.yaml b/releasenotes/notes/add-ssh-port-parameter-to-client-6d16c374ac4456c1.yaml
new file mode 100644
index 0000000..b2ad199
--- /dev/null
+++ b/releasenotes/notes/add-ssh-port-parameter-to-client-6d16c374ac4456c1.yaml
@@ -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.
diff --git a/tempest/lib/common/ssh.py b/tempest/lib/common/ssh.py
index a831dbd..9002a45 100644
--- a/tempest/lib/common/ssh.py
+++ b/tempest/lib/common/ssh.py
@@ -36,9 +36,11 @@
class Client(object):
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.username = username
+ self.port = port
self.password = password
if isinstance(pkey, six.string_types):
pkey = paramiko.RSAKey.from_private_key(
@@ -58,17 +60,17 @@
paramiko.AutoAddPolicy())
_start_time = time.time()
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",
- self.host, self.username)
+ self.host, self.port, self.username)
else:
- LOG.info("Creating ssh connection to '%s' as '%s'"
+ LOG.info("Creating ssh connection to '%s:%d' as '%s'"
" with password %s",
- self.host, self.username, str(self.password))
+ self.host, self.port, self.username, str(self.password))
attempts = 0
while True:
try:
- ssh.connect(self.host, username=self.username,
+ ssh.connect(self.host, port=self.port, username=self.username,
password=self.password,
look_for_keys=self.look_for_keys,
key_filename=self.key_filename,
diff --git a/tempest/tests/lib/test_ssh.py b/tempest/tests/lib/test_ssh.py
index b07f6bc..8a0a84c 100644
--- a/tempest/tests/lib/test_ssh.py
+++ b/tempest/tests/lib/test_ssh.py
@@ -69,6 +69,7 @@
mock.sentinel.aa)
expected_connect = [mock.call(
'localhost',
+ port=22,
username='root',
pkey=None,
key_filename=None,