X-Git-Url: https://gerrit.fd.io/r/gitweb?p=csit.git;a=blobdiff_plain;f=resources%2Flibraries%2Fpython%2FVppApiCrc.py;h=693dac064a93f182839b74424fc897a1cd22f33c;hp=94e2690d8b5d5c70659f1eb5c57b2fd20eb28f3f;hb=HEAD;hpb=d76d99af81585c10e778d761d862fca77a94bc35 diff --git a/resources/libraries/python/VppApiCrc.py b/resources/libraries/python/VppApiCrc.py index 94e2690d8b..a8947a18cb 100644 --- a/resources/libraries/python/VppApiCrc.py +++ b/resources/libraries/python/VppApiCrc.py @@ -1,4 +1,4 @@ -# Copyright (c) 2021 Cisco and/or its affiliates. +# Copyright (c) 2023 Cisco and/or its affiliates. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at: @@ -75,8 +75,9 @@ class VppApiCrcChecker: Starts the same as _expected, but each time an encountered api,crc pair fits the expectation, the pair is removed from all collections - within this mapping. Ideally, the active mappings will become empty. - If not, it is an error, VPP removed or renamed a message CSIT needs.""" + within this mapping. It is fine if an api is missing + from some collections, as long as it is not missing from all collections + that remained in _expected.""" self._found = dict() """Mapping from API name to CRC string. @@ -197,8 +198,8 @@ class VppApiCrcChecker: for item in reversed(msg_obj): if not isinstance(item, dict): continue - options = item.get(u"options", None) - if options is not None: + options = item.get(u"options", dict()) + if not options: break if version is None or version.startswith(u"0."): options[u"version"] = version @@ -325,12 +326,15 @@ class VppApiCrcChecker: if not report_missing: return missing = {name: mapp for name, mapp in self._missing.items() if mapp} - if missing: - missing_indented = json.dumps( - missing, indent=1, sort_keys=True, separators=[u",", u":"]) - self.log_and_raise( - f"API CRCs missing from .api.json:\n{missing_indented}" - ) + if set(missing.keys()) < set(self._expected.keys()): + # There is a collection where nothing is missing. + return + missing_indented = json.dumps( + missing, indent=1, sort_keys=True, separators=[u",", u":"] + ) + self.log_and_raise( + f"API CRCs missing from .api.json:\n{missing_indented}" + ) def check_api_name(self, api_name): """Fail if the api_name has no, or different from known CRC associated. @@ -373,10 +377,27 @@ class VppApiCrcChecker: if not matching: self._reported[api_name] = crc self.log_and_raise( - f"No active collection contains API {api_name!r} with CRC {crc!r}" + f"No active collection has API {api_name!r} with CRC {crc!r}" ) - options = self._options[api_name] + options = self._options.get(api_name, None) + if not options: + # None means CSIT is attempting a new API on an old VPP build. + # If that is an issue, the API has been reported as missing already. + return options.pop(u"vat_help", None) if options: self._reported[api_name] = crc logger.console(f"{api_name} used but has options {options}") + + def print_warnings(self): + """Call check_api_name for API names in surviving collections. + + Useful for VPP CRC checking job. + The API name is only checked when it appears + in all surviving collections. + """ + api_name_to_crc_maps = self._expected.values() + api_name_sets = (set(n2c.keys()) for n2c in api_name_to_crc_maps) + api_names = set.intersection(*api_name_sets) + for api_name in sorted(api_names): + self.check_api_name(api_name)