On 06/10/2010 04:01 PM, Cao, Chen wrote:
> On Thu, Jun 10, 2010 at 12:02:18PM +0300, Michael Goldish wrote:
>> On 06/10/2010 08:10 AM, Chen Cao wrote:
>>>     (match, s) = session.read_up_to_prompt()
>>>     if not match:
>>>         raise error.TestError("Could not get guest time")
>>>     s = re.findall(time_filter_re, s)[0]
>>>
>>> Sometimes "match" is not None, but does not contain time string with
>>> illegal format.
>>> So we need to check the return value of re.findall before get the value
>>> by subindexing.
>>>
>>> And add debug info when error encountered.
>>>
>>> Signed-off-by: Chen Cao <[email protected]>
>>> ---
>>>  client/tests/kvm/kvm_test_utils.py |   10 ++++++++--
>>>  1 files changed, 8 insertions(+), 2 deletions(-)
>>>
>>> diff --git a/client/tests/kvm/kvm_test_utils.py 
>>> b/client/tests/kvm/kvm_test_utils.py
>>> index 24e2bf5..c0627b3 100644
>>> --- a/client/tests/kvm/kvm_test_utils.py
>>> +++ b/client/tests/kvm/kvm_test_utils.py
>>> @@ -201,9 +201,15 @@ def get_time(session, time_command, time_filter_re, 
>>> time_format):
>>>      host_time = time.time()
>>>      session.sendline(time_command)
>>>      (match, s) = session.read_up_to_prompt()
>>> -    if not match:
>>> +    if not match or s is None:
>>
>> I don't know if it's possible for s to be None.  s is supposed to be a
>> string (possibly an empty one).  Did you encounter a case where s is None?
>>
> 
> I'm not sure if s could be None, either.
> I just dont like to assume that surprises won't happen, after
> suffering lots of traps in our daily testing work. :-)
> 
> anyway i think the check won't hurt, do you?

It won't hurt, but if it's completely unnecessary it's better left out.

>>>          raise error.TestError("Could not get guest time")
>>> -    s = re.findall(time_filter_re, s)[0]
>>> +
>>> +    try:
>>> +        s = re.findall(time_filter_re, s)[0]
>>> +    except IndexError:
>>> +        logging.debug("The time string from guest is:\n%s" % s)
>>> +        raise error.TestError("The time string from guest is unexpected.")
>>> +
>>
>> This part looks good.
>>
>>
>> When you encountered this problem, was it due to an incorrect format
>> specified in the config file, or did the guest do something crazy, like
>> return an empty string or an unrelated string?  I'm asking because this
>> might indicate a kvm-autotest bug.  Maybe your guest replied to a
>> previous command whose output was not properly read.
>>
> 
> I met this problem only once, and as we did not print any debug info,
> i dont know what has happened. however, sometimes
> get_command_status_output() returns unrecoganized chars, like,
> /usr/bin/qemu-kvm -name 'vm1' -monitor tcp:0:5202,s<usr/bin/qemu-kvm -name 
> 'vm1' -monitor tcp:0:5202,se                         
> rver,nowait 
> 

OK, I think it's useful to catch that exception.
_______________________________________________
Autotest mailing list
[email protected]
http://test.kernel.org/cgi-bin/mailman/listinfo/autotest

Reply via email to