~canonical-platform-qa/snappy-ecosystem-tests/remove-unneeded-FIXMEs

« back to all changes in this revision

Viewing changes to snappy_ecosystem_tests/utils/store_versions.py

  • Committer: Omer Akram
  • Date: 2017-03-03 14:12:16 UTC
  • mfrom: (22.1.6 trunk)
  • Revision ID: om26er@ubuntu.com-20170303141216-ny9pnukubbfhaz9z
merge with trnk

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
 
2
 
 
3
#
 
4
# Snappy Ecosystem Tests
 
5
# Copyright (C) 2017 Canonical
 
6
#
 
7
# This program is free software: you can redistribute it and/or modify
 
8
# it under the terms of the GNU General Public License as published by
 
9
# the Free Software Foundation, either version 3 of the License, or
 
10
# (at your option) any later version.
 
11
#
 
12
# This program is distributed in the hope that it will be useful,
 
13
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
15
# GNU General Public License for more details.
 
16
#
 
17
# You should have received a copy of the GNU General Public License
 
18
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
19
#
 
20
 
 
21
"""Utility for printing Store versions of: CPI, SCA and SSO.
 
22
To be called as a standalone script.
 
23
"""
 
24
 
 
25
import requests
 
26
 
 
27
DEFAULT_HEADER = "X-BZR-REVISION-NUMBER"
 
28
 
 
29
SERVICES_INFO = dict(
 
30
    CPI=('https://search.apps.ubuntu.com/api/v1',
 
31
         'https://search.apps.staging.ubuntu.com/api/v1'),
 
32
    SCA=('https://myapps.developer.ubuntu.com/',
 
33
         'https://myapps.developer.staging.ubuntu.com/'),
 
34
    SSO=('https://login.ubuntu.com/',
 
35
         'https://login.staging.ubuntu.com/'),
 
36
)
 
37
 
 
38
 
 
39
def get_deployed_revno(service, environment):
 
40
    """Get revno from service."""
 
41
    prod, stag = SERVICES_INFO[service]
 
42
    if environment == 'staging':
 
43
        url = stag
 
44
    else:
 
45
        url = prod
 
46
    with requests.Session() as session:
 
47
        resp = session.get(url)
 
48
        if resp.status_code == 200:
 
49
            revno = resp.headers[DEFAULT_HEADER]
 
50
        else:
 
51
            print("{} 500'ed: {}".format(service, resp.text))
 
52
            revno = 0
 
53
    return service, environment, revno
 
54
 
 
55
 
 
56
def print_versions():
 
57
    """Print Store components version"""
 
58
    coros = []
 
59
    for service in SERVICES_INFO:
 
60
        coro = get_deployed_revno(service, 'staging')
 
61
        coros.append(coro)
 
62
        coro = get_deployed_revno(service, 'production')
 
63
        coros.append(coro)
 
64
 
 
65
    data = {(service, kind): value for service, kind, value in coros}
 
66
    print("#########################-STORE VERSIONS-#########################")
 
67
    for service in sorted(SERVICES_INFO):
 
68
        print("{}:    Staging:    {:>5}".format(service,
 
69
                                                data[(service, 'staging')]))
 
70
        print("{}:    Production: {:>5}".format(service,
 
71
                                                data[(service, 'production')]))
 
72
 
 
73
if __name__ == '__main__':
 
74
    print_versions()