From fddb70443857c072e748ed5c9511743aa5b28772 Mon Sep 17 00:00:00 2001 From: Pavel Raiskup Date: Tue, 27 Feb 2024 08:35:27 +0100 Subject: [PATCH] agent-spawner: base64 encode the resalloc ticket DATA in env Fixes: #144 --- config/agent-spawner/config.yaml | 10 ++++++---- resalloc_agent_spawner/worker.py | 8 ++++++-- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/config/agent-spawner/config.yaml b/config/agent-spawner/config.yaml index 139b183..c59de65 100644 --- a/config/agent-spawner/config.yaml +++ b/config/agent-spawner/config.yaml @@ -9,12 +9,14 @@ # # agent immediately marked for removal. `cmd_terminate` exit status is # # just ignored (we need to remove the agent no matter what). # -# # Prepare the agent. Variable $RESALLOC_RESOURCE_DATA (base64 encoded) -# # is provided in the script environment. Other variables like -# # RESOURCE_NAME, RESOURCE_POOL_ID, etc. are provided as well. +# # Prepare the agent. Variable $AGENT_SPAWNER_RESOURCE_DATA (base64 +# # encoded, output from `resalloc ticket-wait`) is provided in the script +# # environment. # cmd_prepare: /bin/true +# # # Prepare the agent for termination. Upon finishing this command, the -# # resalloc resource ticket is closed and the resource deallocated. +# # resalloc resource ticket is closed and the resource deallocated (the +# # $AGENT_SPAWNER_RESOURCE_DATA env var is provided as well). # cmd_terminate: echo noop # # # The following commands are executed synchronously by the agent spawner diff --git a/resalloc_agent_spawner/worker.py b/resalloc_agent_spawner/worker.py index 7909a21..3ed9c8d 100644 --- a/resalloc_agent_spawner/worker.py +++ b/resalloc_agent_spawner/worker.py @@ -2,6 +2,8 @@ Handle certain tasks by a background daemon process. """ +import base64 + from copr_common.background_worker import BackgroundWorker from resalloc_agent_spawner.helpers import ( @@ -35,8 +37,10 @@ def handle_ticket(self, ticket_id): # We know there's self._redis initialized by parent class so we don't # create yet another connection. redis_dict = self._redis.hgetall(redis_key) + ticket_data = base64.b64encode(redis_dict["data"]) + if redis_dict["state"] == "PREPARING": - if self.cmd_take(redis_dict["group_id"], redis_dict["data"]): + if self.cmd_take(redis_dict["group_id"], ticket_data): self._redis.hset(redis_key, "state", "WORKING") else: # failed preparation -> prepare removal @@ -44,7 +48,7 @@ def handle_ticket(self, ticket_id): return if redis_dict["state"] == "TERMINATING": - self.cmd_terminate(redis_dict["group_id"], redis_dict["data"]) + self.cmd_terminate(redis_dict["group_id"], ticket_data) self._redis.hset(redis_key, "state", "ENDED") def handle_task(self):