jobs: do not expose 404 errors (#764)

This commit is contained in:
Ken Sipe
2016-10-10 12:58:03 -05:00
committed by tamarrow
parent 2dfa7a5350
commit f372c87316
2 changed files with 50 additions and 2 deletions

View File

@@ -344,8 +344,11 @@ def _show(job_id):
try:
response = _do_request("{}/{}".format(
_get_api_url('v1/jobs'), job_id), 'GET')
except DCOSException as e:
raise DCOSException(e)
except DCOSHTTPException as e:
if e.response.status_code == 404:
raise DCOSException("Job ID: '{}' does NOT exist.".format(job_id))
else:
raise DCOSException(e)
json_job = _read_http_response_body(response)
emitter.publish(json_job)
@@ -447,6 +450,11 @@ def _show_schedule(job_id, json_flag=False):
url = "{}/{}/schedules".format(_get_api_url('v1/jobs'), job_id)
try:
response = _do_request(url, 'GET')
except DCOSHTTPException as e:
if e.response.status_code == 404:
raise DCOSException("Job ID: '{}' does NOT exist.".format(job_id))
else:
raise DCOSException(e)
except DCOSException as e:
raise DCOSException(e)

View File

@@ -87,6 +87,46 @@ def test_show_job():
show_job('pikachu')
def test_show_job_with_blank_jobname():
returncode, stdout, stderr = exec_command(
['dcos', 'job', 'show'])
assert returncode == 1
assert "Command not recognized" in stdout.decode('utf-8')
def test_show_job_with_invalid_jobname():
assert_command(
['dcos', 'job', 'show', 'invalid'],
stdout=b'',
stderr=b"Job ID: 'invalid' does NOT exist.\n",
returncode=1)
def test_show_job_runs_blank_jobname():
assert_command(
['dcos', 'job', 'show', 'runs'],
stdout=b'',
stderr=b"Job ID: 'runs' does NOT exist.\n",
returncode=1)
def test_show_schedule_blank_jobname():
returncode, stdout, stderr = exec_command(
['dcos', 'job', 'schedule', 'show'])
assert returncode == 1
assert stdout.decode('utf-8').startswith('Command not recognized')
def test_show_schedule_invalid_jobname():
assert_command(
['dcos', 'job', 'schedule', 'show', 'invalid'],
stdout=b'',
stderr=b"Job ID: 'invalid' does NOT exist.\n",
returncode=1)
def test_remove_job():
with _no_schedule_instance_job():
pass