Vladimir Khlyunev | f38cee2 | 2020-11-06 14:00:55 +0400 | [diff] [blame] | 1 | import datetime |
| 2 | import re |
| 3 | import urllib.request |
| 4 | |
| 5 | |
| 6 | def get_url_content(url): |
| 7 | with urllib.request.urlopen(url) as f: |
| 8 | return f.read().decode('utf-8') |
| 9 | |
| 10 | |
| 11 | def get_snapshot_date(target_content): |
| 12 | date_regex = r".*(\d\d\d\d-\d\d-\d\d-\d\d\d\d\d\d)" |
| 13 | snapshot_date_str = re.findall(date_regex, target_content)[0] |
| 14 | date_format = "%Y-%m-%d-%H%M%S" |
| 15 | snapshot_date = datetime.datetime.strptime(snapshot_date_str, date_format) |
| 16 | return snapshot_date |
| 17 | |
| 18 | |
| 19 | update_url = "http://mirror.mirantis.com/update/" |
| 20 | proposed_section = "proposed/" |
| 21 | releases_regex = r"2019.2.\d+" |
| 22 | mirror_target_file = "xenial.target.txt" |
| 23 | |
| 24 | update_url_content = get_url_content(update_url) |
| 25 | releases = re.findall(releases_regex, update_url_content) |
| 26 | latest_release = sorted(set(releases), |
| 27 | key=lambda release: int(release.split('.')[2]))[-1] |
| 28 | latest_release += "/" |
| 29 | update_released_url = update_url + latest_release |
| 30 | update_proposed_url = update_url + proposed_section |
| 31 | |
| 32 | proposed_subrepos = get_url_content(update_proposed_url) |
| 33 | |
| 34 | subrepos = ["cassandra/", |
| 35 | "ceph-luminous/", |
| 36 | "ceph-nautilus/", |
| 37 | "docker/", |
| 38 | "elasticsearch-5.x/", |
| 39 | "elasticsearch-6.x/", |
| 40 | "elasticsearch-curator-5/", |
| 41 | "extra/", |
| 42 | "glusterfs-5/", |
| 43 | "kubernetes-extra/", |
| 44 | "maas/", |
| 45 | "opencontrail-3.2/", |
| 46 | "opencontrail-4.0/", |
| 47 | "opencontrail-4.1/", |
| 48 | "opencontrail-5.0/", |
| 49 | "openstack-mitaka/", |
| 50 | "openstack-newton/", |
| 51 | "openstack-ocata/", |
| 52 | "openstack-pike/", |
| 53 | "openstack-queens/", |
| 54 | "percona/", |
| 55 | "salt-2017.7.8/", |
| 56 | "salt-formulas/", |
| 57 | "saltstack/", |
| 58 | "saltstack-2017.7/", |
| 59 | "td-agent/", |
| 60 | "ubuntu", |
| 61 | "maas-ephemeral-v3"] |
| 62 | |
| 63 | good_subrepos = [] |
| 64 | suspicious_subrepos = [] |
| 65 | error_subrepos = [] |
| 66 | |
| 67 | |
| 68 | def check_snapshot(subrepo): |
| 69 | if subrepo in ['ubuntu', 'maas-ephemeral-v3']: |
| 70 | proposed_target_url = "{}{}".format( |
| 71 | update_proposed_url, "{}.target.txt".format(subrepo)) |
| 72 | released_target_url = "{}{}".format( |
| 73 | update_released_url, "{}.target.txt".format(subrepo)) |
| 74 | else: |
| 75 | proposed_target_url = "{}{}{}".format(update_proposed_url, subrepo, |
| 76 | mirror_target_file) |
| 77 | released_target_url = "{}{}{}".format(update_released_url, subrepo, |
| 78 | mirror_target_file) |
| 79 | |
| 80 | released_snapshot = get_url_content(released_target_url).splitlines()[0] |
| 81 | proposed_snapshot = get_url_content(proposed_target_url).splitlines()[0] |
| 82 | released_snapshot_date = get_snapshot_date(released_snapshot) |
| 83 | proposed_snapshot_date = get_snapshot_date(proposed_snapshot) |
| 84 | if proposed_snapshot_date > released_snapshot_date: |
Vladimir Khlyunev | 0f33394 | 2020-11-16 17:14:18 +0400 | [diff] [blame] | 85 | good_subrepos.append([subrepo, proposed_snapshot]) |
Vladimir Khlyunev | f38cee2 | 2020-11-06 14:00:55 +0400 | [diff] [blame] | 86 | elif proposed_snapshot_date == released_snapshot_date: |
| 87 | suspicious_subrepos.append([subrepo, proposed_snapshot]) |
| 88 | else: |
| 89 | error_subrepos.append([subrepo, proposed_snapshot, released_snapshot]) |
| 90 | |
| 91 | |
| 92 | for subrepo in subrepos: |
| 93 | check_snapshot(subrepo) |
| 94 | |
Vladimir Khlyunev | 0f33394 | 2020-11-16 17:14:18 +0400 | [diff] [blame] | 95 | for i in good_subrepos: |
Vladimir Khlyunev | f38cee2 | 2020-11-06 14:00:55 +0400 | [diff] [blame] | 96 | print("Repo {} - all fine, proposed is fresher than " |
Vladimir Khlyunev | 0f33394 | 2020-11-16 17:14:18 +0400 | [diff] [blame] | 97 | "latest release\n{}".format(i[0], i[1])) |
Vladimir Khlyunev | f38cee2 | 2020-11-06 14:00:55 +0400 | [diff] [blame] | 98 | print("Good news ended\n" + "=" * 79) |
| 99 | for i in suspicious_subrepos: |
| 100 | print( |
| 101 | "Repo {} - same as previous release, ensure than this is fine:\n" |
| 102 | "{}".format(i[0], i[1])) |
| 103 | print("Mediocre news ended\n" + "X" * 79) |
| 104 | for i in error_subrepos: |
| 105 | print( |
| 106 | "ERROR: Repo {} IS OLDER THAN RELEASED ONE!!!\n" |
| 107 | "Released:{}\n" |
| 108 | "Proposed:{}".format(i[0], i[1], i[2])) |
| 109 | if error_subrepos: |
| 110 | exit(1) |