summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCorentin LABBE <clabbe@baylibre.com>2020-11-23 09:17:36 +0000
committerCorentin LABBE <clabbe@baylibre.com>2020-11-23 10:01:35 +0000
commita9c41d2882d4b63f201e43fde959f375bdc3c2ad (patch)
treeb0939c0df5b0ac05552820d65fbe166a020e70ee
parent13dcdb52eb69f3a022244e840e7d671375133702 (diff)
Handle 2020.09+ workers
Since 2020.09, workers does not use ZMQ anymore but use a token. This patch permit our setup to detecte when we use LAVA 2020.09+ and retrieve it from master.
-rw-r--r--lava-slave/scripts/getworkertoken.py15
-rwxr-xr-xlava-slave/scripts/setup.sh18
-rwxr-xr-xlavalab-gen.py2
3 files changed, 35 insertions, 0 deletions
diff --git a/lava-slave/scripts/getworkertoken.py b/lava-slave/scripts/getworkertoken.py
new file mode 100644
index 0000000..f538960
--- /dev/null
+++ b/lava-slave/scripts/getworkertoken.py
@@ -0,0 +1,15 @@
+#!/usr/bin/env python3
+
+import xmlrpc.client
+import sys
+
+if len(sys.argv) < 3:
+ print("ERROR: Usage: %s URI workername" % sys.argv[0])
+ sys.exit(1)
+
+server = xmlrpc.client.ServerProxy("%s" % sys.argv[1])
+wdet = server.scheduler.workers.show("%s" % sys.argv[2])
+if "token" in wdet:
+ print(wdet["token"])
+ sys.exit(0)
+sys.exit(1)
diff --git a/lava-slave/scripts/setup.sh b/lava-slave/scripts/setup.sh
index 58672c3..9873a91 100755
--- a/lava-slave/scripts/setup.sh
+++ b/lava-slave/scripts/setup.sh
@@ -68,6 +68,24 @@ do
else
echo "Adding worker $worker"
lavacli $LAVACLIOPTS workers add --description "LAVA dispatcher on $(cat /root/phyhostname)" $worker || exit $?
+ # does we ran 2020.09+ and worker need a token
+ fi
+ grep -q "TOKEN" /root/entrypoint.sh
+ if [ $? -eq 0 ];then
+ echo "DEBUG: Worker need a TOKEN"
+ # TODO use token from env
+ WTOKEN=$(getworkertoken.py $LAVA_MASTER_URI $worker)
+ if [ $? -eq 0 ];then
+ sed -i "s,.*TOKEN.*,TOKEN=\"--token $WTOKEN\"," /etc/lava-dispatcher/lava-worker || exit $?
+ else
+ echo "ERROR: cannot get WORKER TOKEN"
+ exit 1
+ fi
+ echo "DEBUG: set master URL to $LAVA_MASTER_URL"
+ sed -i "s,^# URL.*,URL=\"$LAVA_MASTER_URL\"," /etc/lava-dispatcher/lava-worker || exit $?
+ cat /etc/lava-dispatcher/lava-worker
+ else
+ echo "DEBUG: Worker does not need a TOKEN"
fi
if [ ! -z "$LAVA_DISPATCHER_IP" ];then
echo "Add dispatcher_ip $LAVA_DISPATCHER_IP to $worker"
diff --git a/lavalab-gen.py b/lavalab-gen.py
index d088bbb..e2e0607 100755
--- a/lavalab-gen.py
+++ b/lavalab-gen.py
@@ -546,7 +546,9 @@ def main():
else:
remote_proto = worker["remote_proto"]
remote_uri = "%s://%s:%s@%s:%s/RPC2" % (remote_proto, remote_user, remote_token, remote_address, remote_rpc_port)
+ remote_master_url = "%s://%s:%s" % (remote_proto, remote_address, remote_rpc_port)
dockcomp["services"][worker_name]["environment"]["LAVA_MASTER_URI"] = remote_uri
+ dockcomp["services"][worker_name]["environment"]["LAVA_MASTER_URL"] = remote_master_url
dockcomp["services"][worker_name]["environment"]["LAVA_MASTER_USER"] = remote_user
dockcomp["services"][worker_name]["environment"]["LAVA_MASTER_BASEURI"] = "%s://%s:%s/RPC2" % (remote_proto, remote_address, remote_rpc_port)
dockcomp["services"][worker_name]["environment"]["LAVA_MASTER_TOKEN"] = remote_token