Add support to SSH on a different port

This commit allow for setting the access to the controller over a
different port than 22. This will allow the test framework to use port
fowarding when deploying StarlingX on virtualized hosts.

Signed-off-by: Thiago Brito <thiago.brito@windriver.com>
Change-Id: I59044beaa13a65dd15840e0e0fbe1d83ad6c1a8a
This commit is contained in:
Thiago Brito 2021-09-21 15:23:02 -03:00
parent aeec1d38e0
commit a1bae32795
6 changed files with 24 additions and 13 deletions

View File

@ -6,7 +6,7 @@
class Tenant:
__PASSWORD = 'St8rlingX*'
__PASSWORD = 'St4rlingX*'
__REGION = 'RegionOne'
__URL_PLATFORM = 'http://192.168.204.2:5000/v3/'
__URL_CONTAINERS = 'http://keystone.openstack.svc.cluster.local/v3'
@ -210,7 +210,7 @@ class HostLinuxUser:
__SYSADMIN = {
'user': 'sysadmin',
'password': 'St8rlingX*'
'password': 'St4rlingX*'
}
@classmethod

View File

@ -17,8 +17,11 @@ class Labs(object):
# 'short_name': 'my_server1',
# 'name': 'my_server1.com',
# 'floating ip': '10.10.10.2',
# 'floating port': 22,
# 'controller-0 ip': '10.10.10.3',
# 'controller-0 port: 22,
# 'controller-1 ip': '10.10.10.4',
# 'controller-1 port: 22,
# }
pass
@ -87,7 +90,7 @@ def get_lab_dict(lab, key='short_name'):
return lab_info
def add_lab_entry(floating_ip, dict_name=None, short_name=None, name=None,
def add_lab_entry(floating_ip, floating_port, dict_name=None, short_name=None, name=None,
**kwargs):
"""
Add a new lab dictionary to Labs class
@ -126,6 +129,7 @@ def add_lab_entry(floating_ip, dict_name=None, short_name=None, name=None,
lab_dict = {'name': name,
'short_name': short_name,
'floating ip': floating_ip,
'floating port': floating_port
}
lab_dict.update(kwargs)

View File

@ -315,7 +315,7 @@ def reboot_hosts(hostnames, timeout=HostTimeout.REBOOT, con_ssh=None,
if check_hypervisor_up and computes:
res, hosts_hypervisordown = wait_for_hypervisors_up(
computes, fail_ok=fail_ok, con_ssh=con_ssh,
timeout=HostTimeout.HYPERVISOR_UP, auth_info=auth_info)
timeout=HostTimeout.HYPERVISOR_UP, auth_info=Tenant.get('admin'))
if not res:
err_msg = "Hosts not up in nova hypervisor-list: " \
"{}".format(hosts_hypervisordown)

View File

@ -1,4 +1,4 @@
pytest>=3.1.0,<4.0
pytest==3.6.1
pexpect
requests
selenium

View File

@ -35,7 +35,7 @@ def setup_tis_ssh(lab):
if con_ssh is None:
con_ssh = SSHClient(lab['floating ip'], HostLinuxUser.get_user(),
HostLinuxUser.get_password(),
CONTROLLER_PROMPT)
CONTROLLER_PROMPT, port=lab['floating port'])
con_ssh.connect(retry=True, retry_timeout=30)
ControllerClient.set_active_controller(con_ssh)
@ -218,6 +218,7 @@ def setup_keypair(con_ssh, natbox_client=None):
natbox_client.exec_cmd(
'mkdir -p {}'.format(os.path.dirname(keyfile_path_natbox)))
tis_ip = ProjVar.get_var('LAB').get('floating ip')
tis_port = ProjVar.get_var('LAB').get('floating port')
for i in range(10):
try:
natbox_client.scp_on_dest(source_ip=tis_ip,
@ -225,7 +226,8 @@ def setup_keypair(con_ssh, natbox_client=None):
source_pswd=HostLinuxUser.get_password(),
source_path=keyfile_stx_final,
dest_path=keyfile_path_natbox,
timeout=120)
timeout=120,
port=tis_port)
LOG.info("private key is copied to NatBox: {}".format(
keyfile_path_natbox))
break
@ -255,7 +257,7 @@ def _get_nonroot_group(con_ssh, user=None):
'and at least one non-root groups'.format(user))
def get_lab_dict(labname):
def get_lab_dict(labname, port):
labname = labname.strip().lower().replace('-', '_')
labs = get_labs_list()
@ -265,7 +267,7 @@ def get_lab_dict(labname):
lower().strip() or labname == lab.get('floating ip'):
return lab
else:
return add_lab_entry(labname)
return add_lab_entry(labname, port)
def get_labs_list():
@ -641,7 +643,8 @@ def setup_testcase_config(testcase_config, lab=None, natbox=None):
config.set(auth_section, 'oam_floating_ip', fip)
else:
fip = config.get(auth_section, 'oam_floating_ip', fallback='').strip()
lab = get_lab_dict(fip)
port = config.get(auth_section, 'oam_floating_port', fallback='22').strip()
lab = get_lab_dict(fip, port)
if __get_ip_version(fip) != 4:
raise ValueError(fip_error)
@ -652,6 +655,7 @@ def setup_testcase_config(testcase_config, lab=None, natbox=None):
'controller0_oam_ip',
fallback='').strip():
con0_ip = config.get(auth_section, 'controller0_oam_ip').strip()
con0_port = config.get(auth_section, 'controller0_oam_port', fallback='22').strip()
if __get_ip_version(con0_ip) == 4:
lab['controller-0 ip'] = con0_ip
else:

View File

@ -621,17 +621,20 @@ class SSHClient:
def scp_on_dest(self, source_user, source_ip, source_path, dest_path,
source_pswd, timeout=3600, cleanup=True,
is_dir=False):
is_dir=False, port=None):
source = source_path
if source_ip:
source = '{}:{}'.format(source_ip, source)
if source_user:
source = '{}@{}'.format(source_user, source)
if port:
port_fmt = "-P {} ".format(port)
option = '-r ' if is_dir else ''
scp_cmd = 'scp -o StrictHostKeyChecking=no -o ' \
scp_cmd = 'scp {}-o StrictHostKeyChecking=no -o ' \
'UserKnownHostsFile=/dev/null {}{} ' \
'{}'.format(option, source, dest_path)
'{}'.format(port_fmt, option, source, dest_path)
try:
self.send(scp_cmd)