diff --git a/whitebox_neutron_tempest_plugin/common/constants.py b/whitebox_neutron_tempest_plugin/common/constants.py index d9c7fcf..2faf033 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 d2be2f3..00e46bf 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 9a90569..9fee487 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'