From 9126b47650a0724932467fc31ec676f0724592e6 Mon Sep 17 00:00:00 2001 From: David Shrewsbury Date: Wed, 3 Aug 2016 10:40:47 -0400 Subject: [PATCH] Add config support for ZooKeeper servers Allows defining a cluster of ZooKeeper servers within the nodepool configuration file. Validation of the new config values is supported, and the new values are documented. Change-Id: I24401d08135a071dee1d00711fdd82c1d728b31a --- doc/source/configuration.rst | 15 +++++++++++++++ nodepool/cmd/config_validator.py | 5 +++++ nodepool/config.py | 13 +++++++++++++ nodepool/tests/fixtures/config_validate/good.yaml | 5 +++++ .../fixtures/config_validate/yaml_error.yaml | 3 +++ nodepool/tests/test_builder.py | 4 ---- 6 files changed, 41 insertions(+), 4 deletions(-) diff --git a/doc/source/configuration.rst b/doc/source/configuration.rst index 6b09d60e3..d4f95e879 100644 --- a/doc/source/configuration.rst +++ b/doc/source/configuration.rst @@ -152,6 +152,21 @@ Example:: The ``port`` key is optional (default: 4730). +zookeeper-servers +----------------- +Lists the ZooKeeper servers uses for coordinating information between +nodepool workers. Example:: + + zookeeper-servers: + - host: zk1.example.com + port: 2181 + chroot: /nodepool + +The ``port`` key is optional (default: 2181). + +The ``chroot`` key, used for interpreting ZooKeeper paths relative to +the supplied root path, is also optional and has no default. + .. _labels: labels diff --git a/nodepool/cmd/config_validator.py b/nodepool/cmd/config_validator.py index 7c699d063..592fb574a 100644 --- a/nodepool/cmd/config_validator.py +++ b/nodepool/cmd/config_validator.py @@ -122,6 +122,11 @@ class ConfigValidator: 'host': str, 'port': int, }], + 'zookeeper-servers': [{ + 'host': str, + 'port': int, + 'chroot': str, + }], 'cron': cron, 'providers': [providers], 'labels': [labels], diff --git a/nodepool/config.py b/nodepool/config.py index 590330328..46d64ddf4 100644 --- a/nodepool/config.py +++ b/nodepool/config.py @@ -102,6 +102,10 @@ class GearmanServer(ConfigValue): pass +class ZooKeeperServer(ConfigValue): + pass + + class DiskImage(ConfigValue): pass @@ -128,6 +132,7 @@ def loadConfig(config_path): newconfig.jenkins_managers = {} newconfig.zmq_publishers = {} newconfig.gearman_servers = {} + newconfig.zookeeper_servers = {} newconfig.diskimages = {} newconfig.crons = {} @@ -155,6 +160,14 @@ def loadConfig(config_path): g.name = g.host + '_' + str(g.port) newconfig.gearman_servers[g.name] = g + for server in config.get('zookeeper-servers', []): + z = ZooKeeperServer() + z.host = server['host'] + z.port = server.get('port', 2181) + z.chroot = server.get('chroot', '') + z.name = z.host + '_' + str(z.port) + newconfig.zookeeper_servers[z.name] = z + for provider in config.get('providers', []): p = Provider() p.name = provider['name'] diff --git a/nodepool/tests/fixtures/config_validate/good.yaml b/nodepool/tests/fixtures/config_validate/good.yaml index 30d68d16c..54f9ad56f 100644 --- a/nodepool/tests/fixtures/config_validate/good.yaml +++ b/nodepool/tests/fixtures/config_validate/good.yaml @@ -19,6 +19,11 @@ zmq-publishers: gearman-servers: - host: zuul.openstack.org +zookeeper-servers: + - host: zk1.openstack.org + port: 2181 + chroot: /test + labels: - name: devstack-precise image: devstack-precise diff --git a/nodepool/tests/fixtures/config_validate/yaml_error.yaml b/nodepool/tests/fixtures/config_validate/yaml_error.yaml index bd20c7839..7d153c620 100644 --- a/nodepool/tests/fixtures/config_validate/yaml_error.yaml +++ b/nodepool/tests/fixtures/config_validate/yaml_error.yaml @@ -19,6 +19,9 @@ zmq-publishers: gearman-servers: - host: zuul.openstack.org +zookeeper-servers: + - host: zk1.openstack.org + labels: - name: devstack-precise image: devstack-precise diff --git a/nodepool/tests/test_builder.py b/nodepool/tests/test_builder.py index 622cc0ce0..884cf9d11 100644 --- a/nodepool/tests/test_builder.py +++ b/nodepool/tests/test_builder.py @@ -147,7 +147,3 @@ class TestNodepoolBuilder(tests.DBTestCase): # We failed to upload first_fail_id and have # moved onto another upload that will fail. break - -class TestZookeeper(tests.ZKTestCase): - def test_zk(self): - self.zkclient.get('/')