Skip to content
Snippets Groups Projects
test_apt_proxy.py 1.69 KiB
Newer Older
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# Copyright 2017, Florent Thiery
'''
Criticality: Normal
Stéphane Diemer's avatar
Stéphane Diemer committed
Checks that packages mirror works for capture systems
from pathlib import Path
import os
import requests
try:
    from requests.packages.urllib3.exceptions import InsecureRequestWarning
    requests.packages.urllib3.disable_warnings(InsecureRequestWarning)
except ImportError:
    requests.packages.urllib3.disable_warnings()

sys.path.append(str(Path(__file__).parents[1].resolve()))

# pylint: disable=wrong-import-position
from utilities import logging as lg  # noqa: E402


def main():
    # get Miris Manager domain
    path = '/etc/nginx/sites-enabled/skyreach.conf'
    if not os.path.exists(path):
        lg.log('Server not running Miris Manager, skipping test')
        return 2
    domain = None
    with open(path, 'r') as fo:
        for line in fo:
            if line.strip().startswith('server_name'):
                domain = line.strip()[len('server_name'):].strip(' \t;').split(' ')[0]
    if not domain:
        lg.error('Miris Manager domain not found in Nginx configuration.')
        url = 'https://%s/mirismanager.ubicast.eu/old-releases.ubuntu.com/ubuntu/dists/lucid/Release.gpg' % domain
        lg.log('Checking url certificate "%s"...' % url)
        response = requests.get(url, verify=False).text
        if 'BEGIN PGP SIGNATURE' not in response:
            lg.error('Unexpected content:\n%s' % response)
            lg.success('Test OK.')
    except Exception as e:
        lg.error('Package mirror not working: %s' % e)
if __name__ == '__main__':
    code = main()
    sys.exit(code)