feat(crc): print warnings in crc checker script
[csit.git] / resources / libraries / python / VppApiCrc.py
index 94e2690..761059f 100644 (file)
@@ -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:
@@ -197,8 +197,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
@@ -373,10 +373,25 @@ 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.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 every API name in surviving collections.
+
+        Useful for VPP CRC checking job.
+
+        Even though there usually is only one surviving collection,
+        the implementation has to be prepared for multiple collections,
+        and it should de-duplicate api names.
+        """
+        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().union(*api_name_sets)
+        for api_name in sorted(api_names):
+            self.check_api_name(api_name)