stage creates cache fetcher with cache object (so it can be mocked for tests)
This commit is contained in:
parent
fe71ba992d
commit
142d1f5cbc
@ -392,12 +392,3 @@ def remove_linked_tree(path):
|
|||||||
os.unlink(path)
|
os.unlink(path)
|
||||||
else:
|
else:
|
||||||
shutil.rmtree(path, True)
|
shutil.rmtree(path, True)
|
||||||
|
|
||||||
class FsCache(object):
|
|
||||||
def __init__(self, root):
|
|
||||||
self.root = os.path.abspath(root)
|
|
||||||
|
|
||||||
def store(self, copyCmd, relativeDst):
|
|
||||||
dst = join_path(self.root, relativeDst)
|
|
||||||
mkdirp(os.path.dirname(dst))
|
|
||||||
copyCmd(dst)
|
|
||||||
|
@ -49,8 +49,8 @@
|
|||||||
cache_path = join_path(var_path, "cache")
|
cache_path = join_path(var_path, "cache")
|
||||||
|
|
||||||
# TODO: i get a complaint if i dont qualify this, fix that
|
# TODO: i get a complaint if i dont qualify this, fix that
|
||||||
import llnl.util.filesystem
|
import spack.fetch_strategy
|
||||||
cache = llnl.util.filesystem.FsCache(cache_path)
|
cache = fetch_strategy.FsCache(cache_path)
|
||||||
|
|
||||||
prefix = spack_root
|
prefix = spack_root
|
||||||
opt_path = join_path(prefix, "opt")
|
opt_path = join_path(prefix, "opt")
|
||||||
|
@ -31,6 +31,7 @@
|
|||||||
|
|
||||||
import spack
|
import spack
|
||||||
import spack.test
|
import spack.test
|
||||||
|
from spack.fetch_strategy import FetchError
|
||||||
|
|
||||||
description ="Run unit tests"
|
description ="Run unit tests"
|
||||||
|
|
||||||
@ -54,6 +55,19 @@ class MockCache(object):
|
|||||||
def store(self, copyCmd, relativeDst):
|
def store(self, copyCmd, relativeDst):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
def fetcher(self, targetPath, digest):
|
||||||
|
return MockCacheFetcher()
|
||||||
|
|
||||||
|
|
||||||
|
class MockCacheFetcher(object):
|
||||||
|
def set_stage(self, stage):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def fetch(self):
|
||||||
|
raise FetchError("Mock cache always fails for tests")
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return "[mock fetcher]"
|
||||||
|
|
||||||
def test(parser, args):
|
def test(parser, args):
|
||||||
if args.list:
|
if args.list:
|
||||||
|
@ -689,6 +689,20 @@ def for_package_version(pkg, version):
|
|||||||
raise InvalidArgsError(pkg, version)
|
raise InvalidArgsError(pkg, version)
|
||||||
|
|
||||||
|
|
||||||
|
class FsCache(object):
|
||||||
|
def __init__(self, root):
|
||||||
|
self.root = os.path.abspath(root)
|
||||||
|
|
||||||
|
def store(self, copyCmd, relativeDst):
|
||||||
|
dst = join_path(self.root, relativeDst)
|
||||||
|
mkdirp(os.path.dirname(dst))
|
||||||
|
copyCmd(dst)
|
||||||
|
|
||||||
|
def fetcher(self, targetPath, digest):
|
||||||
|
url = "file://" + join_path(self.root, targetPath)
|
||||||
|
return URLFetchStrategy(url, digest)
|
||||||
|
|
||||||
|
|
||||||
class FetchError(spack.error.SpackError):
|
class FetchError(spack.error.SpackError):
|
||||||
def __init__(self, msg, long_msg=None):
|
def __init__(self, msg, long_msg=None):
|
||||||
super(FetchError, self).__init__(msg, long_msg)
|
super(FetchError, self).__init__(msg, long_msg)
|
||||||
|
@ -273,7 +273,6 @@ def fetch(self, mirror_only=False):
|
|||||||
# the root, so we add a '/' if it is not present.
|
# the root, so we add a '/' if it is not present.
|
||||||
mirror_roots = [root if root.endswith('/') else root + '/'
|
mirror_roots = [root if root.endswith('/') else root + '/'
|
||||||
for root in mirrors.values()]
|
for root in mirrors.values()]
|
||||||
mirror_roots.append("file://" + os.path.abspath(spack.cache_path) + os.sep)
|
|
||||||
urls = [urljoin(root, self.mirror_path) for root in mirror_roots]
|
urls = [urljoin(root, self.mirror_path) for root in mirror_roots]
|
||||||
|
|
||||||
# If this archive is normally fetched from a tarball URL,
|
# If this archive is normally fetched from a tarball URL,
|
||||||
@ -290,6 +289,7 @@ def fetch(self, mirror_only=False):
|
|||||||
# Add URL strategies for all the mirrors with the digest
|
# Add URL strategies for all the mirrors with the digest
|
||||||
for url in urls:
|
for url in urls:
|
||||||
fetchers.insert(0, fs.URLFetchStrategy(url, digest))
|
fetchers.insert(0, fs.URLFetchStrategy(url, digest))
|
||||||
|
fetchers.insert(0, spack.cache.fetcher(self.mirror_path, digest))
|
||||||
|
|
||||||
for fetcher in fetchers:
|
for fetcher in fetchers:
|
||||||
try:
|
try:
|
||||||
|
Loading…
Reference in New Issue
Block a user