mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-04 07:18:27 +01:00
test: simplify google creds handling
This commit is contained in:
@@ -23,9 +23,6 @@ logger = logging.getLogger("dvc")
|
||||
|
||||
|
||||
class TestDirFixture(object):
|
||||
GCP_CREDS_FILE = os.path.abspath(
|
||||
os.path.join("scripts", "ci", "gcp-creds.json")
|
||||
)
|
||||
DATA_DIR = "data_dir"
|
||||
DATA_SUB_DIR = os.path.join(DATA_DIR, "data_sub_dir")
|
||||
DATA = os.path.join(DATA_DIR, "data")
|
||||
|
||||
@@ -47,6 +47,15 @@ TEST_AWS_REPO_BUCKET = os.environ.get("DVC_TEST_AWS_REPO_BUCKET", "dvc-test")
|
||||
TEST_GCP_REPO_BUCKET = os.environ.get("DVC_TEST_GCP_REPO_BUCKET", "dvc-test")
|
||||
TEST_OSS_REPO_BUCKET = "dvc-test"
|
||||
|
||||
TEST_GCP_CREDS_FILE = os.path.abspath(
|
||||
os.environ.get(
|
||||
"GOOGLE_APPLICATION_CREDENTIALS",
|
||||
os.path.join("scripts", "ci", "gcp-creds.json"),
|
||||
)
|
||||
)
|
||||
# Ensure that absolute path is used
|
||||
os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = TEST_GCP_CREDS_FILE
|
||||
|
||||
|
||||
def _should_test_aws():
|
||||
dvc_test_aws = os.getenv("DVC_TEST_AWS")
|
||||
@@ -65,31 +74,22 @@ def _should_test_gcp():
|
||||
if os.getenv("DVC_TEST_GCP") == "true":
|
||||
return True
|
||||
|
||||
if not os.path.exists(TestDvc.GCP_CREDS_FILE):
|
||||
if not os.path.exists(TEST_GCP_CREDS_FILE):
|
||||
return False
|
||||
|
||||
# NOTE: we copy because GOOGLE_APPLICATION_CREDENTIALS uses rel path.
|
||||
# This is only my guess and I don't know why won't we use absolute.
|
||||
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
|
||||
try:
|
||||
check_output(
|
||||
[
|
||||
"gcloud",
|
||||
"auth",
|
||||
"activate-service-account",
|
||||
"--key-file",
|
||||
TEST_GCP_CREDS_FILE,
|
||||
]
|
||||
)
|
||||
except (CalledProcessError, OSError):
|
||||
return False
|
||||
return True
|
||||
|
||||
|
||||
def _should_test_azure():
|
||||
@@ -393,7 +393,7 @@ class TestRemoteGS(TestDataCloudBase):
|
||||
config[TEST_SECTION][Config.SECTION_REMOTE_URL] = repo
|
||||
config[TEST_SECTION][
|
||||
Config.SECTION_GCP_CREDENTIALPATH
|
||||
] = TestDvc.GCP_CREDS_FILE
|
||||
] = TEST_GCP_CREDS_FILE
|
||||
self.cloud = DataCloud(self.dvc, config)
|
||||
|
||||
self.assertIsInstance(self.cloud._cloud, self._get_cloud_class())
|
||||
@@ -668,7 +668,7 @@ class TestRemoteGSCLI(TestDataCloudCLIBase):
|
||||
"modify",
|
||||
TEST_REMOTE,
|
||||
"credentialpath",
|
||||
TestDvc.GCP_CREDS_FILE,
|
||||
TEST_GCP_CREDS_FILE,
|
||||
]
|
||||
)
|
||||
|
||||
|
||||
@@ -4,9 +4,7 @@
|
||||
# export DVC_TEST_AWS_REPO_BUCKET="...SET-ME..."
|
||||
|
||||
# Uncomment and set a bucket name to test against Google Storage
|
||||
# export GOOGLE_APPLICATION_CREDENTIALS=".gcp-creds.json"
|
||||
# export GCP_CREDS="yes"
|
||||
# export DVC_TEST_GCP_REPO_BUCKET="...SET-ME..."
|
||||
# export GOOGLE_APPLICATION_CREDENTIALS="scripts/ci/gcp-creds.json"
|
||||
|
||||
# Uncomment to test against Microsoft Azure via Azurite
|
||||
# export AZURE_STORAGE_CONTAINER_NAME="dvc-test"
|
||||
|
||||
Reference in New Issue
Block a user