From 88cab433286e094c19915f357060a6358fd42fcb Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Diemer?= <stephane.diemer@ubicast.eu>
Date: Fri, 16 Mar 2018 16:21:08 +0100
Subject: [PATCH] Added celerity version check (refs #23674).

---
 tests/test_mediaworker.py | 35 ++++++++++++++++++++++++++++-------
 1 file changed, 28 insertions(+), 7 deletions(-)

diff --git a/tests/test_mediaworker.py b/tests/test_mediaworker.py
index 36b7fd53..847d40c2 100755
--- a/tests/test_mediaworker.py
+++ b/tests/test_mediaworker.py
@@ -34,7 +34,7 @@ conf = es_utils.load_conf()
 
 
 def check_ssh(ip):
-    cmd = 'ssh -o StrictHostKeyChecking=no -o PasswordAuthentication=no %s ls /tmp' % ip
+    cmd = 'ssh -o StrictHostKeyChecking=no -o PasswordAuthentication=no root@%s ls /tmp' % ip
     print('Connecting to MediaWorker:\n%s' % cmd)
     try:
         subprocess.check_output(cmd, shell=True, timeout=5)
@@ -47,10 +47,10 @@ def check_ssh(ip):
 
 def run_tests(ip):
     print('Updating envsetup tests on MediaWorker.')
-    cmd = 'ssh -t %s /root/envsetup/update_envsetup.py' % ip
+    cmd = 'ssh -t root@%s /root/envsetup/update_envsetup.py' % ip
     os.system(cmd)
     print('Running envsetup tests on MediaWorker.')
-    cmd = 'ssh -t %s /root/envsetup/tester.py' % ip
+    cmd = 'ssh -t root@%s /root/envsetup/tester.py' % ip
     status = os.system(cmd)
     if status == 0:
         subprocess.check_output(cmd, shell=True, timeout=60)
@@ -63,7 +63,7 @@ def run_tests(ip):
 
 def check_celerity_connectivity(ip):
     print('Getting celerity server url.')
-    cmd = 'ssh -t %s cat /etc/celerity/config.py' % ip
+    cmd = 'ssh -t root@%s cat /etc/celerity/config.py' % ip
     print(cmd)
     try:
         d = subprocess.check_output(cmd, shell=True, timeout=5, universal_newlines=True)
@@ -76,7 +76,7 @@ def check_celerity_connectivity(ip):
         return False
     server_url = m.groups()[0].strip('"\' ')
     print('Checking celerity connectivity.')
-    cmd = 'ssh -t %s curl -k %s' % (ip, server_url)
+    cmd = 'ssh -t root@%s curl -k %s' % (ip, server_url)
     print(cmd)
     try:
         d = subprocess.check_output(cmd, shell=True, timeout=5, universal_newlines=True)
@@ -89,7 +89,26 @@ def check_celerity_connectivity(ip):
     return False
 
 
+def check_celerity_versions(ip):
+    print('Checking tha celerity server and worker uses the same version.')
+    cmd = 'diff -Naur <(dpkg -s celerity-utils) <(ssh -t root@%s dpkg -s celerity-utils)' % ip
+    print(cmd)
+    try:
+        out = subprocess.check_output(cmd, shell=True, timeout=5, universal_newlines=True)
+    except subprocess.CalledProcessError as e:
+        print('%sFailed to check celerity version in MediaWorker "%s":\n%s%s' % (RED, ip, e, DEF))
+        return False
+    out = out.strip()
+    if out:
+        print('%sThe celerity version in MediaWorker "%s" is not the same as in MediaServer:\n%s%s' % (RED, ip, out, DEF))
+        return False
+    print('%sThe celerity version in MediaWorker "%s" is the same as in MediaServer.%s' % (GREEN, ip, DEF))
+    return True
+
+
 def check_mediaworker_in_whitelist(ip):
+    # this check is not usefull anymore because the worker uses the
+    # API to get links to resources with valid secure link token
     nginx_vhosts_path = '/etc/nginx/sites-enabled'
     vhosts = os.listdir(nginx_vhosts_path)
     for v in vhosts:
@@ -116,10 +135,12 @@ for worker_ip in worker_ips.split(','):
         else:
             if not check_celerity_connectivity(worker_ip):
                 all_ok = False
+            if not check_celerity_versions(worker_ip):
+                all_ok = False
             # if not run_tests(worker_ip):
             #     all_ok = False
-            if not check_mediaworker_in_whitelist(worker_ip):
-                all_ok = False
+            # if not check_mediaworker_in_whitelist(worker_ip):
+            #     all_ok = False
 if not tested:
     print('Celerity IP not set or running locally, skipping test.')
     sys.exit(2)
-- 
GitLab