summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Maw <richard.maw@codethink.co.uk>2014-08-19 10:40:53 +0000
committerRichard Maw <richard.maw@codethink.co.uk>2014-08-19 10:40:53 +0000
commite86a598553e96dab2dc4111aedefcb6b0a60c50d (patch)
tree04e193878bbd4bcfb0992a4aeb488715e50cbe36
parent7aec8c2eb0f8ce0dae70559d11db8e84115f8ba6 (diff)
downloadmorph-e86a598553e96dab2dc4111aedefcb6b0a60c50d.tar.gz
Only autodetect morphology when result is 404baserock/richardmaw/bugfix/http-fail
The MorphologyFactory class will use a RemoteRepoCache to see if a morphology file exists, and if it doesn't, uses a file listing to see if it can detect what build-system is uses, hence what the default morphology should be. However, it was overly generic in what error cases it would accept as the morphology not being found, so if the RemoteRepoCache was suddenly un-resolvable for a brief period, then it would assume the morphology didn't exist, and use the default one. This happened to a user, and the result was a full rebuild. So we now fix this by only raising the exception that means the file didn't exist, if we got a HTTP 404.
-rw-r--r--morphlib/remoterepocache.py8
-rw-r--r--morphlib/remoterepocache_tests.py9
2 files changed, 12 insertions, 5 deletions
diff --git a/morphlib/remoterepocache.py b/morphlib/remoterepocache.py
index b1544b03..004ba86e 100644
--- a/morphlib/remoterepocache.py
+++ b/morphlib/remoterepocache.py
@@ -1,4 +1,4 @@
-# Copyright (C) 2012-2013 Codethink Limited
+# Copyright (C) 2012-2014 Codethink Limited
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -63,9 +63,11 @@ class RemoteRepoCache(object):
repo_url = self._resolver.pull_url(repo_name)
try:
return self._cat_file_for_repo_url(repo_url, ref, filename)
- except BaseException, e:
+ except urllib2.HTTPError as e:
logging.error('Caught exception: %s' % str(e))
- raise CatFileError(repo_name, ref, filename)
+ if e.code == 404:
+ raise CatFileError(repo_name, ref, filename)
+ raise # pragma: no cover
def ls_tree(self, repo_name, ref):
repo_url = self._resolver.pull_url(repo_name)
diff --git a/morphlib/remoterepocache_tests.py b/morphlib/remoterepocache_tests.py
index 0b1a183b..ef81506f 100644
--- a/morphlib/remoterepocache_tests.py
+++ b/morphlib/remoterepocache_tests.py
@@ -1,4 +1,4 @@
-# Copyright (C) 2012-2013 Codethink Limited
+# Copyright (C) 2012-2014 Codethink Limited
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -16,6 +16,7 @@
import json
import unittest
+import urllib2
import morphlib
@@ -26,7 +27,11 @@ class RemoteRepoCacheTests(unittest.TestCase):
return self.sha1s[repo_url][ref]
def _cat_file_for_repo_url(self, repo_url, sha1, filename):
- return self.files[repo_url][sha1][filename]
+ try:
+ return self.files[repo_url][sha1][filename]
+ except KeyError:
+ raise urllib2.HTTPError(url='', code=404, msg='Not found',
+ hdrs={}, fp=None)
def _ls_tree_for_repo_url(self, repo_url, sha1):
return json.dumps({