* On 2012-03-14 12:05:47 +0800, yanglei.f...@gmail.com (yanglei.f...@gmail.com) wrote: > From: Lei Yang <yanglei.f...@gmail.com> > > Before dhclient, we need to check if it has been running,and then kill it > Signed-off-by: Lei Yang <yanglei.f...@gmail.com> > --- > client/tests/kvm/tests/nic_bonding.py | 8 ++++++++ > 1 files changed, 8 insertions(+), 0 deletions(-) > > diff --git a/client/tests/kvm/tests/nic_bonding.py > b/client/tests/kvm/tests/nic_bonding.py > index 6266058..c976466 100644 > --- a/client/tests/kvm/tests/nic_bonding.py > +++ b/client/tests/kvm/tests/nic_bonding.py > @@ -36,6 +36,14 @@ def run_nic_bonding(test, params, env): > for vlan, nic in enumerate(params.get("nics").split())] > setup_cmd = "ifenslave bond0 " + " ".join(ifnames) > session_serial.cmd(setup_cmd) > + #do a pgrep to check if dhclient has already been running > + pgrep_cmd = "pgrep dhclient" > + cmd_output = session_serial.cmd(pgrep_cmd) Hi, Lei, I think your idea is checking existing dhclient process before run 'dhclient' cmd, right? But this 'session_serial.cmd' will raise an exception called 'ShellCmdError' if no dhclient process existed (pgrep returns 1 when no matched process is found), this exception would interrupt your test process.
There are 2 way to avoid this problem, 1) Change session_serial.cmd to session_serial.cmd_status which doesn't care about the return value of a command. (please refer to virt/aexpect.py file) 2) Add a try...except... block here, a example: try: cmd_output = session_serial.cmd(pgrep_cmd) except aexpect.ShellCmdError: pass else: #if dhclient is there, killl it logging.info("dhclient already is running,kill it") session_serial.cmd("killall -9 dhclient") time.sleep(1) > + #if dhclient is there, killl it > + if cmd_output != '': > + logging.info("dhclient already is running,kill it") > + session_serial.cmd("killall -9 dhclient") > + time.sleep(1) Oh, BTW, autotest's recommended indentation is 4 space, same as python standard. (See CODING_STYLE file in the top directory of autotest) > session_serial.cmd("dhclient bond0") > > try: > -- > 1.7.5.4 > > _______________________________________________ > Autotest mailing list > Autotest@test.kernel.org > http://test.kernel.org/cgi-bin/mailman/listinfo/autotest _______________________________________________ Autotest mailing list Autotest@test.kernel.org http://test.kernel.org/cgi-bin/mailman/listinfo/autotest