summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Shrewsbury <shrewsbury.dave@gmail.com>2018-12-13 15:14:20 -0500
committerTobias Henkel <tobias.henkel@bmw.de>2019-01-07 12:34:05 +0000
commitd6ef934b708b1731a248e05f2aaf56024d5a826a (patch)
tree4cc641425ddde27716696ea3c9b6fce4f4665a6b
parenta19dffd916981097e3eb59dcbbc75787e9590d1a (diff)
Extract common config parsing for ProviderConfig
Adds a ProviderConfig class method that can be called to get the config schema for the common config options in a Provider. Drivers are modified to call this method. Change-Id: Ib67256dddc06d13eb7683226edaa8c8c10a73326
Notes
Notes (review): Code-Review+2: Tobias Henkel <tobias.henkel@bmw.de> Code-Review+2: Monty Taylor <mordred@inaugust.com> Code-Review+2: James E. Blair <corvus@inaugust.com> Workflow+1: James E. Blair <corvus@inaugust.com> Verified+2: Zuul Submitted-by: Zuul Submitted-at: Wed, 09 Jan 2019 21:41:32 +0000 Reviewed-on: https://review.openstack.org/625094 Project: openstack-infra/nodepool Branch: refs/heads/master
-rw-r--r--nodepool/cmd/config_validator.py7
-rw-r--r--nodepool/driver/__init__.py9
-rw-r--r--nodepool/driver/kubernetes/config.py5
-rw-r--r--nodepool/driver/openstack/config.py4
-rw-r--r--nodepool/driver/static/config.py4
-rw-r--r--nodepool/driver/test/config.py4
6 files changed, 24 insertions, 9 deletions
diff --git a/nodepool/cmd/config_validator.py b/nodepool/cmd/config_validator.py
index c06b64d..c3dde57 100644
--- a/nodepool/cmd/config_validator.py
+++ b/nodepool/cmd/config_validator.py
@@ -14,6 +14,7 @@ import logging
14import voluptuous as v 14import voluptuous as v
15import yaml 15import yaml
16 16
17from nodepool.driver import ProviderConfig
17from nodepool.config import get_provider_config 18from nodepool.config import get_provider_config
18 19
19log = logging.getLogger(__name__) 20log = logging.getLogger(__name__)
@@ -26,11 +27,7 @@ class ConfigValidator:
26 self.config_file = config_file 27 self.config_file = config_file
27 28
28 def validate(self): 29 def validate(self):
29 provider = { 30 provider = ProviderConfig.getCommonSchemaDict()
30 'name': v.Required(str),
31 'driver': str,
32 'max-concurrency': int,
33 }
34 31
35 label = { 32 label = {
36 'name': str, 33 'name': str,
diff --git a/nodepool/driver/__init__.py b/nodepool/driver/__init__.py
index dde69c1..1b958a4 100644
--- a/nodepool/driver/__init__.py
+++ b/nodepool/driver/__init__.py
@@ -22,6 +22,7 @@ import importlib
22import logging 22import logging
23import math 23import math
24import os 24import os
25import voluptuous as v
25 26
26from nodepool import zk 27from nodepool import zk
27from nodepool import exceptions 28from nodepool import exceptions
@@ -910,6 +911,14 @@ class ProviderConfig(ConfigValue, metaclass=abc.ABCMeta):
910 def __repr__(self): 911 def __repr__(self):
911 return "<Provider %s>" % self.name 912 return "<Provider %s>" % self.name
912 913
914 @classmethod
915 def getCommonSchemaDict(self):
916 return {
917 v.Required('name'): str,
918 'driver': str,
919 'max-concurrency': int
920 }
921
913 @property 922 @property
914 @abc.abstractmethod 923 @abc.abstractmethod
915 def pools(self): 924 def pools(self):
diff --git a/nodepool/driver/kubernetes/config.py b/nodepool/driver/kubernetes/config.py
index db303a8..d58ffb0 100644
--- a/nodepool/driver/kubernetes/config.py
+++ b/nodepool/driver/kubernetes/config.py
@@ -109,7 +109,10 @@ class KubernetesProviderConfig(ProviderConfig):
109 v.Required('context'): str, 109 v.Required('context'): str,
110 'launch-retries': int, 110 'launch-retries': int,
111 } 111 }
112 return v.Schema(provider) 112
113 schema = ProviderConfig.getCommonSchemaDict()
114 schema.update(provider)
115 return v.Schema(schema)
113 116
114 def getSupportedLabels(self, pool_name=None): 117 def getSupportedLabels(self, pool_name=None):
115 labels = set() 118 labels = set()
diff --git a/nodepool/driver/openstack/config.py b/nodepool/driver/openstack/config.py
index 065ac9f..2f25997 100644
--- a/nodepool/driver/openstack/config.py
+++ b/nodepool/driver/openstack/config.py
@@ -385,7 +385,8 @@ class OpenStackProviderConfig(ProviderConfig):
385 'security-groups': [str] 385 'security-groups': [str]
386 }) 386 })
387 387
388 return v.Schema({ 388 schema = ProviderConfig.getCommonSchemaDict()
389 schema.update({
389 'region-name': str, 390 'region-name': str,
390 v.Required('cloud'): str, 391 v.Required('cloud'): str,
391 'boot-timeout': int, 392 'boot-timeout': int,
@@ -400,6 +401,7 @@ class OpenStackProviderConfig(ProviderConfig):
400 'diskimages': [provider_diskimage], 401 'diskimages': [provider_diskimage],
401 'cloud-images': [provider_cloud_images], 402 'cloud-images': [provider_cloud_images],
402 }) 403 })
404 return v.Schema(schema)
403 405
404 def getSupportedLabels(self, pool_name=None): 406 def getSupportedLabels(self, pool_name=None):
405 labels = set() 407 labels = set()
diff --git a/nodepool/driver/static/config.py b/nodepool/driver/static/config.py
index cef6a09..b35b965 100644
--- a/nodepool/driver/static/config.py
+++ b/nodepool/driver/static/config.py
@@ -112,7 +112,9 @@ class StaticProviderConfig(ProviderConfig):
112 'name': str, 112 'name': str,
113 'nodes': [pool_node], 113 'nodes': [pool_node],
114 }) 114 })
115 return v.Schema({'pools': [pool]}) 115 schema = ProviderConfig.getCommonSchemaDict()
116 schema.update({'pools': [pool]})
117 return v.Schema(schema)
116 118
117 def getSupportedLabels(self, pool_name=None): 119 def getSupportedLabels(self, pool_name=None):
118 labels = set() 120 labels = set()
diff --git a/nodepool/driver/test/config.py b/nodepool/driver/test/config.py
index a164804..b90f268 100644
--- a/nodepool/driver/test/config.py
+++ b/nodepool/driver/test/config.py
@@ -58,7 +58,9 @@ class TestConfig(ProviderConfig):
58 'name': str, 58 'name': str,
59 'labels': [str] 59 'labels': [str]
60 }) 60 })
61 return v.Schema({'pools': [pool]}) 61 schema = ProviderConfig.getCommonSchemaDict()
62 schema.update({'pools': [pool]})
63 return v.Schema(schema)
62 64
63 def getSupportedLabels(self, pool_name=None): 65 def getSupportedLabels(self, pool_name=None):
64 return self.labels 66 return self.labels