Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

athena: uploads, show which items fail on error #23412

Merged
merged 4 commits into from
Jan 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions selfdrive/athena/athenad.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,23 +269,29 @@ def uploadFileToUrl(fn, url, headers):
@dispatcher.add_method
def uploadFilesToUrls(files_data):
items = []
failed = []
for fn, url, headers in files_data:
if len(fn) == 0 or fn[0] == '/' or '..' in fn:
return 500
failed.append(fn)
continue
path = os.path.join(ROOT, fn)
if not os.path.exists(path):
return 404
failed.append(fn)
continue

item = UploadItem(path=path, url=url, headers=headers, created_at=int(time.time() * 1000), id=None)
upload_id = hashlib.sha1(str(item).encode()).hexdigest()
items.append(item._replace(id=upload_id))

for item in items:
item = item._replace(id=upload_id)
upload_queue.put_nowait(item)
items.append(item._asdict())

UploadQueueCache.cache(upload_queue)

return {"enqueued": len(items), "items": [i._asdict() for i in items]}
resp = {"enqueued": len(items), "items": items}
if failed:
resp["failed"] = failed

return resp


@dispatcher.add_method
Expand Down
3 changes: 2 additions & 1 deletion selfdrive/athena/tests/test_athenad.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,13 +134,14 @@ def test_do_upload(self, host):
@with_http_server
def test_uploadFileToUrl(self, host):
not_exists_resp = dispatcher["uploadFileToUrl"]("does_not_exist.bz2", "http://localhost:1238", {})
self.assertEqual(not_exists_resp, 404)
self.assertEqual(not_exists_resp, {'enqueued': 0, 'items': [], 'failed': ['does_not_exist.bz2']})

fn = os.path.join(athenad.ROOT, 'qlog.bz2')
Path(fn).touch()

resp = dispatcher["uploadFileToUrl"]("qlog.bz2", f"{host}/qlog.bz2", {})
self.assertEqual(resp['enqueued'], 1)
self.assertNotIn('failed', resp)
self.assertDictContainsSubset({"path": fn, "url": f"{host}/qlog.bz2", "headers": {}}, resp['items'][0])
self.assertIsNotNone(resp['items'][0].get('id'))
self.assertEqual(athenad.upload_queue.qsize(), 1)
Expand Down