зеркало из https://github.com/mozilla/bugbug.git
Use fallback URL to the old Taskcluster index when retrieving the version file too
This commit is contained in:
Родитель
12b71f9711
Коммит
2f347cb853
13
bugbug/db.py
13
bugbug/db.py
|
@ -39,9 +39,16 @@ def exists(path):
|
|||
|
||||
|
||||
def is_old_version(path):
|
||||
r = requests.get(
|
||||
urljoin(DATABASES[path]["url"], f"{os.path.basename(path)}.version")
|
||||
)
|
||||
url = urljoin(DATABASES[path]["url"], f"{os.path.basename(path)}.version")
|
||||
r = requests.get(url)
|
||||
|
||||
if not r.ok:
|
||||
url = url.replace(
|
||||
"https://community-tc.services.mozilla.com/api/index",
|
||||
"https://index.taskcluster.net",
|
||||
)
|
||||
r = requests.get(url)
|
||||
|
||||
if not r.ok:
|
||||
print(f"Version file is not yet available to download for {path}")
|
||||
return True
|
||||
|
|
|
@ -270,6 +270,7 @@ def test_download_support_file_zst(tmp_path, mock_zst):
|
|||
def test_is_old_version(tmp_path):
|
||||
url_zst = "https://community-tc.services.mozilla.com/api/index/v1/task/project.relman.bugbug.data_commits.latest/artifacts/public/prova.json.zst"
|
||||
url_version = "https://community-tc.services.mozilla.com/api/index/v1/task/project.relman.bugbug.data_commits.latest/artifacts/public/prova.json.version"
|
||||
url_version_fallback = "https://index.taskcluster.net/v1/task/project.relman.bugbug.data_commits.latest/artifacts/public/prova.json.version"
|
||||
|
||||
db_path = tmp_path / "prova.json"
|
||||
db.register(db_path, url_zst, 1, support_files=[])
|
||||
|
@ -277,7 +278,9 @@ def test_is_old_version(tmp_path):
|
|||
assert os.path.exists(db_path.with_suffix(db_path.suffix + ".version"))
|
||||
|
||||
responses.add(responses.GET, url_version, status=404)
|
||||
responses.add(responses.GET, url_version_fallback, status=404)
|
||||
responses.add(responses.GET, url_version, status=424)
|
||||
responses.add(responses.GET, url_version_fallback, status=424)
|
||||
responses.add(responses.GET, url_version, status=200, body="1")
|
||||
responses.add(responses.GET, url_version, status=200, body="42")
|
||||
|
||||
|
@ -299,6 +302,43 @@ def test_is_old_version(tmp_path):
|
|||
assert db.is_old_version(db_path)
|
||||
|
||||
|
||||
def test_is_old_version_fallback(tmp_path):
|
||||
url_zst = "https://community-tc.services.mozilla.com/api/index/v1/task/project.relman.bugbug.data_commits.latest/artifacts/public/prova.json.zst"
|
||||
url_version = "https://community-tc.services.mozilla.com/api/index/v1/task/project.relman.bugbug.data_commits.latest/artifacts/public/prova.json.version"
|
||||
url_version_fallback = "https://index.taskcluster.net/v1/task/project.relman.bugbug.data_commits.latest/artifacts/public/prova.json.version"
|
||||
|
||||
db_path = tmp_path / "prova.json"
|
||||
db.register(db_path, url_zst, 1, support_files=[])
|
||||
|
||||
assert os.path.exists(db_path.with_suffix(db_path.suffix + ".version"))
|
||||
|
||||
responses.add(responses.GET, url_version, status=404)
|
||||
responses.add(responses.GET, url_version_fallback, status=404)
|
||||
responses.add(responses.GET, url_version, status=424)
|
||||
responses.add(responses.GET, url_version_fallback, status=424)
|
||||
responses.add(responses.GET, url_version, status=404)
|
||||
responses.add(responses.GET, url_version_fallback, status=200, body="1")
|
||||
responses.add(responses.GET, url_version, status=404)
|
||||
responses.add(responses.GET, url_version_fallback, status=200, body="42")
|
||||
|
||||
# When the remote version file doesn't exist, we consider the db as being old.
|
||||
assert db.is_old_version(db_path)
|
||||
|
||||
# When the remote version file doesn't exist, we consider the db as being old.
|
||||
assert db.is_old_version(db_path)
|
||||
|
||||
# When the remote version file exists and returns the same version as the current db, we consider the remote db as not being old.
|
||||
assert not db.is_old_version(db_path)
|
||||
|
||||
# When the remote version file exists and returns a newer version than the current db, we consider the remote db as not being old.
|
||||
assert not db.is_old_version(db_path)
|
||||
|
||||
db.register(db_path, url_zst, 43, support_files=[])
|
||||
|
||||
# When the remote version file exists and returns an older version than the current db, we consider the remote db as being old.
|
||||
assert db.is_old_version(db_path)
|
||||
|
||||
|
||||
def test_download_support_file_missing(tmp_path, caplog):
|
||||
url = "https://community-tc.services.mozilla.com/api/index/v1/task/project.relman.bugbug.data_commits.latest/artifacts/public/commits.json.zst"
|
||||
support_filename = "support_mock.zst"
|
||||
|
|
Загрузка…
Ссылка в новой задаче