[autotest] Move signal.alarm call inside try clause.

It is possible that alarm is triggered right after signal.alarm call
is made. If it's not in the try clause, the TimeoutException can be
bubbled up to the caller and take down the whole process.

BUG=chromium-os:34424
TEST=run unit test retry_unittest.py, run_suite for smoke tests on lumpy.

Change-Id: I42151326f55137271b2d2ce07d601d009c32f0f5
Reviewed-on: https://gerrit.chromium.org/gerrit/41457
Tested-by: Dan Shi <dshi@chromium.org>
Commit-Queue: Dan Shi <dshi@chromium.org>
Reviewed-by: Dan Shi <dshi@chromium.org>
diff --git a/client/common_lib/cros/retry.py b/client/common_lib/cros/retry.py
index b71c993..5aa1f81 100644
--- a/client/common_lib/cros/retry.py
+++ b/client/common_lib/cros/retry.py
@@ -43,10 +43,10 @@
     # In case the timeout is rounded to 0, force to set it to default value.
     if timeout_sec_n == 0:
         timeout_sec_n = 60
-    old_alarm_sec = signal.alarm(timeout_sec_n)
-    if old_alarm_sec > 0:
-        old_timeout_time = time.time() + old_alarm_sec
     try:
+        old_alarm_sec = signal.alarm(timeout_sec_n)
+        if old_alarm_sec > 0:
+            old_timeout_time = time.time() + old_alarm_sec
         default_result = func(*args, **kwargs)
         return False, default_result
     except TimeoutException: