Example #1
0
 def runCpuLimitTest(self, cpu, duration=5):
     """run CPU limit test with 'while true' processes.
     cpu: desired CPU fraction of each host
     duration: test duration in seconds
     returns a single list of measured CPU fractions as floats.
     """
     pct = cpu * 100
     info('*** Testing CPU %.0f%% bandwidth limit\n' % pct)
     hosts = self.hosts
     for h in hosts:
         h.cmd('while true; do a=1; done &')
     pids = [h.cmd('echo $!').strip() for h in hosts]
     pids_str = ",".join(["%s" % pid for pid in pids])
     cmd = 'ps -p %s -o pid,%%cpu,args' % pids_str
     # It's a shame that this is what pylint prefers
     outputs = []
     for _ in range(duration):
         sleep(1)
         outputs.append(quietRun(cmd).strip())
     for h in hosts:
         h.cmd('kill %1')
     cpu_fractions = []
     for test_output in outputs:
         # Split by line.  Ignore first line, which looks like this:
         # PID %CPU COMMAND\n
         for line in test_output.split('\n')[1:]:
             r = r'\d+\s*(\d+\.\d+)'
             m = re.search(r, line)
             if m is None:
                 error('*** Error: could not extract CPU fraction: %s\n' %
                       line)
                 return None
             cpu_fractions.append(float(m.group(1)))
     output('*** Results: %s\n' % cpu_fractions)
     return cpu_fractions
Example #2
0
 def runCpuLimitTest( self, cpu, duration=5 ):
     """run CPU limit test with 'while true' processes.
     cpu: desired CPU fraction of each host
     duration: test duration in seconds
     returns a single list of measured CPU fractions as floats.
     """
     pct = cpu * 100
     info('*** Testing CPU %.0f%% bandwidth limit\n' % pct)
     hosts = self.hosts
     for h in hosts:
         h.cmd( 'while true; do a=1; done &' )
     pids = [h.cmd( 'echo $!' ).strip() for h in hosts]
     pids_str = ",".join(["%s" % pid for pid in pids])
     cmd = 'ps -p %s -o pid,%%cpu,args' % pids_str
     # It's a shame that this is what pylint prefers
     outputs = []
     for _ in range( duration ):
         sleep( 1 )
         outputs.append( quietRun( cmd ).strip() )
     for h in hosts:
         h.cmd( 'kill %1' )
     cpu_fractions = []
     for test_output in outputs:
         # Split by line.  Ignore first line, which looks like this:
         # PID %CPU COMMAND\n
         for line in test_output.split('\n')[1:]:
             r = r'\d+\s*(\d+\.\d+)'
             m = re.search( r, line )
             if m is None:
                 error( '*** Error: could not extract CPU fraction: %s\n' %
                        line )
                 return None
             cpu_fractions.append( float( m.group( 1 ) ) )
     output( '*** Results: %s\n' % cpu_fractions )
     return cpu_fractions
Example #3
0
 def iperf(self, hosts=None, l4Type='TCP', udpBw='10M'):
     """Run iperf between two hosts.
        hosts: list of hosts; if None, uses opposite hosts
        l4Type: string, one of [ TCP, UDP ]
        returns: results two-element array of server and client speeds"""
     if not quietRun('which telnet'):
         error('Cannot find telnet in $PATH - required for iperf test')
         return
     if not hosts:
         hosts = [self.hosts[0], self.hosts[-1]]
     else:
         assert len(hosts) == 2
     client, server = hosts
     output('*** Iperf: testing ' + l4Type + ' bandwidth between ')
     output("%s and %s\n" % (client.name, server.name))
     server.cmd('killall -9 iperf')
     iperfArgs = 'iperf '
     bwArgs = ''
     if l4Type == 'UDP':
         iperfArgs += '-u '
         bwArgs = '-b ' + udpBw + ' '
     elif l4Type != 'TCP':
         raise Exception('Unexpected l4 type: %s' % l4Type)
     server.sendCmd(iperfArgs + '-s', printPid=True)
     servout = ''
     while server.lastPid is None:
         servout += server.monitor()
     if l4Type == 'TCP':
         while 'Connected' not in client.cmd(
                 'sh -c "echo A | telnet -e A %s 5001"' % server.IP()):
             output('waiting for iperf to start up...')
             sleep(.5)
     cliout = client.cmd(iperfArgs + '-t 5 -c ' + server.IP() + ' ' +
                         bwArgs)
     debug('Client output: %s\n' % cliout)
     server.sendInt()
     servout += server.waitOutput()
     debug('Server output: %s\n' % servout)
     result = [self._parseIperf(servout), self._parseIperf(cliout)]
     if l4Type == 'UDP':
         result.insert(0, udpBw)
     output('*** Results: %s\n' % result)
     return result
Example #4
0
 def iperf( self, hosts=None, l4Type='TCP', udpBw='10M' ):
     """Run iperf between two hosts.
        hosts: list of hosts; if None, uses opposite hosts
        l4Type: string, one of [ TCP, UDP ]
        returns: results two-element array of server and client speeds"""
     if not quietRun( 'which telnet' ):
         error( 'Cannot find telnet in $PATH - required for iperf test' )
         return
     if not hosts:
         hosts = [ self.hosts[ 0 ], self.hosts[ -1 ] ]
     else:
         assert len( hosts ) == 2
     client, server = hosts
     output( '*** Iperf: testing ' + l4Type + ' bandwidth between ' )
     output( "%s and %s\n" % ( client.name, server.name ) )
     server.cmd( 'killall -9 iperf' )
     iperfArgs = 'iperf '
     bwArgs = ''
     if l4Type == 'UDP':
         iperfArgs += '-u '
         bwArgs = '-b ' + udpBw + ' '
     elif l4Type != 'TCP':
         raise Exception( 'Unexpected l4 type: %s' % l4Type )
     server.sendCmd( iperfArgs + '-s', printPid=True )
     servout = ''
     while server.lastPid is None:
         servout += server.monitor()
     if l4Type == 'TCP':
         while 'Connected' not in client.cmd(
                 'sh -c "echo A | telnet -e A %s 5001"' % server.IP()):
             output('waiting for iperf to start up...')
             sleep(.5)
     cliout = client.cmd( iperfArgs + '-t 5 -c ' + server.IP() + ' ' +
                          bwArgs )
     debug( 'Client output: %s\n' % cliout )
     server.sendInt()
     servout += server.waitOutput()
     debug( 'Server output: %s\n' % servout )
     result = [ self._parseIperf( servout ), self._parseIperf( cliout ) ]
     if l4Type == 'UDP':
         result.insert( 0, udpBw )
     output( '*** Results: %s\n' % result )
     return result