zuul-web: jobs list endpoint: Add test and fix tenant not found 500 error

Job lists test was missing so this add a minimal one and
also fix the 500 errors return when the tenant does not
exist.

Change-Id: Ifa161a0c6ac801ced0d55dd48d1d5f83833aeea4
This commit is contained in:
Fabien Boucher 2018-07-12 17:04:01 +02:00
parent 19afda37a3
commit 0ecccbc349
3 changed files with 11 additions and 0 deletions

View File

@ -271,6 +271,13 @@ class TestWeb(BaseTestWeb):
resp = self.get_url("api/tenant/non-tenant/status")
self.assertEqual(404, resp.status_code)
def test_jobs_list(self):
jobs = self.get_url("api/tenant/tenant-one/jobs").json()
self.assertEqual(len(jobs), 8)
resp = self.get_url("api/tenant/non-tenant/jobs")
self.assertEqual(404, resp.status_code)
class TestInfo(BaseTestWeb):

View File

@ -341,6 +341,8 @@ class RPCListener(object):
args = json.loads(job.arguments)
tenant = self.sched.abide.tenants.get(args.get("tenant"))
output = []
if not tenant:
job.sendWorkComplete(json.dumps(None))
for job_name in sorted(tenant.layout.jobs):
desc = None
for tenant_job in tenant.layout.jobs[job_name]:

View File

@ -269,6 +269,8 @@ class ZuulWebAPI(object):
def jobs(self, tenant):
job = self.rpc.submitJob('zuul:job_list', {'tenant': tenant})
ret = json.loads(job.data[0])
if ret is None:
raise cherrypy.HTTPError(404, 'Tenant %s does not exist.' % tenant)
resp = cherrypy.response
resp.headers['Access-Control-Allow-Origin'] = '*'
return ret