From 74bdfde76393764485cfb4667d94589468261dd4 Mon Sep 17 00:00:00 2001 From: Vratko Polak Date: Tue, 13 Aug 2019 10:20:26 +0200 Subject: Revert "Disable CRC checking at runtime" Needed to verify CSIT expects the correct CRCs. This reverts commit d541b2b7d99651b53bd21ff75cd5fdacf8472a98. This reverts commit 2dd27f5a638b5231c0f074ca61e6b67fed9d1faf. + Some pylint related improvements since then. + Less and better documented caching to class fields. + Global kill switch in Constants. Change-Id: Id459800744cd93c578eab9c2e84cb9528235b064 Signed-off-by: Vratko Polak --- resources/libraries/python/VppApiCrc.py | 38 +++++++++++++++++++++++++-------- 1 file changed, 29 insertions(+), 9 deletions(-) (limited to 'resources/libraries/python/VppApiCrc.py') diff --git a/resources/libraries/python/VppApiCrc.py b/resources/libraries/python/VppApiCrc.py index 0d4e8f4f0c..d66d4d7568 100644 --- a/resources/libraries/python/VppApiCrc.py +++ b/resources/libraries/python/VppApiCrc.py @@ -19,6 +19,7 @@ import yaml from robot.api import logger +from resources.libraries.python.Constants import Constants def _str(text): """Convert from possible unicode without interpreting as number. @@ -42,7 +43,8 @@ class VppApiCrcChecker(object): so make sure the calling libraries have appropriate robot library scope. For usual testing, it means "GLOBAL" scope.""" - def __init__(self, directory): + def __init__(self, directory, + fail_on_mismatch=Constants.CRC_MISMATCH_FAILS_TEST): """Initialize empty state, then register known collections. This also scans directory for .api.json files @@ -52,6 +54,11 @@ class VppApiCrcChecker(object): :type directory: str """ + self.fail_on_mismatch = fail_on_mismatch + """If True, mismatch leads to test failure, by raising exception. + If False, the mismatch is logged, but the test is allowed to continue. + """ + self._expected = dict() """Mapping from collection name to mapping from API name to CRC string. @@ -89,6 +96,16 @@ class VppApiCrcChecker(object): self._register_all() self._check_dir(directory) + def raise_or_log(self, exception): + """If fail_on_mismatch, raise, else log to console the exception. + + :param exception: The exception to raise or log. + :type exception: RuntimeError + """ + if self.fail_on_mismatch: + raise exception + logger.console("{exc!r}".format(exc=exception)) + def _register_collection(self, collection_name, name_to_crc_mapping): """Add a named (copy of) collection of CRCs. @@ -243,20 +260,23 @@ class VppApiCrcChecker(object): :param report_missing: Whether to raise on missing messages. :type report_missing: bool - :raises RuntimeError: If CRC mismatch or missing messages are detected. + :raises RuntimeError: If CRC mismatch or missing messages are detected, + and fail_on_mismatch is True. """ if self._initial_conflicts_reported: return self._initial_conflicts_reported = True if self._reported: - raise RuntimeError("Dir check found incompatible API CRCs: {rep!r}"\ - .format(rep=self._reported)) + self.raise_or_log( + RuntimeError("Dir check found incompatible API CRCs: {rep!r}"\ + .format(rep=self._reported))) if not report_missing: return missing = {name: mapp for name, mapp in self._missing.items() if mapp} if missing: - raise RuntimeError("Dir check found missing API CRCs: {mis!r}"\ - .format(mis=missing)) + self.raise_or_log( + RuntimeError("Dir check found missing API CRCs: {mis!r}"\ + .format(mis=missing))) def check_api_name(self, api_name): """Fail if the api_name has no known CRC associated. @@ -285,6 +305,6 @@ class VppApiCrcChecker(object): return crc = self._found.get(api_name, None) self._reported[api_name] = crc - # Disabled temporarily during CRC mismatch. - #raise RuntimeError("No active collection has API {api!r}" - # " CRC found {crc!r}".format(api=api_name, crc=crc)) + self.raise_or_log( + RuntimeError("No active collection has API {api!r}" + " CRC found {crc!r}".format(api=api_name, crc=crc))) -- cgit 1.2.3-korg