Add VPP API CRC checking
[csit.git] / resources / tools / integrated / check_crc.py
1 # Copyright (c) 2019 Cisco and/or its affiliates.
2 # Licensed under the Apache License, Version 2.0 (the "License");
3 # you may not use this file except in compliance with the License.
4 # You may obtain a copy of the License at:
5 #
6 #     http://www.apache.org/licenses/LICENSE-2.0
7 #
8 # Unless required by applicable law or agreed to in writing, software
9 # distributed under the License is distributed on an "AS IS" BASIS,
10 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 # See the License for the specific language governing permissions and
12 # limitations under the License.
13
14 """
15 Script that fails if .api.json files downloaded to a hardcoded place
16 do not match CRC checksusms currently supported by CSIT.
17
18 No executable flag, nor shebang, as most users do not have .api.json
19 files downloaded to the correct place.
20 """
21
22 import os.path as op
23 import sys
24
25 from resources.libraries.python.VppApiCrc import VppApiCrcChecker
26
27 # TODO: Read FDIO_VPP_DIR environment variable, or some other input,
28 # instead of using hardcoded relative path?
29
30 api_dir = op.normpath(op.join(
31     op.dirname(op.abspath(__file__)), "..", "..", "..", "..",
32     "build-root", "install-vpp-native", "vpp", "share", "vpp", "api"))
33 checker = VppApiCrcChecker(api_dir)
34 try:
35     checker.report_initial_conflicts(report_missing=True)
36 except RuntimeError as err:
37     sys.stderr.write("{err!r}\n".format(err=err))
38     sys.stderr.write(
39         "\n"
40         "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n"
41         "\n"
42         "VPP CSIT API CHECK FAIL!\n"
43         "\n"
44         "This means the patch under test has missing messages,\n"
45         "or messages with unexpected CRCs compared to what CSIT needs.\n"
46         "Either this Change and/or its ancestors were editing .api files,\n"
47         "or your chain is not rebased upon the recent enough VPP codebase.\n"
48         "\n"
49         "Please rebase the patch to see if that fixes the problem.\n"
50         "If that fails email csit-dev@lists.fd.io for a new\n"
51         "operational branch supporting the api changes.\n"
52         "\n"
53         "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n"
54     )
55     sys.exit(1)
56 else:
57     sys.stderr.write(
58         "\n"
59         "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n"
60         "\n"
61         "VPP CSIT API CHECK PASS!\n"
62         "\n"
63         "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n"
64     )