From ba7f81be2d4008868c319db3827fab66b0c38dee Mon Sep 17 00:00:00 2001 From: Felix Edel Date: Wed, 28 Apr 2021 15:02:25 +0200 Subject: [PATCH] Provide statsd client to Nodepool and make scheduler optional To lock/unlock the nodes directly in the executor server, we have to make the Nodepool API work without a scheduler instance. To keep the stats emitting intact, we provide a statsd client directly to the Nodepool instance. This leaves only one place where the scheduler is used in the Nodepool class, which is the onNodesProvisioned() callback. This callback won't be necessary anymore when the nodes are locked on the executor and thus this function call and the scheduler parameter itself can be removed. Change-Id: I3f3e4bfff08e244f68a9be7c6a4efcc194a23332 --- tests/nodepool/test_nodepool_integration.py | 3 +- tests/unit/test_nodepool.py | 3 +- zuul/nodepool.py | 86 +++++++++++---------- zuul/scheduler.py | 3 +- 4 files changed, 52 insertions(+), 43 deletions(-) diff --git a/tests/nodepool/test_nodepool_integration.py b/tests/nodepool/test_nodepool_integration.py index 6e8405a5a4..e212ef8ff5 100644 --- a/tests/nodepool/test_nodepool_integration.py +++ b/tests/nodepool/test_nodepool_integration.py @@ -39,7 +39,8 @@ class TestNodepoolIntegration(BaseTestCase): self.provisioned_requests = [] # This class implements the scheduler methods zuul.nodepool # needs, so we pass 'self' as the scheduler. - self.nodepool = zuul.nodepool.Nodepool(self) + self.nodepool = zuul.nodepool.Nodepool( + self.zk_client, self.hostname, self.statsd, self) def waitForRequests(self): # Wait until all requests are complete. diff --git a/tests/unit/test_nodepool.py b/tests/unit/test_nodepool.py index 6d6552c7ce..3b6bfca3ce 100644 --- a/tests/unit/test_nodepool.py +++ b/tests/unit/test_nodepool.py @@ -46,7 +46,8 @@ class TestNodepool(BaseTestCase): self.provisioned_requests = [] # This class implements the scheduler methods zuul.nodepool # needs, so we pass 'self' as the scheduler. - self.nodepool = zuul.nodepool.Nodepool(self) + self.nodepool = zuul.nodepool.Nodepool( + self.zk_client, self.hostname, self.statsd, self) self.fake_nodepool = FakeNodepool(self.zk_chroot_fixture) self.addCleanup(self.fake_nodepool.stop) diff --git a/zuul/nodepool.py b/zuul/nodepool.py index a9732dec7f..69ce515f4e 100644 --- a/zuul/nodepool.py +++ b/zuul/nodepool.py @@ -17,6 +17,7 @@ from collections import defaultdict from zuul import model from zuul.lib.logutil import get_annotated_logger from zuul.zk.exceptions import LockException +from zuul.zk.nodepool import ZooKeeperNodepool def add_resources(target, source): @@ -32,9 +33,16 @@ def subtract_resources(target, source): class Nodepool(object): log = logging.getLogger('zuul.nodepool') - def __init__(self, scheduler): - self.requests = {} + def __init__(self, zk_client, hostname, statsd, scheduler=None): + self.hostname = hostname + self.statsd = statsd + # TODO (felix): Remove the scheduler parameter once the nodes are + # locked on the executor side. self.sched = scheduler + + self.zk_nodepool = ZooKeeperNodepool(zk_client) + + self.requests = {} self.current_resources_by_tenant = {} self.current_resources_by_project = {} @@ -47,10 +55,9 @@ class Nodepool(object): # timer zuul.nodepool.requests.(fulfilled|failed).