Michael and guys,
what do you think about this one?
--
cc
On Fri, Jun 11, 2010 at 09:46:56AM +0800, 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 | 12 +++++++++++-
> 1 files changed, 11 insertions(+), 1 deletions(-)
>
> diff --git a/client/tests/kvm/kvm_test_utils.py
> b/client/tests/kvm/kvm_test_utils.py
> index 24e2bf5..6f9fdec 100644
> --- a/client/tests/kvm/kvm_test_utils.py
> +++ b/client/tests/kvm/kvm_test_utils.py
> @@ -203,7 +203,17 @@ def get_time(session, time_command, time_filter_re,
> time_format):
> (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]
> +
> + 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.")
> + except Exception as e:
> + logging.debug("(time_filter_re, time_string): (%s, %s)" % \
> + (time_filter_re, s))
> + raise e
> +
> guest_time = time.mktime(time.strptime(s, time_format))
> return (host_time, guest_time)
>
>
> _______________________________________________
> 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