From de5213c77e6a676fd3546095fc816bbda4e26547 Mon Sep 17 00:00:00 2001 From: Maor Blaustein Date: Tue, 30 Jul 2024 15:48:17 +0300 Subject: [PATCH] Fix to run openstack commands on the right host This fixes tests in the following test files [1]. Method 'validate_command' is commonly used for openstack/oc commands, therefore default ssh client should be the proxy host (localhost on devstack, controller on podified for now). Another new argument 'local_shell' allows to easily override and execute any command locally (without ssh connection). [1] test_provider_network.py test_router_flavors.py test_security_group_logging.py Change-Id: I9138b1081870da4162eeb40ca055e3547f5c12b9 --- .../tests/scenario/base.py | 49 +++++++++++++------ .../scenario/test_security_group_logging.py | 13 +++-- 2 files changed, 41 insertions(+), 21 deletions(-) diff --git a/whitebox_neutron_tempest_plugin/tests/scenario/base.py b/whitebox_neutron_tempest_plugin/tests/scenario/base.py index 71267e8..6b296db 100644 --- a/whitebox_neutron_tempest_plugin/tests/scenario/base.py +++ b/whitebox_neutron_tempest_plugin/tests/scenario/base.py @@ -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( diff --git a/whitebox_neutron_tempest_plugin/tests/scenario/test_security_group_logging.py b/whitebox_neutron_tempest_plugin/tests/scenario/test_security_group_logging.py index dfa64df..d61083f 100644 --- a/whitebox_neutron_tempest_plugin/tests/scenario/test_security_group_logging.py +++ b/whitebox_neutron_tempest_plugin/tests/scenario/test_security_group_logging.py @@ -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)