Newer
Older
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
'''

Stéphane Diemer
committed
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
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 ('python3-mediaserver', 'python3-mediaserver-monitor', 'skyreach', '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\.\-\_]+)/$'
if content:
for line in content.split('\n'):
m = re.match(expected, line)
if m:
print('The file "%s" is not correct: skyreach url not found.' % apt_source)
sys.exit(1)
print('SkyReach url is %s and API key is %s[...].' % (url, apt_token[:8]))
if not req.ok:
print('Request to %s failed (%s):' % (url, req.status_code))
print(req.text)
else:
print('Request to %s: OK.' % url)
apt_url = '%s/packaging/apt/%s/Packages' % (url, apt_token)
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)
else:
print('Request to %s: OK.' % apt_url)