Merge "Fix to run openstack commands on the right host"

This commit is contained in:
Zuul 2024-07-31 12:00:46 +00:00 committed by Gerrit Code Review
commit 70bc2a747d
2 changed files with 41 additions and 21 deletions

View File

@ -71,9 +71,19 @@ class BaseTempestWhiteboxTestCase(base.BaseTempestTestCase):
cls.has_sriov_support = True if sriov_agents else False
cls.neutron_conf = local_constants.NEUTRON_CONF[WB_CONF.openstack_type]
# deployer tool dependent variables
cls.setup_proxy_host()
if WB_CONF.openstack_type == 'podified':
cls.neutron_api_prefix = '{} rsh {} '.format(
cls.OC, cls.get_pods_of_service()[0])
@classmethod
def setup_proxy_host(cls):
# proxy host commonly used for commands such as oc or openstack
if WB_CONF.openstack_type == 'devstack':
cls.master_node_client = cls.get_node_client('localhost')
cls.master_cont_cmd_executor = cls.run_on_master_controller
cls.master_node_client = cls.get_node_client(
'localhost')
cls.master_cont_cmd_executor = \
cls.run_on_master_controller
cls.neutron_api_prefix = ''
elif WB_CONF.openstack_type == 'podified':
cls.OC = "oc -n openstack "
@ -86,9 +96,8 @@ class BaseTempestWhiteboxTestCase(base.BaseTempestTestCase):
"ln -s {} /home/{}/.kube/config || true".format(
WB_CONF.kubeconfig_path, WB_CONF.proxy_host_user))
cls.master_node_client = cls.proxy_host_client
cls.master_cont_cmd_executor = cls.proxy_host_client.exec_command
cls.neutron_api_prefix = '{} rsh {} '.format(
cls.OC, cls.get_pods_of_service()[0])
cls.master_cont_cmd_executor = \
cls.proxy_host_client.exec_command
else:
LOG.warning(("Unrecognized deployer tool '{}', plugin supports "
"openstack_type as devstack/podified.".format(
@ -773,8 +782,10 @@ class BaseTempestWhiteboxTestCase(base.BaseTempestTestCase):
@staticmethod
def validate_command(cmd, pattern='', timeout=60,
ssh_client=None,
ret_bool_status=False, ret_bool_pattern=False):
"""Run a command on a given host.
ret_bool_status=False,
ret_bool_pattern=False,
local_shell=False):
"""Run a command on a given host (default: host supporting OSP CLI).
Optional: validation of output by regex, and exit status.
:param cmd: Command to execute on given host.
@ -803,13 +814,23 @@ class BaseTempestWhiteboxTestCase(base.BaseTempestTestCase):
:returns: all output of command as str, or boolean if either of
return boolean options is True (ret_bool_pattern or ret_bool_status).
"""
# execute on tester node or other, according to CI configuration
if ssh_client is None and not WB_CONF.exec_on_tester:
ssh_client = ssh.Client(
host=WB_CONF.tester_ip,
username=WB_CONF.tester_user,
password=WB_CONF.tester_pass,
key_filename=WB_CONF.tester_key_file)
# local_shell overrides any other ssh_client setting intentions
if local_shell:
ssh_client = None
elif ssh_client is None:
# default execute on proxy node, or according to CI configuration
if WB_CONF.exec_on_tester:
# preserve static, check proxy host ssh client, or make one
if not hasattr(__class__, 'master_node_client'):
__class__.setup_proxy_host()
ssh_client = __class__.master_node_client
else:
ssh_client = ssh.Client(
host=WB_CONF.tester_ip,
username=WB_CONF.tester_user,
password=WB_CONF.tester_pass,
key_filename=WB_CONF.tester_key_file)
# verify command success using exception
try:
result = shell.execute(

View File

@ -428,8 +428,7 @@ class BaseSecGroupLoggingTest(
stdout_patterns.pop(0)
for cmd, ptn in zip(cmds, stdout_patterns):
self.validate_command(
'bash -c "' + prefix + cmd + '"', ptn,
ssh_client=self.master_node_client)
'bash -c "' + prefix + cmd + '"', ptn)
def _test_only_dropped_traffic_logged(self):
"""This scenario verifies that only the log entries of dropped traffic
@ -481,7 +480,6 @@ class BaseSecGroupLoggingTest(
lambda: self.validate_command(
'{} list meter-band'.format(self.nbctl),
pattern=r'burst_size[ \t]+:[ \t]+{}'.format(burst_val),
ssh_client=self.master_node_client,
ret_bool_pattern=True),
timeout=180,
sleep=10,
@ -489,8 +487,7 @@ class BaseSecGroupLoggingTest(
# extra command call needed due to regex limitation
self.validate_command(
'{} list meter-band'.format(self.nbctl),
pattern=r'rate[ \t]+:[ \t]+{}'.format(rate_val),
ssh_client=self.master_node_client)
pattern=r'rate[ \t]+:[ \t]+{}'.format(rate_val))
# 7) verify openvswitch meter configuration on compute of VM
self.validate_command(
'sudo ovs-ofctl dump-meters br-int -O OpenFlow15',
@ -623,7 +620,8 @@ class BaseSecGroupLoggingTest(
self.start_track_log(vm_a['hv_ssh_client'])
self.validate_command(
'sudo ping {} -i 0.002 -c 500 | tail -n4'.format(vm_a['fip']),
pattern=r' 0% packet loss')
pattern=r' 0% packet loss',
local_shell=True)
self.retrieve_tracked_log(vm_a['hv_ssh_client'])
# 15) verify log entries amount equals to:
# rate limit + burst limit (up to 10% offset allowed)
@ -641,7 +639,8 @@ class BaseSecGroupLoggingTest(
self.validate_command(
'sudo ping {} -i 0.005 -c 12000 | tail -n4'.format(vm_a['fip']),
pattern=r' 0% packet loss',
timeout=70)
timeout=70,
local_shell=True)
self.retrieve_tracked_log(vm_a['hv_ssh_client'])
# 17) verify log entries amount equals to:
# rate limit * 60 + burst limit (up to 5% offset allowed)