-
Notifications
You must be signed in to change notification settings - Fork 24
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
add jobs support #95
add jobs support #95
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
from shakedown.dcos import spinner | ||
import time | ||
import urllib | ||
from dcos import config, errors, http | ||
|
||
|
||
def post_job(job): | ||
return http.post(_metronome_url('v1/jobs'), json=job) | ||
|
||
|
||
def get_job(job_id, history=True): | ||
url = 'v1/jobs/{}'.format(job_id) | ||
if history: | ||
url = url + '?embed=history' | ||
return http.get(_metronome_url(url)) | ||
|
||
|
||
def post_run(job_id): | ||
return http.post(_metronome_url('v1/jobs/{}/runs').format(job_id)) | ||
|
||
|
||
def get_run(job_id, run_id): | ||
return http.get(_metronome_url('v1/jobs/{}/runs/{}').format(job_id, run_id)) | ||
|
||
|
||
def run_job(job_spec, wait=True, assertSuccess=True, timeout_seconds=120): | ||
job_id = post_job(job_spec).json()['id'] | ||
run_id = post_run(job_id).json()['id'] | ||
if wait: | ||
wait_for_run(job_id, run_id, timeout_seconds=timeout_seconds) | ||
if assertSuccess: | ||
job = get_job(job_id).json() | ||
assert(len(job['history']['successfulFinishedRuns']) > 0) | ||
return job_id | ||
|
||
|
||
def wait_for_run(job_id, run_id, timeout_seconds=120): | ||
def run_finished(): | ||
try: | ||
response = get_run(job_id, run_id) | ||
except errors.DCOSHTTPException as ex: | ||
if ex.response.status_code == 404: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there somewhere that has a list of these constants? Also, I've seen a bunch of tests fail flakily due to occasional 404s returned lately. Are you sure you want to fail on 404? What if something like 502 is returned forever, does this just run forever? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, I believe there's already a generic spin implementation somewhere in shakedown. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Generic spinner: |
||
return True | ||
else: | ||
raise ex | ||
return False | ||
spinner.wait_for( | ||
run_finished, | ||
ignore_exceptions=False, | ||
timeout_seconds=timeout_seconds) | ||
|
||
|
||
def _metronome_url(url): | ||
dcos_url = config.get_config_val('core.dcos_url') | ||
return urllib.parse.urljoin( | ||
urllib.parse.urljoin(dcos_url, 'service/metronome/'), | ||
url) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know Python's style rules. Should there be another newline here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added