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

Feature: get and assign sandbox to job #156

Merged
merged 2 commits into from
Apr 10, 2024

Conversation

natthan-pigoux
Copy link
Contributor

@natthan-pigoux natthan-pigoux commented Oct 20, 2023

The features have been started but not finished yet.
TBF:

  • : parse the query result to fit routes expectation
  • : then finish "get" routes
  • : write the test

@natthan-pigoux natthan-pigoux marked this pull request as draft October 20, 2023 02:45
@natthan-pigoux
Copy link
Contributor Author

Hello @chrisburr, I have moved on for the "assign" and "get" routes. But the test return a 404 not found while calling these routes and I did'nt found why... Do you have an idea on this?
Thank you!

@chaen
Copy link
Contributor

chaen commented Nov 9, 2023

Hi @natthan-pigoux ,
General guideline:

You can run the test locally with the --pdb option
pytest --pdb -k test_assign_sandbox_to_job
You will then end up in a prompt that allows you to debug.

A naive guess would be that the job id does not exist

@router.patch("/jobs/{job_id}/sandbox/output")
async def assign_sandbox(
job_id: int,
pfn: Annotated[str, Query(max_length=256, pattern=SANDBOX_PFN_REGEX)],
Copy link
Contributor

Choose a reason for hiding this comment

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

I think the 404 problem comes from here. the pfn is not in the query but in the body

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks @chaen , I simply try that: c968b65
I've tried the Pydantic syntax as well, but it doesn't solve the issue... I also checked that the job and the sandbox are created in the test and it seems to be the case.

Copy link
Contributor

Choose a reason for hiding this comment

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

if you declare pfn as an str, then you need to do your test like

r = normal_user_client.patch(
        f"/api/jobs/{job_id}/sandbox/output",
        json=sandbox_pfn,
)

(although probably the Pydantic model approach is better).
But this would result in 422, not 404

try to replace

    assert r.status_code == 200

with

    assert r.status_code == 200, r.json()

so you get to see the actual error.

If after that you still can't figure out, I'll checkout your branch and try on my machine :-)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I modified the sandbox_pfn declaration. I've investigated but I didn't find any obvious solution. Could be helpful if you can have a look :)

Copy link
Contributor

Choose a reason for hiding this comment

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

OK so the problem was a bit more subtle :-)
You declare your routes like this for example

@router.get("/jobs/{job_id}/sandbox")

However, the /jobs prefix is already automatically prepended when creating the job router (this comes from that, and yes, that is part of the missing docs :-) )

jobs = diracx.routers.job_manager:router

So the way you need to declare your routes is not `/jobs/{job_id}/sandbox" but just "/{job_id}/sandbox"

Effectively, your route is available as "/jobs/jobs/{job_id}/sandbox"

So changing the route definition fixes the problem you have, but you bump then into another one, which I let in your care :-)

Copy link
Contributor Author

@natthan-pigoux natthan-pigoux Nov 20, 2023

Choose a reason for hiding this comment

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

Thanks a lot @chaen!
Indeed I could see that when looking other sandbox routes... I also fixed the pfn parameter by splitting it inside the assign_sandbox route. Is that the right way to do it ?
Otherwise the tests finally passed, the PR should be ready for review.

@natthan-pigoux natthan-pigoux marked this pull request as ready for review November 20, 2023 14:05
@chaen
Copy link
Contributor

chaen commented Nov 28, 2023

@natthan-pigoux thanks ! I'll just rebase it to pick up the latest changes :-)

@chaen chaen force-pushed the np-sanbox-assign branch 2 times, most recently from 51b2b04 to 9dce245 Compare November 30, 2023 16:57
@chaen chaen force-pushed the np-sanbox-assign branch from 9dce245 to 363ae5b Compare March 14, 2024 13:10
@chaen
Copy link
Contributor

chaen commented Mar 15, 2024

@natthan-pigoux thanks a lot for the PR. There are a few TODO's left, in particular for identity check. Do you have time or should I finish it ? :-)

@natthan-pigoux
Copy link
Contributor Author

natthan-pigoux commented Mar 15, 2024

Hi @chaen, for the todo list, are you talking about what's left in #13 or the TODOs I left in the code (such as: f04166a#diff-c24591c47e0251c9014801ea7df92eb36ff4d01a77c47d6a48a7c37e7c682f98R219) ?
Yes I have time to finish the work :)

@chaen
Copy link
Contributor

chaen commented Mar 15, 2024

The TODO in the code :-) Once these are adressed, I merge it and if you will, you can continue with the rest of #13 :-)

@natthan-pigoux
Copy link
Contributor Author

@chaen, one of the todo is check that user has created the job or is admin , Can I assume the router definition: router = DiracxRouter(dependencies=[has_properties(NORMAL_USER | JOB_ADMINISTRATOR)]) gives the needed rights ?
I'm not sure what is the perimeter of NORMAL_USER

@natthan-pigoux natthan-pigoux force-pushed the np-sanbox-assign branch 2 times, most recently from 7e71c90 to 7eb19d1 Compare April 2, 2024 14:37
@natthan-pigoux
Copy link
Contributor Author

@chaen, I added the method to unassign sandbox and added the concept of "entity" which was not implemented.
Still, I don't know how to manage the policy on sandbox, I suppose it is the same as for jobs. But it doesn't look like it is implemented for job right now.
Should I leave it as TODO for now?

@chaen
Copy link
Contributor

chaen commented Apr 3, 2024

yes, we are working on the policy at the moment, so don't bother with it :-)
Is the rest of the PR finished ?

@chaen chaen merged commit 97200df into DIRACGrid:main Apr 10, 2024
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants