Committed by
Brian O'Connor
Add python script to test host attachment points for the obelisk network
Change-Id: I68560a31cce8b12d9626cfdaa8cb5acc0f20dc12
Showing
1 changed file
with
91 additions
and
0 deletions
tools/test/topos/obeliskHostCheck.py
0 → 100755
| 1 | +#!/usr/bin/python | ||
| 2 | + | ||
| 3 | +import sys | ||
| 4 | +import os | ||
| 5 | +import json | ||
| 6 | + | ||
| 7 | +# TODO: if none given, use OCI | ||
| 8 | +try: | ||
| 9 | + onosIp = sys.argv[1] | ||
| 10 | + print "Reading hosts view from ONOS node " + onosIp + ":" | ||
| 11 | +except Exception as e: | ||
| 12 | + print "Error reading ONOS IP arguement" | ||
| 13 | + print e | ||
| 14 | +# Grab the json objects from ONOS | ||
| 15 | +output = os.popen("onos " + onosIp + " \"hosts -j\"" ) | ||
| 16 | +hosts = json.loads( output.read() ) | ||
| 17 | +#hosts = json.loads( output.split( 'Logging in as karaf\n' )[1] ) | ||
| 18 | + | ||
| 19 | +hostAttachment = True | ||
| 20 | +# FIXME: topo-HA/obelisk specific mappings: | ||
| 21 | +# key is mac and value is dpid | ||
| 22 | +mappings = {} | ||
| 23 | +for i in range( 1, 29 ): # hosts 1 through 28 | ||
| 24 | + # set up correct variables: | ||
| 25 | + macId = "00:" * 5 + hex( i ).split( "0x" )[1].upper().zfill(2) | ||
| 26 | + if i == 1: | ||
| 27 | + deviceId = "1000".zfill(16) | ||
| 28 | + elif i == 2: | ||
| 29 | + deviceId = "2000".zfill(16) | ||
| 30 | + elif i == 3: | ||
| 31 | + deviceId = "3000".zfill(16) | ||
| 32 | + elif i == 4: | ||
| 33 | + deviceId = "3004".zfill(16) | ||
| 34 | + elif i == 5: | ||
| 35 | + deviceId = "5000".zfill(16) | ||
| 36 | + elif i == 6: | ||
| 37 | + deviceId = "6000".zfill(16) | ||
| 38 | + elif i == 7: | ||
| 39 | + deviceId = "6007".zfill(16) | ||
| 40 | + elif i >= 8 and i <= 17: | ||
| 41 | + dpid = '3' + str( i ).zfill( 3 ) | ||
| 42 | + deviceId = dpid.zfill(16) | ||
| 43 | + elif i >= 18 and i <= 27: | ||
| 44 | + dpid = '6' + str( i ).zfill( 3 ) | ||
| 45 | + deviceId = dpid.zfill(16) | ||
| 46 | + elif i == 28: | ||
| 47 | + deviceId = "2800".zfill(16) | ||
| 48 | + mappings[ macId ] = deviceId | ||
| 49 | + | ||
| 50 | +if hosts or "Error" not in hosts: | ||
| 51 | + if hosts == []: | ||
| 52 | + print "WARNING: There are no hosts discovered" | ||
| 53 | + else: | ||
| 54 | + for host in hosts: | ||
| 55 | + mac = None | ||
| 56 | + location = None | ||
| 57 | + device = None | ||
| 58 | + port = None | ||
| 59 | + try: | ||
| 60 | + mac = host.get( 'mac' ) | ||
| 61 | + assert mac, "mac field could not be found for this host object" | ||
| 62 | + | ||
| 63 | + location = host.get( 'location' ) | ||
| 64 | + assert location, "location field could not be found for this host object" | ||
| 65 | + | ||
| 66 | + # Trim the protocol identifier off deviceId | ||
| 67 | + device = str( location.get( 'elementId' ) ).split(':')[1] | ||
| 68 | + assert device, "elementId field could not be found for this host location object" | ||
| 69 | + | ||
| 70 | + port = location.get( 'port' ) | ||
| 71 | + assert port, "port field could not be found for this host location object" | ||
| 72 | + | ||
| 73 | + # Now check if this matches where they should be | ||
| 74 | + if mac and device and port: | ||
| 75 | + if device != mappings[ str( mac ) ]: | ||
| 76 | + print "The attachment device is incorrect for host " + str( mac ) +\ | ||
| 77 | + ". Expected: " + mappings[ str( mac ) ] + "; Actual: " + device | ||
| 78 | + hostAttachment = False | ||
| 79 | + if str( port ) != "1": | ||
| 80 | + print "The attachment port is incorrect for host " + str( mac ) +\ | ||
| 81 | + ". Expected: 1; Actual: " + str( port) | ||
| 82 | + hostAttachment = False | ||
| 83 | + else: | ||
| 84 | + hostAttachment = False | ||
| 85 | + except AssertionError as e: | ||
| 86 | + print "ERROR: Json object not as expected:" | ||
| 87 | + print e | ||
| 88 | + print "host object: " + repr( host ) | ||
| 89 | + hostAttachment = False | ||
| 90 | +else: | ||
| 91 | + print "No hosts json output or \"Error\" in output. hosts = " + repr( hosts ) |
-
Please register or login to post a comment