From 94a8054d293c932b8b935418456f8339dbd09db9 Mon Sep 17 00:00:00 2001 From: Ruslan Kuprieiev Date: Wed, 6 Feb 2019 01:46:23 +0200 Subject: [PATCH] test: gs: refresh credentials Signed-off-by: Ruslan Kuprieiev --- tests/test_data_cloud.py | 18 +++++++++++++++++- tests/test_repro.py | 2 +- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/tests/test_data_cloud.py b/tests/test_data_cloud.py index ae7e33dcd..5bd914b5a 100644 --- a/tests/test_data_cloud.py +++ b/tests/test_data_cloud.py @@ -65,7 +65,23 @@ def _should_test_gcp(): if not os.path.exists(TestDvc.GCP_CREDS_FILE): return False - if os.getenv("GCP_CREDS"): + creds = os.getenv("GOOGLE_APPLICATION_CREDENTIALS") + if creds and os.getenv("GCP_CREDS"): + if os.path.exists(creds): + os.unlink(creds) + shutil.copyfile(TestDvc.GCP_CREDS_FILE, creds) + try: + check_output( + [ + "gcloud", + "auth", + "activate-service-account", + "--key-file", + creds, + ] + ) + except (CalledProcessError, OSError): + return False return True return False diff --git a/tests/test_repro.py b/tests/test_repro.py index d70a0a3bf..9eee2f4b0 100644 --- a/tests/test_repro.py +++ b/tests/test_repro.py @@ -957,7 +957,7 @@ class TestReproExternalGS(TestReproExternalBase): return "gsutil cp {} {}".format(i, o) def write(self, bucket, key, body): - client = gc.Client.from_service_account_json(self.GCP_CREDS_FILE) + client = gc.Client() bucket = client.bucket(bucket) bucket.blob(key).upload_from_string(body)