Skip to content

Commit

Permalink
feat: (temporary, 4, change logging format) Restructured pilot logger…
Browse files Browse the repository at this point in the history
… + new broken test
  • Loading branch information
martynia committed Jan 16, 2025
1 parent 25b1409 commit ad2699d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
15 changes: 10 additions & 5 deletions diracx-routers/src/diracx/routers/pilots/access_policies.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@
class ActionType(StrEnum):
#: Create/update pilot log records
CREATE = auto()
#: delete pilot logs
DELETE = auto()
#: Search
QUERY = auto()

Expand All @@ -49,18 +47,25 @@ async def policy(
status.HTTP_400_BAD_REQUEST, detail="Action is a mandatory argument"
)
elif action == ActionType.QUERY:
assert pilot_id
if pilot_id is None:
logger.error("Pilot ID value is not provided (None)")
raise HTTPException(
status.HTTP_400_BAD_REQUEST,
detail=f"PilotID not provided: {pilot_id}",
)
search_params = ScalarSearchSpec(
parameter="PilotID",
operator=ScalarSearchOperator.EQUAL,
value=pilot_id,
)

total, result = await pilot_agents_db.search(["VO"], [search_params], [])
print("Total: ", total, "Result: ", result)
# we expect exactly one row.
if total != 1:
logger.error(
f"Cannot determine VO for requested PilotID: {pilot_id}, Error #rows !=1: {total}."
"Cannot determine VO for requested PilotID: %d, found %d candidates.",
pilot_id,
total,
)
raise HTTPException(
status.HTTP_400_BAD_REQUEST, detail=f"PilotID not found: {pilot_id}"
Expand Down
4 changes: 3 additions & 1 deletion diracx-routers/src/diracx/routers/pilots/logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ async def send_message(
)
if total != 1:
logger.error(
f"Cannot determine PilotID for requested PilotStamp: {data.pilot_stamp}, Error #rows !=1: {total}."
"Cannot determine PilotID for requested PilotStamp: %r, (%r candidates)",
data.pilot_stamp,
total,
)
raise HTTPException(
status.HTTP_400_BAD_REQUEST, detail=f"Number of rows !=1: {total}"
Expand Down

0 comments on commit ad2699d

Please sign in to comment.