On Wed, Mar 14, 2012 at 1:33 PM, Qingtang Zhou <[email protected]> wrote:
> * On 2012-03-14 12:05:47 +0800, [email protected]
> ([email protected]) wrote:
>> From: Lei Yang <[email protected]>
>>
>> Before dhclient, we need to check if it has been running,and then kill it
>> Signed-off-by: Lei Yang <[email protected]>
>> ---
>> 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?
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.
>
Good, I have noticed this before, I will change it, thanks
Lei
> 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
>> [email protected]
>> http://test.kernel.org/cgi-bin/mailman/listinfo/autotest
_______________________________________________
Autotest mailing list
[email protected]
http://test.kernel.org/cgi-bin/mailman/listinfo/autotest