Commit 14d8092d authored by Lucas Carvalho's avatar Lucas Carvalho

Call the method get_sha256sum_from_networkcached into download_network_cached....

Call the method get_sha256sum_from_networkcached into download_network_cached. If the sha256sum does not exists on networkcached server it should return False.
Signed-off-by: default avatarLucas Carvalho <lucas@nexedi.com>
parent 42a4f020
......@@ -105,12 +105,13 @@ def get_sha256sum_from_networkcached(network_cache, url, logger):
result = urllib.urlopen(network_cached_url)
if int(result.code) == 200:
return json.loads(result.read().strip()).get('sha256sum', None)
logger.info('The url is not cached yet: %s' % url)
except IOError, e:
logger.info('An error occurred to get sha256sum from networkcached:' \
' %s' % str(e))
def download_network_cached(network_cache, path, logger):
def download_network_cached(network_cache, path, url, logger):
"""Download from a network cache provider
If something fail (providor be offline, or hash_string fail), we ignore
......@@ -122,19 +123,21 @@ def download_network_cached(network_cache, path, logger):
# Not able to use network cache
return False
sha256sum = get_sha256sum_from_networkcached(network_cache,
url,
self.logger)
sha256sum = get_sha256sum_from_networkcached(network_cache, url, logger)
if sha256sum is None:
return False
url = os.path.join(network_cache, sha256sum)
logger.info('Downloading from network cache %s' % url)
network_cached_url = os.path.join(network_cache, sha256sum)
logger.info('Downloading from network cache %s' % network_cached_url)
try:
path, headers = urllib.urlretrieve(url, path)
path, headers = urllib.urlretrieve(network_cached_url, path)
if not check_sha256sum(path, sha256sum):
logger.info('MD5/SHA256 checksum mismatch downloading %r' % url)
logger.info('MD5/SHA256 checksum mismatch downloading %r' % \
network_cached_url)
return False
except IOError, e:
logger.info('Fail to download from network cache %s' % url)
logger.info('Fail to download from network cache %s' % \
network_cached_url)
return False
return True
......@@ -190,12 +193,7 @@ def fetch_from_network_cache(network_cache, location, tmp, logger=None):
filename = _get_filename_from_url(location)
path = os.path.join(tmp, filename)
sha256sum = get_sha256sum_from_networkcached(network_cache,
location, logger)
if sha256sum is None:
return None
is_downloaded = download_network_cached(network_cache, path, sha256sum, logger)
is_downloaded = download_network_cached(network_cache, path, location, logger)
if is_downloaded:
return path
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment