From 0f40dfd63418e82868475623930ec9c6d6eda334 Mon Sep 17 00:00:00 2001 From: Clark Boylan Date: Tue, 17 Apr 2018 15:33:38 -0700 Subject: [PATCH] Better supports sev checking Previously we attempted to check supports sev by running re.search against the full log path of the log file. This meannt that the re that roughly said: r'/neutron-' could match job logs like this: http://logs.openstack.org/17/553617/16/check/neutron-tempest-plugin-dvr-multinode-scenario/42fb158/job-output.txt.gz Unfortunately that meant that all neutron logs had to support sev and if they didn't (which job output doesn't) then we'd serve no logs to the user if they set a log level. We address this by switching to matching on the basename of the path and by switching to re.match so that we only match from the beginning of the re. Change-Id: Ia428dc7339f06a15c58001e99ca677cb6059186b --- os_loganalyze/filter.py | 8 ++++++-- os_loganalyze/tests/test_filters.py | 14 ++++++++------ 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/os_loganalyze/filter.py b/os_loganalyze/filter.py index 91da89b..7c5eed2 100644 --- a/os_loganalyze/filter.py +++ b/os_loganalyze/filter.py @@ -15,14 +15,15 @@ # License for the specific language governing permissions and limitations # under the License. +import os.path import re import os_loganalyze.generator as generator import os_loganalyze.util as util # which logs support severity +# This uses re.match so you must match the left hand side. SUPPORTS_SEV = re.compile( - r'/' # this uses an re.search so anchor the string r'((screen-)?(n-|c-|g-|h-|ir-|ironic-|m-|o-|df-|placement-api|' r'q-|neutron-|' # support both lib/neutron and lib/neutron-legacy logs r'ceil|key|sah|des|tr)' # openstack logs @@ -118,8 +119,11 @@ class SevFilter(object): def __init__(self, file_generator, minsev="NONE", limit=None): self.minsev = minsev self.file_generator = file_generator + # To avoid matching strings in the log dir path we only consider the + # filename itself for severity support. + filename = os.path.basename(file_generator.logname) self.supports_sev = \ - SUPPORTS_SEV.search(file_generator.logname) is not None + SUPPORTS_SEV.match(filename) is not None self.limit = limit self.strip_control = False diff --git a/os_loganalyze/tests/test_filters.py b/os_loganalyze/tests/test_filters.py index 6ec2b98..090afed 100644 --- a/os_loganalyze/tests/test_filters.py +++ b/os_loganalyze/tests/test_filters.py @@ -26,20 +26,22 @@ from os_loganalyze.tests import base class TestSupportsSevRegex(base.TestCase): def test_matching(self): def yes(fname): - self.assertIsNotNone(flt.SUPPORTS_SEV.search(fname), + self.assertIsNotNone(flt.SUPPORTS_SEV.match(fname), "%s should have matched" % fname) def no(fname): - self.assertIsNone(flt.SUPPORTS_SEV.search(fname), + self.assertIsNone(flt.SUPPORTS_SEV.match(fname), "%s should not have matched" % fname) - yes("/n-api.txt.gz") - yes("/c-vol.txt.gz") - yes("/tempest.txt") - yes("/devstack@c-api.service.log.txt") + yes("n-api.txt.gz") + yes("c-vol.txt.gz") + yes("tempest.txt") + yes("devstack@c-api.service.log.txt") # this specific bug was hit previously no("check/gate-horizon-python27/1dba20d/console.html") no("check/gate-tempest-dsvm-trove/c5950fc/console.html") + no("check/neutron-tempest-plugin-dvr-multinode-scenario" + "/42fb158/job-output.txt.gz") # NOTE(sdague): if we ever get edge conditions in the future, # please add checks in here.