Allow pip retry/retry delay to be provided as options

Change-Id: Iea398761ce6a9d3a8cf557eb17ca92d42bcdf9b7
This commit is contained in:
Joshua Harlow 2015-08-07 17:13:34 -07:00
parent b32d913c64
commit bfa51394a2
2 changed files with 11 additions and 12 deletions

View File

@ -54,8 +54,10 @@ class InstallHelper(object):
class DependencyHandler(object):
"""Basic class for handler of OpenStack dependencies."""
MAX_PIP_DOWNLOAD_ATTEMPTS = 4
PIP_DOWNLOAD_DELAY = 10
# Sometimes pip fails doing things, retry it when this happens...
RETRIES = 3
RETRY_DELAY = 10
def __init__(self, distro, root_dir,
instances, opts, group, prior_groups):
@ -65,6 +67,9 @@ class DependencyHandler(object):
self.prior_groups = prior_groups
self.opts = opts or {}
self.group = group
self.retries = max(0, int(opts.get('pip_retries', self.RETRIES)))
self.retry_delay = max(0, float(opts.get('pip_retry_delay',
self.RETRY_DELAY)))
# Various paths we will use while operating
self.deps_dir = sh.joinpths(self.root_dir, "deps")
self.download_dir = sh.joinpths(self.deps_dir, "download")
@ -355,9 +360,8 @@ class DependencyHandler(object):
if self._requirements_satisfied(pips_to_download, self.download_dir):
LOG.info("All python dependencies have been already downloaded")
else:
utils.retry(self.MAX_PIP_DOWNLOAD_ATTEMPTS,
self.PIP_DOWNLOAD_DELAY, self._try_download,
pips_to_download)
utils.retry(self.retries, self.retry_delay,
self._try_download, pips_to_download)
pips_downloaded = [pip_helper.extract_requirement(p) for p in pips_to_download]
what_downloaded = self._examine_download_dir(pips_downloaded, self.download_dir)
return (pips_downloaded, what_downloaded)

View File

@ -54,11 +54,6 @@ class VenvDependencyHandler(base.DependencyHandler):
PREREQUISITE_PKGS = frozenset(['pbr'])
PREREQUISITE_UPGRADE_PKGS = frozenset(['pip'])
# Sometimes pip fails downloading things, retry it when
# this happens...
_RETRIES = 3
_RETRY_DELAY = 5
def __init__(self, distro, root_dir,
instances, opts, group, prior_groups):
super(VenvDependencyHandler, self).__init__(distro, root_dir,
@ -199,7 +194,7 @@ class VenvDependencyHandler(base.DependencyHandler):
run_funcs = []
for instance in instances:
func = functools.partial(utils.retry,
self._RETRIES, self._RETRY_DELAY,
self.retries, self.retry_delay,
self._package_instance, instance,
retryable_exceptions=retryable_exceptions)
run_funcs.append(func)
@ -215,7 +210,7 @@ class VenvDependencyHandler(base.DependencyHandler):
self.package_instance(instance)
return results
def _package_instance(self, instance, attempt):
def _package_instance(self, instance, attempt=0):
if not self._is_buildable(instance):
# Skip things that aren't python...
LOG.warn("Skipping building %s (not python)",