Remove unused views
[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 __author__ = 'Thanh Ha'
17
18
19 import fnmatch
20 import os
21 import re
22 import sys
23
24
25 def get_robot_systems(filename):
26     """Scan for robot vms.
27
28     Returns a list of Robot systems found in file.
29     """
30     robots = set()
31
32     with open(filename, 'r') as _file:
33         for num, line in enumerate(_file, 1):
34             if re.search('centos7-robot', line):
35                 robots.add(line.rsplit(maxsplit=1)[1])
36
37     return robots
38
39
40 if __name__ == "__main__":
41     robots = []
42     for root, dirnames, filenames in os.walk('jjb'):
43         for filename in fnmatch.filter(filenames, '*.yaml'):
44             robots += get_robot_systems(os.path.join(root, filename))
45
46     if len(robots) > 1:
47         print("ERROR: More than one robot system type definition detected.")
48         print("Please ensure that ALL templates use the same robot nodes.")
49         print("Infra does not support more than 1 robot node type in use.")
50         sys.exit(1)