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

Allow multiple IP for worker (refs #20799).

parent ad951308
No related branches found
No related tags found
No related merge requests found
......@@ -48,8 +48,14 @@ def setup(interactive=True):
if os.path.exists('/home/msuser/msinstance'):
need_uwsgi = True
server_name = utils.get_conf('MS_SERVER_NAME') or 'mediaserver'
worker_ips = utils.get_conf('CELERITY_WORKER_IP') or '127.0.1.1'
whitelist = ''
for worker_ip in worker_ips.split(','):
worker_ip = worker_ip.strip()
if worker_ip:
whitelist += '\n\t%s 1;' % worker_ip
cmds.extend(vhost_write_cmds(dir_path, 'mediaserver-msuser', server_name,
secret=utils.get_conf('MS_SECRET') or 'secret', worker_ip=utils.get_conf('CELERITY_WORKER_IP') or '127.0.1.1'))
secret=utils.get_conf('MS_SECRET') or 'secret', whitelist=whitelist))
hosts.append(server_name)
# Monitor vhost
if os.path.exists('/home/msmonitor/msmonitor'):
......
geo $msuser_whitelist {
default 0;
127.0.0.1 1;
{{ worker_ip }} 1;
127.0.0.1 1;{{ whitelist }}
}
map $msuser_whitelist $msuser_allowed {
0 $secure_link;
......
......@@ -34,13 +34,3 @@ if [ "${MS_SECRET}" = "secret" ]; then
fi
echo "The config MS_SECRET has been set."
fi
# Worker IP for whitelist
if [ "${CELERITY_WORKER_IP}" = "" ] || [ "${CELERITY_WORKER_IP}" = "127.0.1.1" ]; then
CELERITY_WORKER_IP=$(ip addr show | grep inet | grep -v 127 | grep -v ":" | awk -F " " '{print$2}' | awk -F "/" '{print$1}')
if ( cat "/root/envsetup/conf.sh" | grep "CELERITY_WORKER_IP" >/dev/null ); then
sed -i "s@^CELERITY_WORKER_IP=.*@CELERITY_WORKER_IP='${CELERITY_WORKER_IP}'@" /root/envsetup/conf.sh
else
echo "CELERITY_WORKER_IP='${CELERITY_WORKER_IP}'" >> /root/envsetup/conf.sh
fi
echo "The config CELERITY_WORKER_IP has been set."
fi
......@@ -73,6 +73,7 @@ MYSQL_CONTACT_IP=
# -- Celerity --
CELERITY_SIGNING_KEY='test'
# worker IP adresses, use commas to separate values
CELERITY_WORKER_IP='127.0.1.1'
# -- Network configuration --
......
......@@ -17,15 +17,15 @@ DEF = '\033[0m'
try:
import mediaserver
except ImportError:
print('MediaServer is not installed, skipping test')
print('MediaServer is not installed, skipping test.')
sys.exit(2)
else:
print('MediaServer version: %s' % mediaserver.__version__)
print('MediaServer version: %s.' % mediaserver.__version__)
os.chdir(os.path.dirname(__file__))
if not os.path.isfile('../utils.py'):
print('conf.sh not found')
print('conf.sh not found.')
sys.exit(1)
es_utils = imp.load_source('es_utils', '../utils.py')
......@@ -34,60 +34,64 @@ conf = es_utils.load_conf()
def check_ssh(ip):
cmd = 'ssh -o StrictHostKeyChecking=no -o PasswordAuthentication=no %s ls /tmp' % ip
print('Connecting to MediaWorker: %s' % cmd)
print('Connecting to MediaWorker:\n%s' % cmd)
try:
subprocess.check_output(cmd, shell=True, timeout=2)
print('%sLogged in successfully%s' % (GREEN, DEF))
print('%sLogged in successfully in "%s".%s' % (GREEN, ip, DEF))
except subprocess.CalledProcessError:
print('%sFailed to login using SSH, run ssh-copy-id %s %s' % (RED, ip, DEF))
print('%sFailed to login using SSH, run "ssh-copy-id %s".%s' % (RED, ip, DEF))
return False
return True
def run_tests(ip):
print('Updating envsetup tests on MediaWorker')
print('Updating envsetup tests on MediaWorker.')
cmd = 'ssh -t %s cd /root/envsetup && git pull' % ip
os.system(cmd)
print('Running envsetup tests on MediaWorker')
print('Running envsetup tests on MediaWorker.')
cmd = 'ssh -t %s /root/envsetup/tester.py' % ip
status = os.system(cmd)
if status == 0:
subprocess.check_output(cmd, shell=True, timeout=60)
print('%sAll tests completed on MediaWorker%s' % (GREEN, DEF))
print('%sAll tests completed on MediaWorker "%s".' % (GREEN, ip, DEF))
return True
else:
print('%apt-get update failed on MediaWorker%s' % (RED, DEF))
print('%apt-get update failed on MediaWorker "%s".%s' % (RED, ip, DEF))
return False
def check_celerity_connectivity(ip):
h = conf.get('MS_SERVER_NAME')
cmd = "ssh %s curl -k https://%s:6200" % (ip, h)
cmd = 'ssh %s curl -k https://%s:6200' % (ip, h)
print('Checking celerity connectivity: %s' % cmd)
try:
d = subprocess.check_output(cmd, shell=True, timeout=5, universal_newlines=True)
except subprocess.CalledProcessError:
d = ''
if "Celerity tasks server" in d:
print('%sSuccessfully reached tasks server%s' % (GREEN, DEF))
if 'Celerity tasks server' in d:
print('%sSuccessfully reached tasks server from MediaWorker "%s".%s' % (GREEN, ip, DEF))
return True
print('%sMediaWorker %s failed to reach tasks server%s' % (RED, ip, DEF))
print('%sFailed to reach tasks server from MediaWorker "%s".%s' % (RED, ip, DEF))
return False
all_ok = True
all_ok = True
tested = False
mediaserver_ip = conf.get('NETWORK_IP')
worker_ip = conf.get('CELERITY_WORKER_IP')
if worker_ip != '127.0.1.1' and worker_ip != mediaserver_ip:
if not check_ssh(worker_ip):
all_ok = False
else:
if not check_celerity_connectivity(worker_ip):
worker_ips = conf.get('CELERITY_WORKER_IP')
for worker_ip in worker_ips.split(','):
worker_ip = worker_ip.strip()
if worker_ip and worker_ip != '127.0.1.1' and worker_ip != mediaserver_ip:
tested = True
if not check_ssh(worker_ip):
all_ok = False
if not run_tests(worker_ip):
all_ok = False
else:
print('Celerity IP not set or running locally, skipping test')
else:
if not check_celerity_connectivity(worker_ip):
all_ok = False
if not run_tests(worker_ip):
all_ok = False
if not tested:
print('Celerity IP not set or running locally, skipping test.')
sys.exit(2)
sys.exit(int(not all_ok))
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment