From 7a1c75f918cf9025c4b0d61fb6d97bf4ce64255b Mon Sep 17 00:00:00 2001 From: "James E. Blair" Date: Mon, 23 Oct 2023 10:04:02 -0700 Subject: [PATCH] Fix metastatic missing pool config The metastatic driver was ignoring the 3 standard pool configuration options (max-servers, priority, and node-attributes) due to a missing superclass method call. Correct that and update tests to validate. Further, the node-attributes option was undocumented for the metastatic driver, so add it to the docs. Change-Id: I6a65ea5b8ddb319bc131f87e0793f3626379e15f Co-Authored-By: Benedikt Loeffler --- doc/source/metastatic.rst | 6 ++++++ nodepool/driver/metastatic/config.py | 1 + nodepool/tests/fixtures/metastatic.yaml | 7 +++++++ nodepool/tests/unit/test_driver_metastatic.py | 14 ++++++++++++++ 4 files changed, 28 insertions(+) diff --git a/doc/source/metastatic.rst b/doc/source/metastatic.rst index 9ff9853c3..a01a8986d 100644 --- a/doc/source/metastatic.rst +++ b/doc/source/metastatic.rst @@ -85,6 +85,12 @@ itself, which is "meta". to apply to all pools within that provider, or it can be overridden here for a specific pool. + .. attr:: node-attributes + :type: dict + + A dictionary of key-value pairs that will be stored with the node data + in ZooKeeper. The keys and values can be any arbitrary string. + .. attr:: max-servers :type: int diff --git a/nodepool/driver/metastatic/config.py b/nodepool/driver/metastatic/config.py index f4863a71f..b38b0ad91 100644 --- a/nodepool/driver/metastatic/config.py +++ b/nodepool/driver/metastatic/config.py @@ -79,6 +79,7 @@ class MetastaticPool(ConfigPool): self.load(pool_config) def load(self, pool_config): + super().load(pool_config) self.name = pool_config['name'] self.max_servers = pool_config.get('max-servers', math.inf) for label in pool_config.get('labels', []): diff --git a/nodepool/tests/fixtures/metastatic.yaml b/nodepool/tests/fixtures/metastatic.yaml index 16e7f7f95..3305e97b5 100644 --- a/nodepool/tests/fixtures/metastatic.yaml +++ b/nodepool/tests/fixtures/metastatic.yaml @@ -34,6 +34,9 @@ providers: pools: - name: main max-servers: 96 + node-attributes: + backattr: back + testattr: backing labels: - name: backing-label cloud-image: fake-image @@ -45,6 +48,10 @@ providers: pools: - name: main max-servers: 10 + priority: 1 + node-attributes: + metaattr: meta + testattr: metastatic labels: - name: user-label backing-label: backing-label diff --git a/nodepool/tests/unit/test_driver_metastatic.py b/nodepool/tests/unit/test_driver_metastatic.py index f232a8c5e..5b7098aae 100644 --- a/nodepool/tests/unit/test_driver_metastatic.py +++ b/nodepool/tests/unit/test_driver_metastatic.py @@ -85,6 +85,12 @@ class TestDriverMetastatic(tests.DBTestCase): pool = self.useNodepool(configfile, watermark_sleep=1) self.startPool(pool) manager = pool.getProviderManager('fake-provider') + + pool_worker = pool.getPoolWorkers('meta-provider')[0] + pool_config = pool_worker.getPoolConfig() + self.assertEqual(pool_config.max_servers, 10) + self.assertEqual(pool_config.priority, 1) + manager.adapter._client.create_image(name="fake-image") # Request a node, verify that there is a backing node, and it @@ -104,6 +110,14 @@ class TestDriverMetastatic(tests.DBTestCase): self.assertEqual(bn1.host_keys, node1.host_keys) self.assertEqual(['ssh-rsa FAKEKEY'], node1.host_keys) self.assertEqual(bn1.id, node1.driver_data['backing_node']) + self.assertEqual(bn1.attributes, { + 'backattr': 'back', + 'testattr': 'backing', + }) + self.assertEqual(node1.attributes, { + 'metaattr': 'meta', + 'testattr': 'metastatic', + }) # Allocate a second node, should have same backing node node2 = self._requestNode()