summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorPeter Scheibel <scheibel1@llnl.gov>2016-03-24 19:28:21 -0700
committerPeter Scheibel <scheibel1@llnl.gov>2016-03-24 19:28:21 -0700
commit142d1f5cbc098a4e8a0046148400bb2f40e839bc (patch)
tree20ceb15ba5a3ad2defb73f0fbf67cdc91c83d117 /lib
parentfe71ba992d26b66a4a9492d9b0fbf17b1410b1e1 (diff)
downloadspack-142d1f5cbc098a4e8a0046148400bb2f40e839bc.tar.gz
spack-142d1f5cbc098a4e8a0046148400bb2f40e839bc.tar.bz2
spack-142d1f5cbc098a4e8a0046148400bb2f40e839bc.tar.xz
spack-142d1f5cbc098a4e8a0046148400bb2f40e839bc.zip
stage creates cache fetcher with cache object (so it can be mocked for tests)
Diffstat (limited to 'lib')
-rw-r--r--lib/spack/llnl/util/filesystem.py9
-rw-r--r--lib/spack/spack/__init__.py4
-rw-r--r--lib/spack/spack/cmd/test.py14
-rw-r--r--lib/spack/spack/fetch_strategy.py14
-rw-r--r--lib/spack/spack/stage.py2
5 files changed, 31 insertions, 12 deletions
diff --git a/lib/spack/llnl/util/filesystem.py b/lib/spack/llnl/util/filesystem.py
index 7586d514d1..c4665c284c 100644
--- a/lib/spack/llnl/util/filesystem.py
+++ b/lib/spack/llnl/util/filesystem.py
@@ -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)
diff --git a/lib/spack/spack/__init__.py b/lib/spack/spack/__init__.py
index 0041d50624..6e7cb217c8 100644
--- a/lib/spack/spack/__init__.py
+++ b/lib/spack/spack/__init__.py
@@ -49,8 +49,8 @@ share_path = join_path(spack_root, "share", "spack")
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")
diff --git a/lib/spack/spack/cmd/test.py b/lib/spack/spack/cmd/test.py
index 82bf3928c3..8c9dea3c66 100644
--- a/lib/spack/spack/cmd/test.py
+++ b/lib/spack/spack/cmd/test.py
@@ -31,6 +31,7 @@ from llnl.util.lang import list_modules
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:
diff --git a/lib/spack/spack/fetch_strategy.py b/lib/spack/spack/fetch_strategy.py
index fc5d7e231c..b696a12e7a 100644
--- a/lib/spack/spack/fetch_strategy.py
+++ b/lib/spack/spack/fetch_strategy.py
@@ -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)
diff --git a/lib/spack/spack/stage.py b/lib/spack/spack/stage.py
index 780f391603..9f2619f43e 100644
--- a/lib/spack/spack/stage.py
+++ b/lib/spack/spack/stage.py
@@ -273,7 +273,6 @@ class Stage(object):
# 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 @@ class Stage(object):
# 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: