diff --git a/packetary/drivers/deb_driver.py b/packetary/drivers/deb_driver.py index 131715a..69275d3 100644 --- a/packetary/drivers/deb_driver.py +++ b/packetary/drivers/deb_driver.py @@ -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, diff --git a/packetary/library/connections.py b/packetary/library/connections.py index 9a37861..6b013a7 100644 --- a/packetary/library/connections.py +++ b/packetary/library/connections.py @@ -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. diff --git a/packetary/tests/test_deb_driver.py b/packetary/tests/test_deb_driver.py index 7dab61b..c22630d 100644 --- a/packetary/tests/test_deb_driver.py +++ b/packetary/tests/test_deb_driver.py @@ -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(