Merge "Update cloud image Ubuntu18.04 mininet ovs"
[releng/builder.git] / check_robot.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 we are only ever using one robot system.
11
12 Due to the way the Jenkins OpenStack Cloud plugin works we can only limit
13 max parallel robot systems by the VM. So having multiple VM types makes it
14 very difficult for us to properly limit the amount of parallel robot runs.
15 """
16
17 __author__ = "Thanh Ha"
18
19
20 import fnmatch
21 import os
22 import re
23 import sys
24
25
26 def get_robot_systems(filename):
27     """Scan for robot vms.
28
29     Returns a list of Robot systems found in file.
30     """
31     robots = set()
32
33     with open(filename, "r") as _file:
34         for num, line in enumerate(_file, 1):
35             if re.search("centos[78]-robot", line):
36                 robots.add(line.rsplit(maxsplit=1)[1])
37
38     return robots
39
40
41 if __name__ == "__main__":
42     robots = []
43     for root, dirnames, filenames in os.walk("jjb"):
44         for filename in fnmatch.filter(filenames, "*.yaml"):
45             robots += get_robot_systems(os.path.join(root, filename))
46
47     if len(robots) > 1:
48         print("ERROR: More than one robot system type definition detected.")
49         print("Please ensure that ALL templates use the same robot nodes.")
50         print("Infra does not support more than 1 robot node type in use.")
51         sys.exit(1)