Use abide for listing tenants in zuul-web

This uses the abide in zuul-web to directly access the tenant list
instead of asking the scheduler via RPC.

Relevant RPC listener methods are removed as they are not used
anywhere else.

Change-Id: I918cc3b9b8a6e0ba95a24dc55bf06976c6e2cfb5
This commit is contained in:
Felix Edel 2021-11-09 10:23:49 +01:00
parent 9606c07cab
commit b2d7d0b1c2
3 changed files with 19 additions and 26 deletions

View File

@ -87,7 +87,6 @@ class BaseTestWeb(ZuulTestCase):
self.waitUntilSettled()
def get_url(self, url, *args, **kwargs):
zuul.web.ZuulWebAPI._tenants.cache_clear()
return requests.get(
urllib.parse.urljoin(self.base_url, url), *args, **kwargs)

View File

@ -141,7 +141,6 @@ class RPCListener(RPCListenerBase):
'autohold_info',
'autohold_list',
'get_running_jobs',
'tenant_list',
]
def start(self):
@ -237,18 +236,3 @@ class RPCListener(RPCListenerBase):
running_items.append(item.formatJSON())
job.sendWorkComplete(json.dumps(running_items))
def handle_tenant_list(self, job):
output = []
for tenant_name, tenant in sorted(self.sched.abide.tenants.items()):
queue_size = 0
for pipeline_name, pipeline in tenant.layout.pipelines.items():
for queue in pipeline.queues:
for item in queue.queue:
if item.live:
queue_size += 1
output.append({'name': tenant_name,
'projects': len(tenant.untrusted_projects),
'queue': queue_size})
job.sendWorkComplete(json.dumps(output))

View File

@ -17,7 +17,6 @@ import socket
from collections import defaultdict
from contextlib import suppress
from cachetools.func import ttl_cache
from ws4py.server.cherrypyserver import WebSocketPlugin, WebSocketTool
from ws4py.websocket import WebSocket
import codecs
@ -901,18 +900,29 @@ class ZuulWebAPI(object):
return [n for n, t in self.zuulweb.abide.tenants.items()
if self._is_authorized(t, claims)]
@ttl_cache(ttl=60)
def _tenants(self):
job = self.rpc.submitJob('zuul:tenant_list', {})
return json.loads(job.data[0])
@cherrypy.expose
@cherrypy.tools.json_out(content_type='application/json; charset=utf-8')
def tenants(self):
ret = self._tenants()
result = []
for tenant_name, tenant in sorted(self.zuulweb.abide.tenants.items()):
queue_size = 0
for pipeline in tenant.layout.pipelines.values():
status = pipeline.summary.refresh(self.zuulweb.zk_context)
for queue in status["change_queues"]:
for head in queue["heads"]:
for item in head:
if item["live"]:
queue_size += 1
result.append({
'name': tenant_name,
'projects': len(tenant.untrusted_projects),
'queue': queue_size,
})
resp = cherrypy.response
resp.headers['Access-Control-Allow-Origin'] = '*'
return ret
return result
@cherrypy.expose
@cherrypy.tools.json_out(content_type='application/json; charset=utf-8')
@ -1326,7 +1336,7 @@ class ZuulWebAPI(object):
limit=50, skip=0):
connection = self._get_connection()
if tenant not in [x['name'] for x in self._tenants()]:
if tenant not in self.zuulweb.abide.tenants.keys():
raise cherrypy.HTTPError(404, 'Tenant %s does not exist.' % tenant)
# If final is None, we return all builds, both final and non-final