Ray Milkey | 9237067 | 2017-02-21 10:30:43 -0800 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | |
| 3 | # ----------------------------------------------------------------------------- |
| 4 | # Invokes the ONOS CLI and looks for a 'maps' entry with the given name |
| 5 | # ----------------------------------------------------------------------------- |
| 6 | |
| 7 | import subprocess |
| 8 | import json |
| 9 | import sys |
| 10 | |
| 11 | if len(sys.argv) != 4: |
| 12 | print "usage: onos-find-and-check-map onos-node map-name should-be-zero" |
| 13 | sys.exit(1) |
| 14 | |
| 15 | node = sys.argv[1] |
| 16 | mapName = sys.argv[2] |
| 17 | shouldBeZero = sys.argv[3] |
| 18 | |
| 19 | cli = subprocess.Popen(["onos", node, "maps", "-j"], stdout=subprocess.PIPE) |
| 20 | json = json.loads(cli.communicate()[0]) |
| 21 | |
| 22 | for map in json: |
| 23 | foundMapName = map["name"] |
| 24 | foundMapSize = map["size"] |
| 25 | |
| 26 | print foundMapName |
| 27 | print foundMapSize |
| 28 | |
| 29 | if foundMapName == mapName: |
| 30 | if (shouldBeZero == 'yes' and foundMapSize == 0) or \ |
| 31 | (shouldBeZero != 'yes' and foundMapSize != 0): |
| 32 | sys.exit(0) |
| 33 | else: |
| 34 | sys.exit(1) |
| 35 | |
| 36 | sys.exit(1) |