diff options
Diffstat (limited to 'testsuites/vstf/vstf_scripts/vstf/agent/env/fsmonitor/FSMonitor.py')
-rw-r--r-- | testsuites/vstf/vstf_scripts/vstf/agent/env/fsmonitor/FSMonitor.py | 62 |
1 files changed, 39 insertions, 23 deletions
diff --git a/testsuites/vstf/vstf_scripts/vstf/agent/env/fsmonitor/FSMonitor.py b/testsuites/vstf/vstf_scripts/vstf/agent/env/fsmonitor/FSMonitor.py index e6559362..53cddebb 100644 --- a/testsuites/vstf/vstf_scripts/vstf/agent/env/fsmonitor/FSMonitor.py +++ b/testsuites/vstf/vstf_scripts/vstf/agent/env/fsmonitor/FSMonitor.py @@ -23,6 +23,7 @@ LOG = logging.getLogger('__name__') class VMOperation(object): + def __init__(self): self.RTE_SDK = '/home/dpdk-2.0.0' self.RTE_TARGET = 'x86_64-native-linuxapp-gcc' @@ -46,7 +47,8 @@ class VMOperation(object): for mac in tap_macs: bdf = self.ip_helper.mac_bdf_map[mac] bdf_str = bdf_str + ' ' + bdf - cmd = 'python %s/tools/dpdk_nic_bind.py --bind=virtio-pci %s' % (self.RTE_SDK, bdf_str) + cmd = 'python %s/tools/dpdk_nic_bind.py --bind=virtio-pci %s' % ( + self.RTE_SDK, bdf_str) LOG.debug("recover_nic_binding runs cmd = %s", cmd) check_call(cmd, shell=True) @@ -60,15 +62,22 @@ class VMOperation(object): check_call("mount -t hugetlbfs nodev /mnt/huge", shell=True) check_call("modprobe uio", shell=True) check_and_rmmod('igb_uio') - check_call("insmod %s/%s/kmod/igb_uio.ko" % (RTE_SDK, RTE_TARGET), shell=True) + check_call( + "insmod %s/%s/kmod/igb_uio.ko" % + (RTE_SDK, RTE_TARGET), shell=True) bdf_str = '' for mac in tap_macs: bdf = self.ip_helper.mac_bdf_map[mac] bdf_str = bdf_str + ' ' + bdf - check_call('python %s/tools/dpdk_nic_bind.py --bind=igb_uio %s' % (RTE_SDK, bdf_str), shell=True) - cpu_num = int(check_output('cat /proc/cpuinfo | grep processor | wc -l', shell=True)) + check_call( + 'python %s/tools/dpdk_nic_bind.py --bind=igb_uio %s' % + (RTE_SDK, bdf_str), shell=True) + cpu_num = int( + check_output( + 'cat /proc/cpuinfo | grep processor | wc -l', + shell=True)) cpu_bit_mask = 0 i = cpu_num while i: @@ -76,14 +85,7 @@ class VMOperation(object): i -= 1 cpu_bit_mask = hex(cpu_bit_mask) cmd = "%s/%s/app/testpmd -c %s -n %d -- --disable-hw-vlan --disable-rss --nb-cores=%d --rxq=%d --txq=%d --rxd=4096 --txd=4096" % ( - RTE_SDK, - RTE_TARGET, - cpu_bit_mask, - cpu_num / 2, - cpu_num - 1, - (cpu_num - 1) / 2, - (cpu_num - 1) / 2 - ) + RTE_SDK, RTE_TARGET, cpu_bit_mask, cpu_num / 2, cpu_num - 1, (cpu_num - 1) / 2, (cpu_num - 1) / 2) LOG.info("set_pktloop_dpdk runs cmd = %s", cmd) p = subprocess.Popen(cmd.split()) if not p.poll(): @@ -105,6 +107,7 @@ class VMOperation(object): class FSMonitor(object): + def __init__(self, pidfile=None, interval=1): if pidfile: self.pidfile = pidfile @@ -121,8 +124,9 @@ class FSMonitor(object): pass def kill_old(self): - out = check_output("ps -ef | grep -v grep | egrep 'python.*%s' | awk '{print $2}'" % sys.argv[0], - shell=True) + out = check_output( + "ps -ef | grep -v grep | egrep 'python.*%s' | awk '{print $2}'" % + sys.argv[0], shell=True) if out: for pid in out.split(): if int(pid) != os.getpid(): @@ -131,7 +135,8 @@ class FSMonitor(object): def set_fail(self, failed_reason): with open(constant.VM_CMD_RETURN_CODE_FILE, 'w') as f: - f.writelines([constant.VM_CMD_EXCUTE_FAILED_FLAG_CONTENT, '\n', failed_reason]) + f.writelines( + [constant.VM_CMD_EXCUTE_FAILED_FLAG_CONTENT, '\n', failed_reason]) with open(constant.VM_CMD_DONE_FLAG_FILE, 'w') as f: pass @@ -149,8 +154,10 @@ class FSMonitor(object): pid = os.fork() if pid > 0: sys.exit(0) - except OSError, e: - sys.stderr.write('fork #1 failed:%d,(%s)\n' % (e.errno, e.strerror)) + except OSError as e: + sys.stderr.write( + 'fork #1 failed:%d,(%s)\n' % + (e.errno, e.strerror)) sys.exit(1) os.setsid() os.umask(0) @@ -158,10 +165,17 @@ class FSMonitor(object): pid = os.fork() if pid > 0: sys.exit(0) - except OSError, e: - sys.stderr.write('fork #2 failed:%d,(%s)\n' % (e.errno, e.strerror)) + except OSError as e: + sys.stderr.write( + 'fork #2 failed:%d,(%s)\n' % + (e.errno, e.strerror)) sys.exit(1) - LOG.debug("pid:%d,ppid:%d,sid:%d", os.getpid(), os.getppid(), os.getsid(os.getpid())) + LOG.debug( + "pid:%d,ppid:%d,sid:%d", + os.getpid(), + os.getppid(), + os.getsid( + os.getpid())) old = open('/dev/null', 'r') os.dup2(old.fileno(), sys.stdin.fileno()) old = open('/dev/null', 'a+') @@ -192,8 +206,9 @@ class FSMonitor(object): method(*param) self.set_success() LOG.debug("cmd sucessfully done") - except Exception, e: - LOG.debug('failed to run:%s %s,reason:%s', cmd, param, str(e)) + except Exception as e: + LOG.debug( + 'failed to run:%s %s,reason:%s', cmd, param, str(e)) self.set_fail(str(e)) break else: @@ -209,7 +224,8 @@ if __name__ == '__main__': # echo "config_ip 56:6f:44:a5:3f:a2 192.168.188.200/23" > command;touch command_set # echo "config_gw 192.168.188.1" > command;touch command_set # echo set_pktloop_dpdk 56:6f:44:a5:3f:a2 56:6f:44:a5:3f:a3 > command;touch command_set - # echo recover_nic_binding 56:6f:44:a5:3f:a2 56:6f:44:a5:3f:a3 > command;touch command_set + # echo recover_nic_binding 56:6f:44:a5:3f:a2 56:6f:44:a5:3f:a3 > + # command;touch command_set import os logging.basicConfig(level=logging.DEBUG, filename=LOG_FILE, filemode='w') os.environ['PATH'] = os.environ["PATH"] + ":/usr/local/bin" |