serialize_package_info: parse argument to allow other types
Allow the function to log and parse other types so we can instantly
convert all usages of CPVToPackageInfo, and search the logs for deeper
instances of CPV/SplitCPV usages.
BUG=b:187792048
TEST=run_tests
Change-Id: Ie16132fc27caa7a073ba3ef5bd5bf9b7e37240f5
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/chromite/+/3152623
Tested-by: Alex Klein <saklein@chromium.org>
Reviewed-by: Chris McDonald <cjmcdonald@chromium.org>
Reviewed-by: Sergey Frolov <sfrolov@google.com>
Commit-Queue: Alex Klein <saklein@chromium.org>
diff --git a/api/controller/controller_util.py b/api/controller/controller_util.py
index 341f5d2..0bf8f17 100644
--- a/api/controller/controller_util.py
+++ b/api/controller/controller_util.py
@@ -3,6 +3,7 @@
# found in the LICENSE file.
"""Utility functions that are useful for controllers."""
+import logging
from chromite.api.gen.chromite.api import sysroot_pb2
from chromite.api.gen.chromiumos import common_pb2
@@ -154,8 +155,16 @@
package_info_msg.version = cpv.version
-def serialize_package_info(pkg_info: 'package_info.PackageInfo', pkg_info_msg):
+def serialize_package_info(pkg_info: package_info.PackageInfo,
+ pkg_info_msg: common_pb2.PackageInfo):
"""Serialize a PackageInfo object to a PackageInfo proto."""
+ if not isinstance(pkg_info, package_info.PackageInfo):
+ # Allows us to swap everything to serialize_package_info, and search the
+ # logs for usages that aren't passing though a PackageInfo yet.
+ logging.warning(
+ 'serialize_package_info: Got a %s instead of a PackageInfo.',
+ type(pkg_info))
+ pkg_info = package_info.parse(pkg_info)
pkg_info_msg.package_name = pkg_info.package
if pkg_info.category:
pkg_info_msg.category = pkg_info.category