tree: validate resolved remote:// sections (#4569)

* tree: validate resolved remote:// sections

* dvc: use checksum_jobs instead of hash_jobs

This is a regression introduced during one of the refactorings.
This commit is contained in:
Ruslan Kuprieiev
2020-09-14 12:15:38 +03:00
committed by GitHub
parent 61be19b9b5
commit 8c19492ba6
5 changed files with 47 additions and 6 deletions
+6 -1
View File
@@ -63,7 +63,12 @@ class Cache:
if local:
settings = {"name": local}
else:
settings = {**config, "url": config["dir"]}
from ..config import LOCAL_COMMON
settings = {"url": config["dir"]}
for opt in LOCAL_COMMON.keys():
if opt in config:
settings[str(opt)] = config.get(opt)
tree = get_cloud_tree(repo, **settings)
self.local = LocalCache(tree)
+6
View File
@@ -78,5 +78,11 @@ def _resolve_remote_refs(repo, remote_conf):
def get_cloud_tree(repo, **kwargs):
from dvc.config import SCHEMA, ConfigError, Invalid
remote_conf = _get_conf(repo, **kwargs)
try:
remote_conf = SCHEMA["remote"][str](remote_conf)
except Invalid as exc:
raise ConfigError(str(exc)) from None
return _get_tree(remote_conf)(repo, remote_conf)
+2 -2
View File
@@ -75,8 +75,8 @@ class BaseTree:
@cached_property
def hash_jobs(self):
return (
self.config.get("hash_jobs")
or (self.repo and self.repo.config["core"].get("hash_jobs"))
self.config.get("checksum_jobs")
or (self.repo and self.repo.config["core"].get("checksum_jobs"))
or self.HASH_JOBS
)
+3 -3
View File
@@ -8,9 +8,9 @@ from dvc.tree.s3 import S3Tree
def test_remote_with_hash_jobs(dvc):
dvc.config["remote"]["with_hash_jobs"] = {
"url": "s3://bucket/name",
"hash_jobs": 100,
"checksum_jobs": 100,
}
dvc.config["core"]["hash_jobs"] = 200
dvc.config["core"]["checksum_jobs"] = 200
tree = get_cloud_tree(dvc, name="with_hash_jobs")
assert tree.hash_jobs == 100
@@ -18,7 +18,7 @@ def test_remote_with_hash_jobs(dvc):
def test_remote_without_hash_jobs(dvc):
dvc.config["remote"]["without_hash_jobs"] = {"url": "s3://bucket/name"}
dvc.config["core"]["hash_jobs"] = 200
dvc.config["core"]["checksum_jobs"] = 200
tree = get_cloud_tree(dvc, name="without_hash_jobs")
assert tree.hash_jobs == 200
+30
View File
@@ -1,3 +1,6 @@
import pytest
from dvc.config import ConfigError
from dvc.path_info import CloudURLInfo
from dvc.tree import get_cloud_tree
@@ -16,3 +19,30 @@ def test_get_cloud_tree(tmp_dir, dvc):
assert get_cloud_tree(dvc, name="base").path_info == base
assert get_cloud_tree(dvc, name="first").path_info == first
assert get_cloud_tree(dvc, name="second").path_info == second
def test_get_cloud_tree_validate(tmp_dir, dvc):
tmp_dir.add_remote(
name="base", url="ssh://example.com/path", default=False
)
tmp_dir.add_remote(
name="first",
config={"url": "remote://base/first", "type": "symlink"},
default=False,
)
tmp_dir.add_remote(
name="second",
config={"url": "remote://first/second", "oss_key_id": "mykey"},
default=False,
)
assert get_cloud_tree(dvc, name="base").config == {
"url": "ssh://example.com/path"
}
assert get_cloud_tree(dvc, name="first").config == {
"url": "ssh://example.com/path/first",
"type": ["symlink"],
}
with pytest.raises(ConfigError):
get_cloud_tree(dvc, name="second")