Masayoshi Kobayashi | e4a551d | 2013-04-07 04:56:09 +0000 | [diff] [blame] | 1 | #! /usr/bin/env python |
| 2 | import json |
| 3 | import sys |
| 4 | import os |
| 5 | import re |
| 6 | from check_status import * |
| 7 | import time |
| 8 | |
| 9 | flowdef="flowdef_8node_252.txt" |
| 10 | basename="onosdevz" |
| 11 | operation=["sw3-eth4 down","sw4-eth4 down","sw4-eth3 down","sw3-eth4 up","sw1-eth2 down","sw4-eth4 up","sw4-eth3 up","sw1-eth2 up"] |
| 12 | |
| 13 | def check_by_pingall(): |
| 14 | buf = "" |
| 15 | cmd = "dsh -w %s1 \"cd ONOS/web; ./pingallm.py %s\"" % (basename, flowdef) |
| 16 | result = os.popen(cmd).read() |
| 17 | buf += result |
| 18 | |
| 19 | if re.search("fail 0", result): |
| 20 | return (0, buf) |
| 21 | else: |
| 22 | return (1, buf) |
| 23 | |
| 24 | def link_change_core(op): |
| 25 | cmd = "dsh -w %s1 \"sudo ifconfig %s\"" % (basename, op) |
| 26 | os.popen(cmd) |
| 27 | print cmd |
| 28 | |
| 29 | def check_flow_nmap(): |
| 30 | buf = "" |
| 31 | buf += os.popen("date").read() |
| 32 | print "dump all flows from network map" |
| 33 | cmd = "dsh -w %s1 \"cd ONOS/web; ./get_flow.py all\"" % cluster_basename |
| 34 | buf += os.popen(cmd).read() |
| 35 | return (0, buf) |
| 36 | |
| 37 | def check_flow_raw(): |
| 38 | buf = "" |
| 39 | print "dump all flows from switches" |
| 40 | cmd = "dsh \"cd ONOS/scripts; ./showflow.sh\"" |
| 41 | buf += os.popen(cmd).read() |
| 42 | return (0, buf) |
| 43 | |
| 44 | def dump_json(url, filename): |
| 45 | f = open(filename, 'w') |
| 46 | buf = "" |
| 47 | command = "curl -s %s" % (url) |
| 48 | result = os.popen(command).read() |
| 49 | buf += json.dumps(json.loads(result), sort_keys = True, indent = 2) |
| 50 | f.write(buf) |
| 51 | f.close() |
| 52 | |
| 53 | def check_rest(cycle, n): |
| 54 | url="http://%s:%s/wm/core/topology/switches/all/json" % (RestIP, RestPort) |
| 55 | filename = "rest-sw-log.%d.%d.log" % (cycle, n) |
| 56 | dump_json(url, filename) |
| 57 | |
| 58 | filename = "rest-link-log.%d.%d.log" % (cycle, n) |
| 59 | url = "http://%s:%s/wm/core/topology/links/json" % (RestIP, RestPort) |
| 60 | dump_json(url, filename) |
| 61 | |
| 62 | url = "http://%s:%s/wm/registry/switches/json" % (RestIP, RestPort) |
| 63 | filename = "rest-reg-sw-log.%d.%d.log" % (cycle, n) |
| 64 | dump_json(url, filename) |
| 65 | |
| 66 | url = "http://%s:%s/wm/registry/controllers/json" % (RestIP, RestPort) |
| 67 | filename = "rest-reg-ctrl-log.%d.%d.log" % (cycle, n) |
| 68 | dump_json(url, filename) |
| 69 | |
| 70 | url = "http://%s:%s/wm/flow/getsummary/0/0/json" % (RestIP, RestPort) |
| 71 | filename = "rest-flow-log.%d.%d.log" % (cycle, n) |
| 72 | dump_json(url, filename) |
| 73 | |
| 74 | if __name__ == "__main__": |
| 75 | print "%s" % check_switch()[1] |
| 76 | print "%s" % check_link()[1] |
| 77 | print "%s" % check_controllers(8)[1] |
| 78 | (code, result) = check_by_pingall() |
| 79 | print result |
| 80 | k = raw_input('hit any key>') |
| 81 | |
| 82 | |
| 83 | for cycle in range(1000): |
| 84 | for n, op in enumerate(operation): |
| 85 | print "==== Cycle %d operation %d ====" % (cycle, n) |
| 86 | link_change_core(op) |
| 87 | print "wait 30 sec" |
| 88 | time.sleep(30) |
| 89 | print "check by pingall" |
| 90 | (code, result) = check_by_pingall() |
| 91 | if code == 0: |
| 92 | print "ping success %s" % (result) |
| 93 | else: |
| 94 | print "pingall failed (%d, %d). Collecting logs" % (cycle, n) |
| 95 | error = "error-log.%d.%d.log" % (cycle, n) |
| 96 | nmapflow = "nmap-flow-log.%d.%d.log" % (cycle, n) |
| 97 | rawflow = "raw-flow-log.%d.%d.log" % (cycle, n) |
| 98 | |
| 99 | f = open(error, 'w') |
| 100 | f.write(result) |
| 101 | f.write(check_switch()[1]) |
| 102 | f.write(check_link()[1]) |
| 103 | f.write(check_switch_local()[1]) |
| 104 | f.write(check_controllers(8)[1]) |
| 105 | f.close() |
| 106 | |
| 107 | f = open(nmapflow,'w') |
| 108 | f.write(check_flow_nmap()[1]) |
| 109 | f.close() |
| 110 | |
| 111 | f = open(rawflow,'w') |
| 112 | f.write(check_flow_raw()[1]) |
| 113 | f.close() |
| 114 | check_rest(cycle,n) |
| 115 | |
| 116 | |