Skip to content

Commit

Permalink
exporter: guard against repeated resource requests
Browse files Browse the repository at this point in the history
Handle acquire/release calls for already acquired/released resources as
errors by raising an exception and providing the reason to the
coordinator. That also means that these calls will now return an error
to the coordinator.

Signed-off-by: Rouven Czerwinski <[email protected]>
  • Loading branch information
Emantor committed Jan 15, 2025
1 parent d0fd0bc commit 468ae7a
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions labgrid/remote/exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ class ExporterError(Exception):
class BrokenResourceError(ExporterError):
pass

class UnknownResourceError(ExporterError):
pass

class InvalidResourceRequestError(ExporterError):
pass

def log_subprocess_kernel_stack(logger, child):
if child.poll() is not None: # nothing to check if no longer running
Expand Down Expand Up @@ -889,7 +894,7 @@ async def message_pump(self):
out_message.set_acquired_request.resource_name,
)
success = True
except BrokenResourceError as e:
except BrokenResourceError, InvalidResourceRequestError, UnknownResourceError as e:
reason = e.args[0]
finally:
in_message = labgrid_coordinator_pb2.ExporterInMessage()
Expand Down Expand Up @@ -924,8 +929,10 @@ async def message_pump(self):
async def acquire(self, group_name, resource_name, place_name):
resource = self.groups.get(group_name, {}).get(resource_name)
if resource is None:
logging.error("acquire request for unknown resource %s/%s by %s", group_name, resource_name, place_name)
return
raise UnknownResourceError(f"acquire request for unknown resource {group_name}/{resource_name} by {place_name}")

if resource.acquired:
raise InvalidResourceRequestError(f"Resource {group_name}/{resource_name} is already acquired by {resource.acquired}")

try:
resource.acquire(place_name)
Expand All @@ -935,8 +942,11 @@ async def acquire(self, group_name, resource_name, place_name):
async def release(self, group_name, resource_name):
resource = self.groups.get(group_name, {}).get(resource_name)
if resource is None:
logging.error("release request for unknown resource %s/%s", group_name, resource_name)
return
logging.error()
raise UnknownResourceError(f"release request for unknown resource {group_name}/{resource_name}")

if not resource.acquired:
raise InvalidResourceRequestError(f"Resource {group_name}/{resource_name} is not acquired")

try:
resource.release()
Expand Down

0 comments on commit 468ae7a

Please sign in to comment.