Page MenuHomePhabricator
Paste P13565

(An Untitled Masterwork)
ActivePublic

Authored by JMeybohm on Dec 17 2020, 9:58 AM.
Tags
None
Referenced Files
F33948024: raw-paste-data.txt
Dec 17 2020, 10:39 AM
F33948019: raw-paste-data.txt
Dec 17 2020, 10:30 AM
F33948004: raw-paste-data.txt
Dec 17 2020, 10:15 AM
F33948000: raw-paste-data.txt
Dec 17 2020, 10:03 AM
F33947998: raw-paste-data.txt
Dec 17 2020, 9:58 AM
Subscribers
None
#!/usr/bin/env python3
import requests
import random
import string
import pprint
registry_url = "docker-registry.wikimedia.org"
#registry_url = "docker-registry.discovery.wmnet"
def randstr():
return ''.join(random.choice(string.ascii_uppercase + string.digits) for _ in range(5))
def _request(url_part, bust_cache=""):
headers = {}
headers["Accept"] = "application/vnd.docker.distribution.manifest.v2+json"
url = "https://{}{}".format(registry_url, url_part)
if bust_cache:
url += "?cache={}".format(bust_cache)
response = requests.request("GET", url, headers=headers, stream=True)
response.raise_for_status()
return response
def compare_content_length(url, bust_cache=""):
r = _request(url, bust_cache)
try:
expected = int(r.headers["content-length"])
except KeyError:
print("ERROR: {} no content-length header".format(r.url))
pprint.pprint(r.headers, width=1)
return False
got = len(r.raw.data)
if expected != got:
print("ERROR: {} expected: {} got: {} ".format(img, expected, got))
pprint.pprint(r.headers, width=1)
return False
return True
img = ["/v2/releng/node10-test-browser/manifests/latest", ]
for url in img:
compare_content_length(url)
bust_cache = randstr()
r = compare_content_length(url, bust_cache=bust_cache)
if not r:
r2 = compare_content_length(url, bust_cache=bust_cache)
print("Second try okay?: {}".format(r2))