-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathprototest.py
executable file
·61 lines (38 loc) · 1.57 KB
/
prototest.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#! /usr/bin/env python
import commands
import string
import sys
import os
import time
usbTestCommand = './usbtest -t usb -a <ip>:8321 | tee <ip>.tmp'
rmCommand = "rm <ip>.tmp"
#processCommand = 'grep -i "got status" <ip>.tmp | grep -v -i "enoent" | grep -v -i "epipe" | wc -l'
#processCommand = 'grep -i "got status" <ip>.tmp | grep -v -i "enoent" | grep -v -i "epipe" | grep -v -i "eproto" |wc -l'
processCommand = 'egrep -i "port error on port| 500 msec" <ip>.tmp | wc -l'
# handle arguments
if (len(sys.argv) != 2):
print "Usage: prototest.py <ip>"
print "TEST FAILED"
sys.exit(1)
# should do a reg expression to make sure the ip is ok....
pano_ip = sys.argv[1]
#print "Running USB protocol test on %s" % pano_ip
print "Running USB port test on %s" % pano_ip
# kick off the protocol error test... with a grep...feed it into a word count
usbTestCommand = string.replace(usbTestCommand, "<ip>", pano_ip)
rmCommand = string.replace(rmCommand, "<ip>", pano_ip)
processCommand = string.replace(processCommand, "<ip>", pano_ip)
os.system(usbTestCommand)
time.sleep(30) # extra time to clear out the io buffers, finish tests, etc.
processResult = commands.getoutput(processCommand)
#print "Protocol Errors detected from %s: %s" % (pano_ip, processResult)
print "Port Errors detected from %s: %s" % (pano_ip, processResult)
# check for zeros in the word count
if (string.strip(processResult) == "0"):
# TEST PASSED on a match of zero
print "Test has PASSED"
else:
# TEST FAILED on a match of anything else
print "Test has FAILED"
os.system(rmCommand)
sys.exit(0)