Ignore 404 error on dowloading release file

Some debian repositories does not contain Release file.

Change-Id: Iad69241856e62b74cdee3a68481957ef38c3ab59
Closes-Bug: #1539703
This commit is contained in:
Bulat Gaifullin 2016-01-29 20:36:44 +03:00
parent ec8a9c8c22
commit d99d1228ef
3 changed files with 47 additions and 1 deletions

View File

@ -109,7 +109,14 @@ class DebRepositoryDriver(RepositoryDriverBase):
release = self._get_url_of_metafile(
(url, suite, component, arch), "Release"
)
deb_release = deb822.Release(connection.open_stream(release))
try:
deb_release = deb822.Release(connection.open_stream(release))
except connection.HTTPError as e:
if e.code != 404:
raise
# some repositories does not contain release file
deb_release = {"origin": ""}
consumer(Repository(
name=name,
architecture=arch,

View File

@ -158,6 +158,8 @@ def is_retryable_http_error(code):
class ConnectionsManager(object):
"""The connections manager."""
HTTPError = urlerror.HTTPError
def __init__(self, proxy=None, secure_proxy=None,
retries_num=0, retry_interval=0):
"""Initialises.

View File

@ -30,6 +30,11 @@ from packetary.tests.stubs.helpers import get_compressed
PACKAGES = path.join(path.dirname(__file__), "data", "Packages")
class HTTPError(Exception):
def __init__(self, code):
self.code = code
class TestDebDriver(base.TestCase):
@classmethod
def setUpClass(cls):
@ -39,6 +44,7 @@ class TestDebDriver(base.TestCase):
def setUp(self):
self.connection = mock.MagicMock()
self.connection.HTTPError = HTTPError
self.repo = gen_repository(
name="trusty", section=("trusty", "main"), url="file:///repo"
)
@ -91,6 +97,37 @@ class TestDebDriver(base.TestCase):
self.assertEqual("x86_64", repo.architecture)
self.assertEqual("http://host/", repo.url)
def test_get_repository_if_release_does_not_exist(self):
repo_data = {
"name": "repo1", "url": "http://host", "suite": "trusty",
"section": ["main"], "path": "my_path"
}
repos = []
self.connection.open_stream.side_effect = HTTPError(404)
self.driver.get_repository(
self.connection,
repo_data,
"x86_64",
repos.append
)
self.assertEqual(1, len(repos))
self.assertEqual("", repos[0].origin)
def test_get_repository_fail_if_error(self):
repo_data = {
"name": "repo1", "url": "http://host", "suite": "trusty",
"section": ["main"], "path": "my_path"
}
repos = []
self.connection.open_stream.side_effect = HTTPError(403)
with self.assertRaises(HTTPError):
self.driver.get_repository(
self.connection,
repo_data,
"x86_64",
repos.append
)
def test_get_flat_repository(self):
with self.assertRaisesRegexp(ValueError, "does not supported"):
self.driver.get_repository(