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
This commit is contained in:
1 parent
ea0e811aa9
commit
dc8a207ad4
3 files changed
+45
-1
No files matched your search
@@ -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'
|
||||
@@ -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))
|
||||
|
||||
@@ -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'
|
||||
|
||||
Reference in new issue
Block a user