X-Git-Url: https://gerrit.fd.io/r/gitweb?p=csit.git;a=blobdiff_plain;f=resources%2Ftools%2Fintegrated%2Fcheck_crc.py;fp=resources%2Ftools%2Fintegrated%2Fcheck_crc.py;h=7930a534ca10fba4100a6e7645eeef499f4cfed3;hp=3d5c30a6d6cc911cee6867b68b2b91f8ed49cb72;hb=d7aec8ee052468f55e2e9bd27de1dedd918c8a37;hpb=54c4da90e4ddff97c066ad29c17ea3838ec45616 diff --git a/resources/tools/integrated/check_crc.py b/resources/tools/integrated/check_crc.py index 3d5c30a6d6..7930a534ca 100644 --- a/resources/tools/integrated/check_crc.py +++ b/resources/tools/integrated/check_crc.py @@ -1,4 +1,4 @@ -# Copyright (c) 2019 Cisco and/or its affiliates. +# Copyright (c) 2020 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: @@ -19,46 +19,68 @@ No executable flag, nor shebang, as most users do not have .api.json files downloaded to the correct place. """ +from __future__ import print_function import os.path as op import sys from resources.libraries.python.VppApiCrc import VppApiCrcChecker -# TODO: Read FDIO_VPP_DIR environment variable, or some other input, -# instead of using hardcoded relative path? -API_DIR = op.normpath(op.join( - op.dirname(op.abspath(__file__)), "..", "..", "..", "..", - "build-root", "install-vpp-native", "vpp", "share", "vpp", "api")) -CHECKER = VppApiCrcChecker(API_DIR) -try: - CHECKER.report_initial_conflicts(report_missing=True) -except RuntimeError as err: - sys.stderr.write("{err!r}\n".format(err=err)) - sys.stderr.write( - "\n" - "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n" - "\n" - "VPP CSIT API CHECK FAIL!\n" - "\n" - "This means the patch under test has missing messages,\n" - "or messages with unexpected CRCs compared to what CSIT needs.\n" - "Either this Change and/or its ancestors were editing .api files,\n" - "or your chain is not rebased upon the recent enough VPP codebase.\n" - "\n" - "Please rebase the patch to see if that fixes the problem.\n" - "If that fails email csit-dev@lists.fd.io for a new\n" - "operational branch supporting the api changes.\n" - "\n" - "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n" - ) - sys.exit(1) -else: - sys.stderr.write( - "\n" - "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n" - "\n" - "VPP CSIT API CHECK PASS!\n" - "\n" - "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n" - ) +def main(): + """Execute the logic, return the return code. + + From current location, construct path to .api file subtree, + initialize and run the CRC checker, print result consequences + to stderr, return the return code to return from the script. + + :returns: Return code to return. 0 if OK, 1 if CRC mismatch. + :rtype: int + """ + + # TODO: Read FDIO_VPP_DIR environment variable, or some other input, + # instead of using hardcoded relative path? + + api_dir = op.normpath(op.join( + op.dirname(op.abspath(__file__)), "..", "..", "..", "..", + "build-root", "install-vpp-native", "vpp", "share", "vpp", + "api" + )) + checker = VppApiCrcChecker(api_dir) + try: + checker.report_initial_conflicts(report_missing=True) + except RuntimeError as err: + stderr_lines = [ + "{err!r}".format(err=err), + "", + "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@", + "", + "VPP CSIT API CHECK FAIL!", + "", + "This means the patch under test has missing messages,", + "or messages with unexpected CRCs compared to what CSIT needs.", + "Either this Change and/or its ancestors were editing .api files,", + "or your chain is not rebased upon a recent enough VPP codebase.", + "", + "Please rebase the patch to see if that fixes the problem.", + "If that fails email csit-dev@lists.fd.io for a new", + "operational branch supporting the api changes.", + "", + "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@", + ] + ret_code = 1 + else: + stderr_lines = [ + "", + "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@", + "", + "VPP CSIT API CHECK PASS!", + "", + "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@", + ] + ret_code = 0 + for stderr_line in stderr_lines: + print(stderr_line, file=sys.stderr) + return ret_code + +if __name__ == "__main__": + sys.exit(main())