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

View File

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