From 540e7454dfc14a8d68924b13112029fe49437282 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Diemer?= <stephane.diemer@ubicast.eu>
Date: Tue, 13 Nov 2018 09:33:14 +0100
Subject: [PATCH] Ignore ubicast package test if no ubicast service is
 installed.

---
 tests/test_ubicast_packages_access.py | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/tests/test_ubicast_packages_access.py b/tests/test_ubicast_packages_access.py
index f547e3fc..08b71e18 100755
--- a/tests/test_ubicast_packages_access.py
+++ b/tests/test_ubicast_packages_access.py
@@ -7,14 +7,28 @@ Check that the updates server is reachable and that the system is still under su
 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)
-    sys.exit(1)
+    # Check if the test should return an error (if a UbiCast service is installed)
+    for package in ('python3-mediaserver', 'python3-mediaserver-monitor', 'campus-manager', 'skyreach', '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()
-- 
GitLab