Skip to content
Snippets Groups Projects
Commit 38fb2219 authored by Stéphane Diemer's avatar Stéphane Diemer
Browse files

Avoid imp usage in APT proxy test

parent e391769f
No related branches found
No related tags found
No related merge requests found
......@@ -5,46 +5,54 @@
Criticality: Normal
Checks that packages mirror works for capture systems
'''
import imp
from pathlib import Path
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',
)
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 envsetup 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
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))
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:
print('%sTest OK%s' % (GREEN, DEF))
except Exception:
print('%sPackage mirror not working%s' % (RED, DEF))
all_ok = False
u.success('Test OK.')
except Exception as e:
u.error('Package mirror not working: %s' % e)
return 1
return 0
sys.exit(int(not all_ok))
if __name__ == '__main__':
code = main()
sys.exit(code)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment