cheets_GTS: Remove the temporary directory for authkey.

BUG=b:112515274
TEST=cheets_GTS.6.0_r1.GtsPlacementTestCases

Change-Id: I5a75f09a35c57fff5c3f2f14d7d037720eb75013
Reviewed-on: https://chromium-review.googlesource.com/1179438
Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com>
Tested-by: Kazuhiro Inaba <kinaba@chromium.org>
Reviewed-by: Rohit Makasana <rohitbm@chromium.org>
(cherry picked from commit 6f60e3a625c0bd665aec56600eeae80e91f1cfe9)
Reviewed-on: https://chromium-review.googlesource.com/1182382
Reviewed-by: Kazuhiro Inaba <kinaba@chromium.org>
diff --git a/server/site_tests/cheets_GTS/cheets_GTS.py b/server/site_tests/cheets_GTS/cheets_GTS.py
index bbdc65c..14c6ef9 100644
--- a/server/site_tests/cheets_GTS/cheets_GTS.py
+++ b/server/site_tests/cheets_GTS/cheets_GTS.py
@@ -14,6 +14,7 @@
 
 import logging
 import os
+import shutil
 import tempfile
 
 from autotest_lib.server import utils
@@ -141,13 +142,6 @@
         dut before the log-in for the test is performed.
         """
 
-        # Download the GTS auth key to the local temp directory.
-        self._authkey = None
-        if not authkey:
-            authkey = self._get_default_authkey()
-        tmpdir = tempfile.mkdtemp()
-        self._authkey = self._download_to_dir(authkey, tmpdir)
-
         # On dev and beta channels timeouts are sharp, lenient on stable.
         self._timeout = timeout
         if self._get_release_channel() == 'stable':
@@ -155,12 +149,20 @@
         # Retries depend on channel.
         self._timeoutfactor = None
 
-        self._run_tradefed_with_retries(
-            test_name=test_name,
-            run_template=run_template,
-            retry_template=retry_template,
-            target_module=target_module,
-            target_plan=target_plan,
-            needs_push_media=needs_push_media,
-            login_precondition_commands=login_precondition_commands,
-            precondition_commands=precondition_commands)
+        # Download the GTS auth key to the local temp directory.
+        tmpdir = tempfile.mkdtemp()
+        try:
+            self._authkey = self._download_to_dir(
+                authkey or self._get_default_authkey(), tmpdir)
+
+            self._run_tradefed_with_retries(
+                test_name=test_name,
+                run_template=run_template,
+                retry_template=retry_template,
+                target_module=target_module,
+                target_plan=target_plan,
+                needs_push_media=needs_push_media,
+                login_precondition_commands=login_precondition_commands,
+                precondition_commands=precondition_commands)
+        finally:
+            shutil.rmtree(tmpdir)