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
This commit is contained in:
Clark Boylan 2018-04-17 15:33:38 -07:00
parent 33ee1b89b8
commit 0f40dfd634
2 changed files with 14 additions and 8 deletions

View File

@ -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

View File

@ -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.