Jordan Halterman | cbbdb8c | 2017-12-20 18:12:26 -0800 | [diff] [blame] | 1 | #! /usr/bin/env python |
| 2 | |
| 3 | import json |
| 4 | import subprocess |
| 5 | import sys |
| 6 | import time |
| 7 | |
| 8 | if len(sys.argv) != 2: |
| 9 | print "usage: check-masters {node}" |
| 10 | sys.exit(1) |
| 11 | |
| 12 | node = sys.argv[1] |
| 13 | |
| 14 | def 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 | |
| 28 | for i in range(10): |
| 29 | if not check_masters(): |
| 30 | time.sleep(1) |
| 31 | else: |
| 32 | sys.exit(0) |
| 33 | |
| 34 | sys.exit(1) |