Skip to content

Commit

Permalink
Fix UploadError/NetworkError exception handling
Browse files Browse the repository at this point in the history
Pip package manager requests should not fail on already uploaded package

CLOUDBLD-10907

Signed-off-by: Ladislav Kolacek <[email protected]>
  • Loading branch information
lkolacek committed Aug 23, 2022
1 parent 07f5cb1 commit fcde3cb
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion cachito/workers/nexus.py
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ def upload_raw_component(repo_name, directory, components, to_nexus_hoster=True)

try:
upload_component(params, payload, to_nexus_hoster, additional_data)
except NetworkError:
except UploadError:
log.exception("Failed to upload %r to the raw Nexus repository", components)
raise

Expand Down
6 changes: 3 additions & 3 deletions cachito/workers/pkg_managers/pip.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
)
from cachito.workers import nexus
from cachito.workers.config import get_worker_config
from cachito.workers.errors import NexusScriptError
from cachito.workers.errors import NexusScriptError, UploadError
from cachito.workers.paths import RequestBundleDir
from cachito.workers.pkg_managers import general
from cachito.workers.pkg_managers.general import (
Expand Down Expand Up @@ -1965,7 +1965,7 @@ def _push_downloaded_requirement(requirement, pip_repo_name, raw_repo_name):
if requirement["kind"] == "pypi":
try:
upload_pypi_package(pip_repo_name, requirement["path"])
except (NetworkError, ValueError):
except UploadError:
if nexus.get_component_info_from_nexus(
pip_repo_name,
"pypi",
Expand All @@ -1987,7 +1987,7 @@ def _push_downloaded_requirement(requirement, pip_repo_name, raw_repo_name):
dest_dir, filename = requirement["raw_component_name"].rsplit("/", 1)
try:
upload_raw_package(raw_repo_name, requirement["path"], dest_dir, filename, True)
except (NetworkError, ValueError):
except UploadError:
if nexus.get_component_info_from_nexus(
raw_repo_name,
"raw",
Expand Down
10 changes: 5 additions & 5 deletions tests/test_workers/test_pkg_managers/test_pip.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
NexusError,
ValidationError,
)
from cachito.workers.errors import NexusScriptError
from cachito.workers.errors import NexusScriptError, UploadError
from cachito.workers.pkg_managers import general, pip
from tests.helper_utils import write_file_tree

Expand Down Expand Up @@ -3363,7 +3363,7 @@ def test_push_downloaded_requirement_from_pypi(mock_upload, dev):
@mock.patch("cachito.workers.pkg_managers.pip.upload_pypi_package")
@mock.patch("cachito.workers.pkg_managers.pip.nexus.get_component_info_from_nexus")
def test_push_downloaded_requirement_from_pypi_duplicated(mock_get_info, mock_upload, uploaded):
mock_upload.side_effect = NetworkError("stub")
mock_upload.side_effect = UploadError("stub")
mock_get_info.return_value = uploaded
pip_repo_name = "test-pip-hosted"
raw_repo_name = "test-pip-raw"
Expand All @@ -3377,7 +3377,7 @@ def test_push_downloaded_requirement_from_pypi_duplicated(mock_get_info, mock_up
mock_upload.assert_called_once_with(pip_repo_name, path)
assert dependency == expected_dependency
else:
with pytest.raises(NetworkError, match="stub"):
with pytest.raises(UploadError, match="stub"):
pip._push_downloaded_requirement(req, pip_repo_name, raw_repo_name)


Expand Down Expand Up @@ -3432,7 +3432,7 @@ def test_push_downloaded_requirement_non_pypi(mock_upload, dev, kind):
def test_push_downloaded_requirement_non_pypi_duplicated(
mock_get_info, mock_upload, kind, uploaded
):
mock_upload.side_effect = NetworkError("stub")
mock_upload.side_effect = UploadError("stub")
mock_get_info.return_value = uploaded
pip_repo_name = "test-pip-hosted"
raw_repo_name = "test-pip-raw"
Expand Down Expand Up @@ -3474,7 +3474,7 @@ def test_push_downloaded_requirement_non_pypi_duplicated(
mock_upload.assert_called_once_with(raw_repo_name, path, dest_dir, filename, True)
assert dependency == expected_dependency
else:
with pytest.raises(NetworkError, match="stub"):
with pytest.raises(UploadError, match="stub"):
pip._push_downloaded_requirement(req, pip_repo_name, raw_repo_name)


Expand Down

0 comments on commit fcde3cb

Please sign in to comment.