Author: gnichols
Date: 2011-03-08 13:05:26 +0000 (Tue, 08 Mar 2011)
New Revision: 791
Modified:
trunk/tests/network/network.py
Log:
680225 - network test should use HTTP for file transfer tests rather than NFS
Modified: trunk/tests/network/network.py
===================================================================
--- trunk/tests/network/network.py 2011-03-08 12:57:20 UTC (rev 790)
+++ trunk/tests/network/network.py 2011-03-08 13:05:26 UTC (rev 791)
@@ -21,6 +21,7 @@
import sys
import re
import time
+import urllib2
# sys.path.append("/home/gnichols/devel/v7")
from v7.tags import Constants, DeviceClass
@@ -29,6 +30,8 @@
from v7.v7kudzu import Kudzu
from v7.command import Command, V7CommandException
from v7.environment import Environment
+from v7.hash import hashModule
+from v7.http import V7Http
FAILED = 1
PASSED = 0
@@ -301,10 +304,6 @@
return None
def createTestFile(self):
- try:
- os.remove(self.testFile)
- except OSError:
- pass
if not self.getInterfaceSpeed():
print "Warning: Unable to determine interface speed"
@@ -312,9 +311,24 @@
else:
print "interface speed is %u Mb/s" % self.interfaceSpeed
- returnValue = os.system("dd if=/dev/urandom of=%s bs=128k count=%s" %
(self.testFile, self.interfaceSpeed))
- return returnValue == 0
+ return self.regenerateTestFile()
+ def regenerateTestFile(self):
+ try:
+ os.remove(self.testFile)
+ except OSError:
+ pass
+
+ dd = Command("dd if=/dev/urandom of=%s bs=128k count=%s" %
(self.testFile, self.interfaceSpeed))
+ try:
+ dd.run()
+ except V7CommandException, exception:
+ # dd shows output on stderr, ignore this
+ pass
+
+ return True
+
+
def getInterfaceSpeed(self):
# default to 100 Mb/s
self.interfaceSpeed = 0
@@ -337,15 +351,24 @@
# icmpTest uses ping with various packet sizes
def icmpTest(self):
- packetSizes = [0, 1, 240, 256, 1024, 2000, 10000, 40000, 65507]
- for size in packetSizes:
- sizeParam = ""
- if size > 0:
- sizeParam = "-s %s" % size
- (input, pingPipe) = os.popen4("/bin/ping -f -c 1000 %s %s" %
(sizeParam, self.getTestServer()))
- returnValue = self.printPipe(pingPipe)
- if returnValue:
- return False
+ # (<bytes in packet>, <percent lost for warning>)
+ packetSizes = [(0, 0), (1, 0), (240, 10), (256, 15), (1024, 20), (2000, 30),
(10000, 40), (40000, 60), (65507, 80)]
+ try:
+ for (size, warnLoss) in packetSizes:
+ sizeParam = ""
+ if size > 0:
+ sizeParam = "-s %s" % size
+ ping = Command("/bin/ping -i 0 -q -c 1000 %s %s" % (sizeParam,
self.getTestServer()))
+ print ping.command
+ packetLoss = ping.getString(regex="^.*,
(?P<packetLoss>[0-9]+)% packet loss.*$", regexGroup="packetLoss",
singleLine=False)
+ ping.printOutput()
+ if int(packetLoss) > warnLoss:
+ print "Warning: packet loss of %s%% is greater than %s%%
expected" % (packetLoss, warnLoss)
+ except V7CommandException, exception:
+ print "Error:"
+ print exception
+ ping.printErrors()
+ return False
# otherwise
return True
@@ -574,6 +597,76 @@
print "%u mbit received in %u sec ( %.2f mbit/s)" % (mbit, rxtime,
mbit/rxtime)
return True # success
+ def httpTransferTest(self):
+ """ transfer a file to the server via POST, then pull it back via
GET and compare the files """
+ errorCount = 0
+ for count in range(1,5):
+ self.regenerateTestFile()
+ (sentFileCheckSum, uploadIPAddress) = self.httpUpload()
+ if not uploadIPAddress:
+ errorCount += 1
+ continue
+ receivedFileCheckSum = self.httpDownload(uploadIPAddress)
+ if sentFileCheckSum == receivedFileCheckSum:
+ print "Checksums Match"
+ else:
+ print "Error: checksum %s does not match the file that was
sent" % receivedFileCheckSum
+ errorCount += 1
+ if errorCount > 0:
+ print "Http test had %u errors" % errorCount
+ return (errorCount is 0)
+
+ def httpUpload(self):
+ # getMD5 checksum
+ m=hashModule.md5()
+ sentFile = open(self.testFile, "rb")
+ m.update(sentFile.read())
+ sentFile.close()
+ sentCheckSum=m.hexdigest()
+ request = V7Http(self.getTestServer(), "/v7/cgi/networkTest.py")
+ if not request.addFile(self.testFile):
+ eturn (None, None)
+ # otherwise
+ print "sending file %s hash: %s" % (self.testFile, sentCheckSum)
+ startTime = time.time()
+ (size, response) = request.send()
+ stopTime = time.time()
+ if not response:
+ # send failed
+ return (None, None)
+ print "response: "
+ print response
+ print "Upload took %.2f seconds, %.2f MB/sec" % (stopTime-startTime,
size/((stopTime-startTime)*1000000))
+
+ #get the requests' IP address as seen by the server
+ pattern = re.compile("[0-9]+\.[0-9]+\.[0-9]+\.[0-9]")
+ match = pattern.search(response)
+ if match:
+ uploadIPAddress = match.group()
+ else:
+ "Warning: could not read upload IP address from response, assuming
device IP address"
+ uploadIPAddress = self.ipAddress
+
+ return (sentCheckSum, uploadIPAddress)
+
+ def httpDownload(self, uploadIPAddress):
+ # GET the file back
+ fileURL = 'http://%s/v7/store/%s/%s' % (self.getTestServer(),
uploadIPAddress, os.path.basename(self.testFile))
+ print "getting file %s " % fileURL
+ sys.stdout.flush()
+ request = urllib2.Request(fileURL)
+ opener = urllib2.build_opener()
+
+ startTime = time.time()
+ response = opener.open(request).read()
+ stopTime = time.time()
+ print "Download took %.2f seconds, %.2f MB/sec" % (stopTime-startTime,
len(response)/((stopTime-startTime)*1000000))
+
+ m=hashModule.md5()
+ m.update(response)
+ return m.hexdigest()
+
+
def printInfo(self):
# YK: grab NIC info and running status
sys.stdout.flush()
@@ -642,7 +735,7 @@
success = True
if not self.runSubTest(self.tcpTest, "TCP", "tcp latency and
bandwidth test via lmbench"):
success = False
- if not self.runSubTest(self.nfsTest, "NFS", "NFS file transfer
test"):
+ if not self.runSubTest(self.nfsTest, "HTTP", "HTTP file transfer
test"):
success = False
if not self.runSubTest(self.icmpTest, "ICMP"):
success = False