Merge "Update cloud image Ubuntu18.04 mininet ovs"
[releng/builder.git] / check_jjb_version.py
1 # SPDX-License-Identifier: EPL-1.0
2 ##############################################################################
3 # Copyright (c) 2018 The Linux Foundation and others.
4 #
5 # All rights reserved. This program and the accompanying materials
6 # are made available under the terms of the Eclipse Public License v1.0
7 # which accompanies this distribution, and is available at
8 # http://www.eclipse.org/legal/epl-v10.html
9 ##############################################################################
10 """Ensures that the jjb-version in tox and releng-jobs.yaml match."""
11
12 __author__ = "Thanh Ha"
13
14
15 import os
16 import re
17 import sys
18
19
20 def check_jjb_version(tox_file, releng_jobs_file):
21     """Check that JJB version matches in job cfg and tox.ini."""
22     with open(tox_file, "r") as _file:
23         for num, line in enumerate(_file, 1):
24             if re.search("env:JJB_VERSION:", line):
25                 jjb_version_tox = line.rsplit(":", 1)[1].replace("}", "").strip()
26                 break
27
28     with open(releng_jobs_file, "r") as _file:
29         for num, line in enumerate(_file, 1):
30             if re.search("jjb-version: ", line):
31                 jjb_version = line.rsplit(":", 1)[1].strip()
32                 break
33
34     print("JJB version in jjb/releng-jobs.yaml: {}".format(jjb_version))
35     print("JJB version in tox.ini: {}".format(jjb_version_tox))
36
37     if jjb_version != jjb_version_tox:
38         print("ERROR: JJB version in jjb/releng-jobs.yaml and tox.ini MUST match.")
39         sys.exit(1)
40
41
42 if __name__ == "__main__":
43     check_jjb_version("tox.ini", os.path.join("jjb", "releng-jobs.yaml"))