Commit b9795d85 authored by Łukasz Nowak's avatar Łukasz Nowak

Immune buildout on any networkcache issues.

As fallback shall be always possible make binding really immune to any problems
in networkcache including name errors, api changes, syntax errors, etc.
parent ff3a32b9
...@@ -51,11 +51,18 @@ import zc.buildout.easy_install ...@@ -51,11 +51,18 @@ import zc.buildout.easy_install
try: try:
import slapos.libnetworkcache try:
except ImportError: import slapos.libnetworkcache
LIBNETWORKCACHE_ENABLED = False except ImportError:
else: LIBNETWORKCACHE_ENABLED = False
LIBNETWORKCACHE_ENABLED = True else:
LIBNETWORKCACHE_ENABLED = True
except:
import traceback
print 'There was problem while trying to import slapos.libnetworkcache:'\
'\n%s' % traceback.format_exc()
LIBNETWORKCACHE_ENABLED = False
print 'Networkcache forced to be disabled.'
realpath = zc.buildout.easy_install.realpath realpath = zc.buildout.easy_install.realpath
......
...@@ -19,14 +19,21 @@ import posixpath ...@@ -19,14 +19,21 @@ import posixpath
import re import re
import shutil import shutil
import urlparse import urlparse
import traceback
try: try:
from slapos.libnetworkcache import NetworkcacheClient, UploadError, \ try:
DirectoryNotFound from slapos.libnetworkcache import NetworkcacheClient, UploadError, \
except ImportError: DirectoryNotFound
except ImportError:
LIBNETWORKCACHE_ENABLED = False
else:
LIBNETWORKCACHE_ENABLED = True
except:
print 'There was problem while trying to import slapos.libnetworkcache:'\
'\n%s' % traceback.format_exc()
LIBNETWORKCACHE_ENABLED = False LIBNETWORKCACHE_ENABLED = False
else: print 'Networkcache forced to be disabled.'
LIBNETWORKCACHE_ENABLED = True
_md5_re = re.compile(r'md5=([a-f0-9]+)') _md5_re = re.compile(r'md5=([a-f0-9]+)')
...@@ -37,7 +44,23 @@ def _get_md5_from_url(url): ...@@ -37,7 +44,23 @@ def _get_md5_from_url(url):
return match.group(1) return match.group(1)
return None return None
def fallback_call(function):
"""Decorator which disallow to have any problem while calling method"""
def wrapper(self, *args, **kwd):
"""
Log the call, and the result of the call
"""
try:
return function(self, *args, **kwd)
except: # indeed, *any* exception is swallowed
print 'There was problem while calling method %r:\n%s' % (
function.__name__, traceback.format_exc())
return False
wrapper.__doc__ = function.__doc__
return wrapper
@fallback_call
def get_directory_key(url): def get_directory_key(url):
"""Returns directory hash based on url. """Returns directory hash based on url.
...@@ -51,6 +74,7 @@ def get_directory_key(url): ...@@ -51,6 +74,7 @@ def get_directory_key(url):
return 'slapos-buildout-%s' % urlmd5 return 'slapos-buildout-%s' % urlmd5
@fallback_call
def download_network_cached(dir_url, cache_url, path, url, logger, def download_network_cached(dir_url, cache_url, path, url, logger,
signature_certificate_list, md5sum=None): signature_certificate_list, md5sum=None):
"""Downloads from a network cache provider """Downloads from a network cache provider
...@@ -104,6 +128,7 @@ def download_network_cached(dir_url, cache_url, path, url, logger, ...@@ -104,6 +128,7 @@ def download_network_cached(dir_url, cache_url, path, url, logger,
return True return True
@fallback_call
def upload_network_cached(dir_url, cache_url, external_url, path, logger, def upload_network_cached(dir_url, cache_url, external_url, path, logger,
signature_private_key_file, shacache_cert_file, shacache_key_file, signature_private_key_file, shacache_cert_file, shacache_key_file,
shadir_cert_file, shadir_key_file): shadir_cert_file, shadir_key_file):
...@@ -158,6 +183,7 @@ def upload_network_cached(dir_url, cache_url, external_url, path, logger, ...@@ -158,6 +183,7 @@ def upload_network_cached(dir_url, cache_url, external_url, path, logger,
return True return True
@fallback_call
def get_filename_from_url(url): def get_filename_from_url(url):
"""Inspired how pip get filename from url. """Inspired how pip get filename from url.
""" """
......
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