~vila/ols-store-tests/fix-arch-requirement

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/usr/bin/env python3

import requests

REQ_HEADERS = {
    'Cache-Control': 'no-cache',
}

DEFAULT_HEADER = "X-BZR-REVISION-NUMBER"

SERVICES_INFO = dict(
    CPI=('HEAD', 'https://search.apps.ubuntu.com/api/v1',
         'https://search.apps.staging.ubuntu.com/api/v1'),
    SCA=('GET', 'https://myapps.developer.ubuntu.com/',
         'https://myapps.developer.staging.ubuntu.com/'),
    SSO=('GET', 'https://login.ubuntu.com/',
         'https://login.staging.ubuntu.com/'),
)


def get_deployed_revno(service, environment):
    """Get revno from service."""
    request_type, prod, stag = SERVICES_INFO[service]
    if environment == 'staging':
        url = stag
    else:
        url = prod

    with requests.Session() as session:
        resp = session.get(url)
        if resp.status_code == 200:
            revno = resp.headers[DEFAULT_HEADER]
        else:
            print("{} 500'ed: {}".format(service, resp.text))
            revno = 0

    return service, environment, revno


def main(environ):
    coros = []
    for service in SERVICES_INFO:
        coro = get_deployed_revno(service, environ)
        coros.append(coro)

    data = {(service, kind): value for service, kind, value in coros}
    for service in sorted(SERVICES_INFO):
        print("{}:    {}:    {:>5}".format(service, environ,
                                           data[(service, environ)]))


if __name__ == '__main__':
    environ = 'staging'
    main(environ)