Skip to content

Commit

Permalink
client: add failure handling to fetch_results
Browse files Browse the repository at this point in the history
Fixes the following Traceback for tasks without any results:
```
$ osh/client/osh-cli download-results 1
Downloading dotnet3.1-3.1.424-1.fc35.tar.xz
Traceback (most recent call last):
  File "/Users/lzaoral/redhat/OpenScanHub/osh/client/osh-cli", line 79, in <module>
    main()
  File "/Users/lzaoral/redhat/OpenScanHub/osh/client/osh-cli", line 72, in main
    parser.run()
  File "/Users/lzaoral/redhat/OpenScanHub/kobo/kobo/cli.py", line 296, in run
    cmd.run(*cmd_args, **cmd_kwargs)
  File "/Users/lzaoral/redhat/OpenScanHub/osh/client/commands/cmd_download_results.py", line 51, in run
    fetch_results(self.hub, results_dir, task_id)
  File "/Users/lzaoral/redhat/OpenScanHub/osh/client/commands/shortcuts.py", line 138, in fetch_results
    urlretrieve(url, local_path)
  File "/opt/homebrew/Cellar/[email protected]/3.11.4_1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/urllib/request.py", line 241, in urlretrieve
    with contextlib.closing(urlopen(url, data)) as fp:
                            ^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/[email protected]/3.11.4_1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/urllib/request.py", line 216, in urlopen
    return opener.open(url, data, timeout)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/[email protected]/3.11.4_1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/urllib/request.py", line 525, in open
    response = meth(req, response)
               ^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/[email protected]/3.11.4_1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/urllib/request.py", line 634, in http_response
    response = self.parent.error(
               ^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/[email protected]/3.11.4_1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/urllib/request.py", line 563, in error
    return self._call_chain(*args)
           ^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/[email protected]/3.11.4_1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/urllib/request.py", line 496, in _call_chain
    result = func(*args)
             ^^^^^^^^^^^
  File "/opt/homebrew/Cellar/[email protected]/3.11.4_1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/urllib/request.py", line 643, in http_error_default
    raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 404: Not Found
```

Related: release-engineering/kobo#214
Related: https://gitlab.cee.redhat.com/covscan/covscan/-/issues/273
  • Loading branch information
lzaoral committed Sep 7, 2023
1 parent 7961d01 commit 2332aa1
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
6 changes: 4 additions & 2 deletions osh/client/commands/cmd_diff_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# SPDX-FileCopyrightText: Copyright contributors to the OpenScanHub project.

import os
import sys
from xmlrpc.client import Fault

from kobo.shortcuts import random_string
Expand Down Expand Up @@ -186,8 +187,9 @@ def run(self, *args, **kwargs): # noqa: C901
TaskWatcher.watch_tasks(self.hub, [task_id])

# store results if user requested this
if self.results_store_file is not None:
fetch_results(self.hub, self.results_store_file, task_id)
if self.results_store_file is not None and \
not fetch_results(self.hub, self.results_store_file, task_id):
sys.exit(1)

def submit_task(self, config, comment, options):
try:
Expand Down
2 changes: 1 addition & 1 deletion osh/client/commands/cmd_download_results.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def run(self, *tasks, **kwargs):
success = False
continue

fetch_results(self.hub, results_dir, task_id)
success &= fetch_results(self.hub, results_dir, task_id)

if not success:
sys.exit(1)
12 changes: 10 additions & 2 deletions osh/client/commands/shortcuts.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import os
import re
import sys
from urllib.error import HTTPError
from urllib.request import urlretrieve
from xmlrpc.client import Fault

Expand Down Expand Up @@ -134,8 +135,15 @@ def fetch_results(hub, dest, task_id):
# task_url is url to task with trailing '/'
url = f"{task_url}log/{tarball}?format=raw"

print(f"Downloading {tarball}", file=sys.stderr)
urlretrieve(url, local_path)
print(f"Downloading {tarball}: ", file=sys.stderr, end="")
try:
urlretrieve(url, local_path)
except HTTPError as e:
print(e, file=sys.stderr)
return False

print("OK", file=sys.stderr)
return True


def upload_file(hub, srpm, target_dir, parser):
Expand Down

0 comments on commit 2332aa1

Please sign in to comment.