Hi~
The point is here:
commands API and utils.run both worked well. But sometimes, we give some 
invalid options
on purpose of testing incorrect situations. In these cases, utils.run will 
throw an exception
which we don't expect.

Of course we can catch the exception and see what to do with the exit status, 
but what is the
difference with commands API? I think commands API is more simple.

On the other hand, we can set ignore_status to True, like the following:
      cmd = "virsh version  %s" % option
      cmd_result = utils.run(cmd, ignore_status=True)
      return cmd_result.exit_status
And there is still no difference with commands API.

So what do you think?

于 2012-2-15 20:53, Chris Evich 写道:
> On 02/14/2012 11:42 PM, guyanhua wrote:
>>
>>>> +def run_virsh_version(test, params, env):
>>>> + """
>>>> + Test command: virsh version.
>>>> + """
>>>> +
>>>> + def virsh_version(option):
>>>> + command = "virsh version %s" % option
>>>> + status, output = commands.getstatusoutput(command)
>>>> + logging.info("Output: %s", output)
>>>> + logging.info("Status: %d", status)
>>>> + return status
>>>
>>> ^ Rather than the commands API, I'd like to see here a call to
>>> utils.run, since it already is supposed to throw an exception if the
>>> command returns exit code != 0, so that you don't have to explicitly
>>> check for status and throw TestFail exceptions.
>>>
>>       Hi, I have read the utils.run function and have some problems about 
>> this.
>>       This patch's aim is to test whether the "virsh version"command can be
>>       used effectively. When we test using a wrong option , it will cause an
>>       exception but it is right ,we should not throw the exception and  stop
>>       the process. So we return status to judge. if exit code != 0, it is 
>> ringt,
>>       otherwise it is wrong.
>>
>
> I think both can be correct (using utils.run() and checking exit code in
> test).  Maybe check the exit code (CmdResult class defined in
> client/base_utils.py) w/in an except clause, re-raising the exception*
> when it makes sense?
>
> *note: We need to support python 2.4 still, so you can't re-raise with
> just 'raise' like in 2.5 :(
>

_______________________________________________
Autotest mailing list
[email protected]
http://test.kernel.org/cgi-bin/mailman/listinfo/autotest

Reply via email to