Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

agent-spawner: base64 encoding one more time #156

Merged
merged 1 commit into from
Mar 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions resalloc_agent_spawner/dispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Agent spawner daemon. Part of the resalloc project.
"""

import base64
import sys
import logging
from copr_common.dispatcher import Dispatcher
Expand Down Expand Up @@ -84,7 +85,11 @@ def get_ticket_data(self, ticket_id):
if not ticket.collect():
# not yet resolved or failed
return None
return ticket.output

# The ticket.output is bytes(), and we don't plan to touch the data at
# all, we are just going to "forward" the data base64 encoded to our
# hook scripts. Encode it now, and never change again.
return base64.b64encode(ticket.output.data).decode("ascii")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need decode() here?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

b64encode returns bytes, yes


def try_to_stop(self, group_id, to_stop):
"""
Expand Down Expand Up @@ -174,10 +179,10 @@ def start_preparing(self):
resource that we can prepare (in the background). Switch the state.
"""
for ticket_id in self.get_tickets("NEW"):
ticket = self.resalloc.getTicket(ticket_id)
if not ticket.collect():
data = self.get_ticket_data(ticket_id)
if data is None:
continue
self.set_ticket_attribute(ticket_id, "data", ticket.output)
self.set_ticket_attribute(ticket_id, "data", data)
self.set_ticket_attribute(ticket_id, "state", "PREPARING")

def detect_failed_tickets(self):
Expand Down
6 changes: 3 additions & 3 deletions resalloc_agent_spawner/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
Handle certain tasks by a background daemon process.
"""

import base64

from copr_common.background_worker import BackgroundWorker

from resalloc_agent_spawner.helpers import (
Expand Down Expand Up @@ -37,7 +35,9 @@ 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"])

# dispatcher already converted data to b64-encoded strings
ticket_data = redis_dict["data"]

if redis_dict["state"] == "PREPARING":
if self.cmd_take(redis_dict["group_id"], ticket_data):
Expand Down
Loading