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): ...@@ -48,8 +48,14 @@ def setup(interactive=True):
if os.path.exists('/home/msuser/msinstance'): if os.path.exists('/home/msuser/msinstance'):
need_uwsgi = True need_uwsgi = True
server_name = utils.get_conf('MS_SERVER_NAME') or 'mediaserver' 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, 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) hosts.append(server_name)
# Monitor vhost # Monitor vhost
if os.path.exists('/home/msmonitor/msmonitor'): if os.path.exists('/home/msmonitor/msmonitor'):
......
geo $msuser_whitelist { geo $msuser_whitelist {
default 0; default 0;
127.0.0.1 1; 127.0.0.1 1;{{ whitelist }}
{{ worker_ip }} 1;
} }
map $msuser_whitelist $msuser_allowed { map $msuser_whitelist $msuser_allowed {
0 $secure_link; 0 $secure_link;
......
...@@ -34,13 +34,3 @@ if [ "${MS_SECRET}" = "secret" ]; then ...@@ -34,13 +34,3 @@ if [ "${MS_SECRET}" = "secret" ]; then
fi fi
echo "The config MS_SECRET has been set." echo "The config MS_SECRET has been set."
fi 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= ...@@ -73,6 +73,7 @@ MYSQL_CONTACT_IP=
# -- Celerity -- # -- Celerity --
CELERITY_SIGNING_KEY='test' CELERITY_SIGNING_KEY='test'
# worker IP adresses, use commas to separate values
CELERITY_WORKER_IP='127.0.1.1' CELERITY_WORKER_IP='127.0.1.1'
# -- Network configuration -- # -- Network configuration --
......
...@@ -17,15 +17,15 @@ DEF = '\033[0m' ...@@ -17,15 +17,15 @@ DEF = '\033[0m'
try: try:
import mediaserver import mediaserver
except ImportError: except ImportError:
print('MediaServer is not installed, skipping test') print('MediaServer is not installed, skipping test.')
sys.exit(2) sys.exit(2)
else: else:
print('MediaServer version: %s' % mediaserver.__version__) print('MediaServer version: %s.' % mediaserver.__version__)
os.chdir(os.path.dirname(__file__)) os.chdir(os.path.dirname(__file__))
if not os.path.isfile('../utils.py'): if not os.path.isfile('../utils.py'):
print('conf.sh not found') print('conf.sh not found.')
sys.exit(1) sys.exit(1)
es_utils = imp.load_source('es_utils', '../utils.py') es_utils = imp.load_source('es_utils', '../utils.py')
...@@ -34,60 +34,64 @@ conf = es_utils.load_conf() ...@@ -34,60 +34,64 @@ conf = es_utils.load_conf()
def check_ssh(ip): def check_ssh(ip):
cmd = 'ssh -o StrictHostKeyChecking=no -o PasswordAuthentication=no %s ls /tmp' % 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: try:
subprocess.check_output(cmd, shell=True, timeout=2) 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: 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 False
return True return True
def run_tests(ip): 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 cmd = 'ssh -t %s cd /root/envsetup && git pull' % ip
os.system(cmd) os.system(cmd)
print('Running envsetup tests on MediaWorker') print('Running envsetup tests on MediaWorker.')
cmd = 'ssh -t %s /root/envsetup/tester.py' % ip cmd = 'ssh -t %s /root/envsetup/tester.py' % ip
status = os.system(cmd) status = os.system(cmd)
if status == 0: if status == 0:
subprocess.check_output(cmd, shell=True, timeout=60) 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 return True
else: 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 return False
def check_celerity_connectivity(ip): def check_celerity_connectivity(ip):
h = conf.get('MS_SERVER_NAME') 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) print('Checking celerity connectivity: %s' % cmd)
try: try:
d = subprocess.check_output(cmd, shell=True, timeout=5, universal_newlines=True) d = subprocess.check_output(cmd, shell=True, timeout=5, universal_newlines=True)
except subprocess.CalledProcessError: except subprocess.CalledProcessError:
d = '' d = ''
if "Celerity tasks server" in d: if 'Celerity tasks server' in d:
print('%sSuccessfully reached tasks server%s' % (GREEN, DEF)) print('%sSuccessfully reached tasks server from MediaWorker "%s".%s' % (GREEN, ip, DEF))
return True 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 return False
all_ok = True
all_ok = True
tested = False
mediaserver_ip = conf.get('NETWORK_IP') mediaserver_ip = conf.get('NETWORK_IP')
worker_ip = conf.get('CELERITY_WORKER_IP') worker_ips = conf.get('CELERITY_WORKER_IP')
if worker_ip != '127.0.1.1' and worker_ip != mediaserver_ip: for worker_ip in worker_ips.split(','):
if not check_ssh(worker_ip): worker_ip = worker_ip.strip()
all_ok = False if worker_ip and worker_ip != '127.0.1.1' and worker_ip != mediaserver_ip:
else: tested = True
if not check_celerity_connectivity(worker_ip): if not check_ssh(worker_ip):
all_ok = False all_ok = False
if not run_tests(worker_ip): else:
all_ok = False if not check_celerity_connectivity(worker_ip):
else: all_ok = False
print('Celerity IP not set or running locally, skipping test') 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(2)
sys.exit(int(not all_ok)) 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