This repository was archived by the owner on Mar 13, 2023. It is now read-only.
generated from amazon-archives/__template_Apache-2.0
-
Notifications
You must be signed in to change notification settings - Fork 27
Add manual script entry as a new job submission option #235
Merged
mtfranchetto
merged 4 commits into
aws-samples:job-submission-manual-script-entry
from
rkilpadi:frontend
Aug 24, 2022
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
912fd80
Add JobField component to simplify JobSubmitDialog
rkilpadi 2bfbd43
Add new endpoint for submitting jobs through Slurm API
rkilpadi d10c21b
Add UI option for script entry through Slurm API
rkilpadi 330467d
Add tests for submit_job_script endpoint
rkilpadi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| import json | ||
| from unittest import mock | ||
| from requests import Response | ||
| from api.PclusterApiHandler import post_job_slurm_api, translate_job | ||
|
|
||
|
|
||
| @mock.patch("api.PclusterApiHandler.requests.post") | ||
| def test_post_to_slurm_api_with_correct_request(mock_post): | ||
| """ | ||
| Given a function that posts jobs to the Slurm API | ||
| When a job body, user, token, and ip are inputted | ||
| It should call request.post with the correct url, data, and headers | ||
| """ | ||
| post_job_slurm_api( | ||
| {'job-name': 'test'}, | ||
| 'test-user', 'slurm-token123', '123.456.7.8' | ||
| ) | ||
|
|
||
| mock_post.assert_called_once_with( | ||
| url='https://123.456.7.8/slurm/v0.0.36/job/submit', | ||
| data=json.dumps({ | ||
| "job": { | ||
| "environment": { | ||
| "PATH": "/bin:/usr/bin/:/usr/local/bin/:/opt/slurm/bin/" | ||
| }, | ||
| "name": "test", | ||
| "current_working_directory": "/home/test-user" | ||
| } | ||
| }), | ||
| headers={ | ||
| 'Content-Type': 'application/json', | ||
| 'X-SLURM-USER-NAME': 'test-user', | ||
| 'X-SLURM-USER-TOKEN': 'slurm-token123' | ||
| }, | ||
| verify=False | ||
| ) | ||
|
|
||
|
|
||
| @mock.patch("api.PclusterApiHandler.requests.post") | ||
| def test_post_to_slurm_api_returns_errors(mock_post): | ||
| """ | ||
| Given a function that posts jobs to the Slurm API | ||
| When the response contains errors | ||
| It should return the error messages separated by new lines | ||
| """ | ||
| resp = Response() | ||
| resp.status_code = 400 | ||
| resp.reason = 'BAD REQUEST' | ||
| resp._content = b'{"errors": [ \ | ||
| {"error": "test", "error_code": -1}, \ | ||
| {"error": "testing", "error_code": 9001}]}' | ||
|
|
||
| mock_post.return_value = resp | ||
|
|
||
| ret = post_job_slurm_api( | ||
| {'job-name': 'test'}, | ||
| 'test-user', 'slurm-token123', '123.456.7.8' | ||
| ) | ||
|
|
||
| assert ret.get('errors') == 'test\ntesting' | ||
| assert ret.get('status_code') == 400 | ||
| assert ret.get('reason') == 'BAD REQUEST' | ||
|
|
||
|
|
||
| def test_translate_job(): | ||
| """ | ||
| Given a function that translates a job | ||
| When a dict of job data is inputted | ||
| It should format the job to be accepted by the Slurm API | ||
| """ | ||
| request_body = {'job-name': 'test', 'nodes': 1, 'command': 'test command'} | ||
|
|
||
| translation = translate_job(request_body, 'test-user') | ||
|
|
||
| assert translation == { | ||
| "job": { | ||
| "name": "test", | ||
| "current_working_directory": "/home/test-user", | ||
| "nodes": 1, | ||
| "environment": { | ||
| "PATH": "/bin:/usr/bin/:/usr/local/bin/:/opt/slurm/bin/" | ||
| } | ||
| }, | ||
| "script": 'test command' | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.