Something went wrong on our end
-
Stéphane Diemer authoredStéphane Diemer authored
test_apt_proxy.py 1.66 KiB
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# Copyright 2017, Florent Thiery
'''
Criticality: Normal
Checks that packages mirror works for capture systems
'''
from pathlib import Path
import os
import requests
import sys
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
import utils as u # noqa: E402
def main():
# get Miris Manager domain
path = '/etc/nginx/sites-enabled/skyreach.conf'
if not os.path.exists(path):
u.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:
u.error('Miris Manager domain not found in Nginx configuration.')
return 1
try:
url = 'https://%s/panel.ubicast.eu/old-releases.ubuntu.com/ubuntu/dists/lucid/Release.gpg' % domain
u.log('Checking url certificate "%s"...' % url)
response = requests.get(url, verify=False).text
if 'BEGIN PGP SIGNATURE' not in response:
u.error('Unexpected content:\n%s' % response)
return 1
else:
u.success('Test OK.')
except Exception as e:
u.error('Package mirror not working: %s' % e)
return 1
return 0
if __name__ == '__main__':
code = main()
sys.exit(code)