blob: dfe4df6e65aaf5a33bea5b92ac3b17f6154fb4d1 [file] [log] [blame]
Jordan Haltermancbbdb8c2017-12-20 18:12:26 -08001#! /usr/bin/env python
2
3import json
4import subprocess
5import sys
6import time
7
8if len(sys.argv) != 2:
9 print "usage: check-masters {node}"
10 sys.exit(1)
11
12node = sys.argv[1]
13
14def check_masters():
15 nodes_json = json.loads(subprocess.check_output(["onos", node, "nodes", "-j"]))
16 inactive_nodes = [n['id'] for n in nodes_json if n['state'] != 'READY']
17
18 masters_json = json.loads(subprocess.check_output(["onos", node, "masters", "-j"]))
19 masters = dict([(m['id'], m['devices']) for m in masters_json])
20
21 for inactive_node in inactive_nodes:
22 if inactive_node in masters:
23 devices = masters[inactive_node]
24 if len(devices) > 0:
25 return False
26 return True
27
28for i in range(10):
29 if not check_masters():
30 time.sleep(1)
31 else:
32 sys.exit(0)
33
34sys.exit(1)