stage creates cache fetcher with cache object (so it can be mocked for tests)

This commit is contained in:
Peter Scheibel 2016-03-24 19:28:21 -07:00
parent fe71ba992d
commit 142d1f5cbc
5 changed files with 31 additions and 12 deletions

View File

@ -392,12 +392,3 @@ def remove_linked_tree(path):
os.unlink(path)
else:
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)

View File

@ -49,8 +49,8 @@
cache_path = join_path(var_path, "cache")
# TODO: i get a complaint if i dont qualify this, fix that
import llnl.util.filesystem
cache = llnl.util.filesystem.FsCache(cache_path)
import spack.fetch_strategy
cache = fetch_strategy.FsCache(cache_path)
prefix = spack_root
opt_path = join_path(prefix, "opt")

View File

@ -31,6 +31,7 @@
import spack
import spack.test
from spack.fetch_strategy import FetchError
description ="Run unit tests"
@ -54,6 +55,19 @@ class MockCache(object):
def store(self, copyCmd, relativeDst):
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):
if args.list:

View File

@ -689,6 +689,20 @@ def for_package_version(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):
def __init__(self, msg, long_msg=None):
super(FetchError, self).__init__(msg, long_msg)

View File

@ -273,7 +273,6 @@ def fetch(self, mirror_only=False):
# the root, so we add a '/' if it is not present.
mirror_roots = [root if root.endswith('/') else root + '/'
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]
# 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
for url in urls:
fetchers.insert(0, fs.URLFetchStrategy(url, digest))
fetchers.insert(0, spack.cache.fetcher(self.mirror_path, digest))
for fetcher in fetchers:
try: