Skip to content
Snippets Groups Projects
test_apt_proxy.py 1.22 KiB
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# Copyright 2017, Florent Thiery
'''
Criticality: Normal
Checks that packages mirror works for capture systems
'''
import imp
import os
import requests
import sys

GREEN = '\033[92m'
RED = '\033[91m'
DEF = '\033[0m'

if not os.path.exists('/etc/nginx/sites-enabled/skyreach.conf'):
    print('Server not running Miris Manager, skipping test')
    sys.exit(2)

os.chdir(os.path.dirname(__file__))
if not os.path.isfile('../utils.py'):
    print('conf.sh not found')
    sys.exit(1)

es_utils = imp.load_source('es_utils', '../utils.py')
conf = es_utils.load_conf()

all_ok = True

conf_servers = (
    'CM_SERVER_NAME',
)

for s in conf_servers:
    v = conf.get(s)
    try:
        url = 'https://%s/panel.ubicast.eu/old-releases.ubuntu.com/ubuntu/dists/lucid/Release.gpg' % v
        print('Checking url certificate %s' % url)
        d = requests.get(url, verify=False).text
        if 'BEGIN PGP SIGNATURE' not in d:
            all_ok = False
            print('%sUnexpected content: %s%s' % (RED, d, DEF))
        else:
            print('%sTest OK%s' % (GREEN, DEF))
    except Exception:
        print('%sPackage mirror not working%s' % (RED, DEF))
        all_ok = False

sys.exit(int(not all_ok))