From dc8a207ad4409b54fa5b5e60bab2f2be7d2f0f26 Mon Sep 17 00:00:00 2001 From: Maor Blaustein Date: Wed, 7 May 2025 00:12:50 +0300 Subject: [PATCH] Add WSGI check for devstack As stated in [1], WSGI can be used by devstack which will also affect neutron service name, added check for such possible use. Added generic find regex in file function. Added crudini function to get/set on local/remote host. [1] https://review.opendev.org/c/x/whitebox-neutron-tempest-plugin/+/947957/comment/cf50e0db_81123f51/ Related-Bug: #OSPRH-16442 Change-Id: I56088673271ee6410ad712ff6152969aae390bf1 --- .../common/constants.py | 2 + .../common/utils.py | 40 +++++++++++++++++++ .../tests/scenario/base.py | 4 +- 3 files changed, 45 insertions(+), 1 deletion(-) diff --git a/whitebox_neutron_tempest_plugin/common/constants.py b/whitebox_neutron_tempest_plugin/common/constants.py index d9c7fcf5..2faf0337 100644 --- a/whitebox_neutron_tempest_plugin/common/constants.py +++ b/whitebox_neutron_tempest_plugin/common/constants.py @@ -45,3 +45,5 @@ DHCP_OPTIONS_NEUTRON_TO_OVN = { 'lease-time': 'lease_time', 'domain-search': 'domain_search', '26': 'mtu'} +LOCAL_CONF_FILE = '/opt/stack/devstack/local.conf' +WSGI_OPT = 'NEUTRON_DEPLOY_MOD_WSGI' diff --git a/whitebox_neutron_tempest_plugin/common/utils.py b/whitebox_neutron_tempest_plugin/common/utils.py index d2be2f36..00e46bf6 100644 --- a/whitebox_neutron_tempest_plugin/common/utils.py +++ b/whitebox_neutron_tempest_plugin/common/utils.py @@ -31,6 +31,46 @@ LOG = log.getLogger(__name__) WB_CONF = CONF.whitebox_neutron_plugin_options +def is_regex_in_file(regex, filename, re_flags=0, fail_no_file=True): + """Returns whether regex found in file content.""" + try: + with open(filename) as file: + result = bool(re.search( + regex, + file.read(), + re_flags)) + except FileNotFoundError: + if fail_no_file: + LOG.exception( + "File '%s' not found while searching regex '%s' in it", + filename, regex) + raise + result = False + LOG.debug("is '%s' regex found in file '%s' -> %s", + regex, filename, result) + return result + + +def _is_devstack_wsgi(local_conf=constants.LOCAL_CONF_FILE): + # NOTE(mblue): fails/false for podified, so file existence optional + return is_regex_in_file( + f'{constants.WSGI_OPT}=.*?true.*?', + local_conf, + re.I, + fail_no_file=False) + + +def conf_action( + file, section='DEFAULT', param='', value='', host=None, check=True): + """get/set using crudini in local/remote host.""" + assert param + _action = '--set' if value else '--get' + _value = f"'{value}'" if value else "" + cmd = f"crudini {_action} '{file}' '{section}' '{param}' {_value}" + output = shell.execute(cmd, host, check) + return output.stdout.strip() + + def create_payload_file(ssh_client, size): ssh_client.exec_command( "head -c {0} /dev/zero > {0}".format(size)) diff --git a/whitebox_neutron_tempest_plugin/tests/scenario/base.py b/whitebox_neutron_tempest_plugin/tests/scenario/base.py index c8d698d4..8ee6c242 100644 --- a/whitebox_neutron_tempest_plugin/tests/scenario/base.py +++ b/whitebox_neutron_tempest_plugin/tests/scenario/base.py @@ -62,6 +62,8 @@ class BaseTempestWhiteboxTestCase(base.BaseTempestTestCase): is_devstack = bool(shell.execute( 'test -d /opt/stack && echo stack', check=False).stdout.strip()) + if 'is_devstack_wsgi' not in locals(): + is_devstack_wsgi = local_utils._is_devstack_wsgi() @classmethod def resource_setup(cls): @@ -93,7 +95,7 @@ class BaseTempestWhiteboxTestCase(base.BaseTempestTestCase): @classmethod def get_neutron_api_service_name(cls): """Return the Neutron API service name based on test configuration""" - if cls.is_devstack: + if cls.is_devstack and not cls.is_devstack_wsgi: # NOTE: in OSP18+, the Neutron API will use WSGI by default (not # the eventlet server) and the name will be "neutron api" return 'q svc'