Azure / azure-cli-extensions

Public Repository for Extensions of Azure CLI.
https://docs.microsoft.com/en-us/cli/azure
MIT License
383 stars 1.24k forks source link

CI test_index fail without showing which download url can't access #3396

Open xfz11 opened 3 years ago

xfz11 commented 3 years ago

Description of issue (in as much detail as possible)


Fail reason: https://github.com/Azure/azure-cli-extensions/blob/5c45cddc34a0a4a80b9c7d801d3700066cc18587/scripts/ci/util.py#L82

    for try_number in range(TRIES):
        try:
            r = requests.get(url, stream=True)
            assert r.status_code == 200, "Request to {} failed with {}".format(url, r.status_code)
            break
        except (requests.exceptions.ConnectionError, requests.exceptions.HTTPError) as err:
            import time
            time.sleep(0.5)
            continue
    ext_file = os.path.join(tmp_dir, filename)
    with open(ext_file, 'wb') as f:
        for chunk in r.iter_content(chunk_size=1024):
            if chunk:  # ignore keep-alive new chunks
                f.write(chunk)

If the download url can't access, then error will throw as below. But the code should catch the error if request fails more than 3 times and log which url cause the error.

error log: 2021-05-19T03:31:26.6037344Z ====================================================================== 2021-05-19T03:31:26.6037941Z ERROR: test_checksums (__main__.TestIndex) 2021-05-19T03:31:26.6039085Z ---------------------------------------------------------------------- 2021-05-19T03:31:26.6040045Z Traceback (most recent call last): 2021-05-19T03:31:26.6041069Z File "./scripts/ci/test_index.py", line 112, in test_checksums 2021-05-19T03:31:26.6043503Z self.whl_cache_dir, self.whl_cache) 2021-05-19T03:31:26.6044259Z File "/home/vsts/work/1/s/scripts/ci/util.py", line 94, in get_whl_from_url 2021-05-19T03:31:26.6044982Z for chunk in r.iter_content(chunk_size=1024): 2021-05-19T03:31:26.6045991Z UnboundLocalError: local variable 'r' referenced before assignment 2021-05-19T03:31:26.6046711Z 2021-05-19T03:31:26.6047311Z ====================================================================== 2021-05-19T03:31:26.6047901Z ERROR: test_metadata (__main__.TestIndex) 2021-05-19T03:31:26.6050156Z ---------------------------------------------------------------------- 2021-05-19T03:31:26.6051007Z Traceback (most recent call last): 2021-05-19T03:31:26.6051762Z File "./scripts/ci/test_index.py", line 142, in test_metadata 2021-05-19T03:31:26.6052726Z self.whl_cache_dir, self.whl_cache) 2021-05-19T03:31:26.6053506Z File "/home/vsts/work/1/s/scripts/ci/util.py", line 94, in get_whl_from_url 2021-05-19T03:31:26.6054275Z for chunk in r.iter_content(chunk_size=1024): 2021-05-19T03:31:26.6055335Z UnboundLocalError: local variable 'r' referenced before assignment 2021-05-19T03:31:26.6055866Z 2021-05-19T03:31:26.6056860Z ---------------------------------------------------------------------- 2021-05-19T03:31:26.6057599Z Ran 9 tests in 40.041s

Extension name (the extension in question)

yonzhan commented 3 years ago

CI