summaryrefslogtreecommitdiff
path: root/zuul/nodepool.py
diff options
context:
space:
mode:
authorJames E. Blair <jim@acmegating.com>2021-09-29 15:03:04 -0700
committerJames E. Blair <jim@acmegating.com>2021-09-29 15:07:42 -0700
commit9e1118615c414db4a1b96176e18cebe41437e405 (patch)
treea1ca15692c6c552b353282c16a7cf4787ff69752 /zuul/nodepool.py
parent0bc4a9b4818cfd2200342421e2b6ad26ce213a04 (diff)
downloadzuul-9e1118615c414db4a1b96176e18cebe41437e405.tar.gz
Don't add node resources to nonexistent tenant
The periodic stats emitter may try to add up node resource usage for nodes which belong to tenants the scheduler doesn't know about yet because it's still starting up. This causes the following error: Traceback (most recent call last): File "/usr/local/lib/python3.8/site-packages/zuul/scheduler.py", line 314, in runStats self._runStats() File "/usr/local/lib/python3.8/site-packages/zuul/scheduler.py", line 459, in _runStats self.nodepool.emitStatsTotals(self.abide) File "/usr/local/lib/python3.8/site-packages/zuul/nodepool.py", line 526, in emitStatsTotals self.addResources(resources_by_tenant[tenant_name], File "/usr/local/lib/python3.8/site-packages/zuul/nodepool.py", line 65, in addResources target[key] += value TypeError: 'int' object is not subscriptable First, we shouldn't initialize that dictionary to a defaultdict(int) because it's actually a dict of dicts. The (int) was leftover from a previous implementation. Second, we should just ignore nodes which belong to tenants or projects we don't know about yet. If we're supposed to track them, then we will do so later once configuration is complete. Change-Id: I552943ef9135041704f9849ef241c68d6b758a8a
Diffstat (limited to 'zuul/nodepool.py')
-rw-r--r--zuul/nodepool.py8
1 files changed, 6 insertions, 2 deletions
diff --git a/zuul/nodepool.py b/zuul/nodepool.py
index db37732de..8dd27bfe6 100644
--- a/zuul/nodepool.py
+++ b/zuul/nodepool.py
@@ -484,8 +484,8 @@ class Nodepool(object):
total_requests = 0
tenant_requests = defaultdict(int)
- resources_by_tenant = defaultdict(int)
- resources_by_project = defaultdict(int)
+ resources_by_tenant = {}
+ resources_by_project = {}
empty_resource_dict = dict([(k, 0) for k in self.resource_types])
# Initialize zero values for gauges
@@ -523,8 +523,12 @@ class Nodepool(object):
model.STATE_USED,
model.STATE_HOLD}:
continue
+ if tenant_name not in resources_by_tenant:
+ continue
self.addResources(resources_by_tenant[tenant_name],
node.resources)
+ if project_name not in resources_by_project:
+ continue
self.addResources(resources_by_project[project_name],
node.resources)