Skip to content

Commit

Permalink
Fix for incorrect marking EOL if connection fails
Browse files Browse the repository at this point in the history
This fixes the bug that incorrectly assumes EOL if connection fails.
See #1
  • Loading branch information
tfogwill committed Sep 5, 2017
1 parent 8d183fc commit 3f7d342
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion apt_mirror_updater/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,8 @@ def release_is_eol(self):
logger.debug("Checking whether %s suite %s is EOL ..",
self.distributor_id.capitalize(),
self.distribution_codename.capitalize())
release_is_eol = not self.validate_mirror(self.security_url)
# only set EOL if we can connect but validation fails - this prevents incorrect setting of EOL if network connection fails
release_is_eol = self.can_connect_to_mirror(self.security_url) and not self.validate_mirror(self.security_url)
logger.debug("The %s suite %s is %s.",
self.distributor_id.capitalize(),
self.distribution_codename.capitalize(),
Expand Down Expand Up @@ -598,6 +599,30 @@ def smart_update(self, max_attempts=10, switch_mirrors=True):
backoff_time += backoff_time / 3
raise Exception("Failed to update package lists %i consecutive times?!" % max_attempts)

def can_connect_to_mirror(self, mirror_url):
"""
Make sure the mirror can be connected to
:param mirror_url: The base URL of the mirror (a string).
:returns: :data:`True` if the mirror can be connected to,
:data:`False` otherwise.
.
"""
mirror_url = normalize_mirror_url(mirror_url)
logger.info("Checking whether %s can be connected to.", mirror_url)
mirror = CandidateMirror(mirror_url=mirror_url, updater=self)
try:
response = fetch_url(mirror.release_gpg_url, retry=False)
mirror.release_gpg_contents = response.read()
except urllib2.URLError as e:
if 'connection refused' in str(e.reason).lower():
logger.warning("Cannot connect to %s.", mirror_url)
return False
except Exception:
pass
logger.info("Can connect to %s.", mirror_url)
return True

def validate_mirror(self, mirror_url):
"""
Make sure a mirror serves :attr:`distribution_codename`.
Expand Down

0 comments on commit 3f7d342

Please sign in to comment.