Something went wrong on our end
-
Stéphane Diemer authoredStéphane Diemer authored
test_ubicast_packages_access.py 2.30 KiB
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
'''
Criticality: Normal
Check that the updates server is reachable and that the system is still under support contract.
'''
import os
import re
import requests
import subprocess
import sys
try:
from requests.packages.urllib3.exceptions import InsecureRequestWarning
requests.packages.urllib3.disable_warnings(InsecureRequestWarning)
except ImportError:
requests.packages.urllib3.disable_warnings()
# SkyReach APT file test
apt_source = '/etc/apt/sources.list.d/skyreach.list'
if not os.path.exists(apt_source):
print('The file "%s" does not exists.' % apt_source)
# Check if the test should return an error (if a UbiCast service is installed)
for package in ('ubicast-mediaserver', 'ubicast-monitor', 'ubicast-skyreach', 'ubicast-skyreach-erp', 'celerity-workers'):
p = subprocess.run(['dpkg', '-s', package], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
if p.returncode == 0:
sys.exit(1)
# No service installed, return non testable status
print('No UbiCast service is installed, ignoring test result.')
sys.exit(2)
with open(apt_source, 'r') as fo:
content = fo.read()
# content hould be something like:
# # skyreach repo
# deb https://panel.ubicast.eu packaging/apt/s0000000000000000000000000000000/
expected = r'^deb (http[s]{0,1}://[A-Za-z0-9\.\-\_]+) packaging/apt/([A-Za-z0-9\.\-\_]+)/$'
url = None
apt_token = None
if content:
for line in content.split('\n'):
m = re.match(expected, line)
if m:
url, apt_token = m.groups()
if not url or not apt_token:
print('The file "%s" is not correct: skyreach url not found.' % apt_source)
sys.exit(1)
print('SkyReach url is "%s" and APT token is "%s[...]".' % (url, apt_token[:8]))
# Test SkyReach responses
req = requests.get(url, verify=False)
if not req.ok:
print('Request to %s failed (%s):' % (url, req.status_code))
print(req.text)
sys.exit(1)
else:
print('Request to %s: OK.' % url)
apt_url = '%s/packaging/apt/%s/Packages' % (url, apt_token)
req = requests.get(apt_url, verify=False)
apt_url = apt_url.replace(apt_token, apt_token[:8] + '[...]')
if not req.ok:
print('Request to %s failed (%s):' % (apt_url, req.status_code))
print(req.text)
sys.exit(1)
else:
print('Request to %s: OK.' % apt_url)