Browse Source

Merge "Extract common config parsing for ProviderConfig"

tags/3.5.0
Zuul 4 months ago
parent
commit
264c3478fa

+ 2
- 5
nodepool/cmd/config_validator.py View File

@@ -14,6 +14,7 @@ import logging
14 14
 import voluptuous as v
15 15
 import yaml
16 16
 
17
+from nodepool.driver import ProviderConfig
17 18
 from nodepool.config import get_provider_config
18 19
 
19 20
 log = logging.getLogger(__name__)
@@ -26,11 +27,7 @@ class ConfigValidator:
26 27
         self.config_file = config_file
27 28
 
28 29
     def validate(self):
29
-        provider = {
30
-            'name': v.Required(str),
31
-            'driver': str,
32
-            'max-concurrency': int,
33
-        }
30
+        provider = ProviderConfig.getCommonSchemaDict()
34 31
 
35 32
         label = {
36 33
             'name': str,

+ 9
- 0
nodepool/driver/__init__.py View File

@@ -22,6 +22,7 @@ import importlib
22 22
 import logging
23 23
 import math
24 24
 import os
25
+import voluptuous as v
25 26
 
26 27
 from nodepool import zk
27 28
 from nodepool import exceptions
@@ -910,6 +911,14 @@ class ProviderConfig(ConfigValue, metaclass=abc.ABCMeta):
910 911
     def __repr__(self):
911 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 922
     @property
914 923
     @abc.abstractmethod
915 924
     def pools(self):

+ 4
- 1
nodepool/driver/kubernetes/config.py View File

@@ -109,7 +109,10 @@ class KubernetesProviderConfig(ProviderConfig):
109 109
             v.Required('context'): str,
110 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 117
     def getSupportedLabels(self, pool_name=None):
115 118
         labels = set()

+ 3
- 1
nodepool/driver/openstack/config.py View File

@@ -385,7 +385,8 @@ class OpenStackProviderConfig(ProviderConfig):
385 385
             'security-groups': [str]
386 386
         })
387 387
 
388
-        return v.Schema({
388
+        schema = ProviderConfig.getCommonSchemaDict()
389
+        schema.update({
389 390
             'region-name': str,
390 391
             v.Required('cloud'): str,
391 392
             'boot-timeout': int,
@@ -400,6 +401,7 @@ class OpenStackProviderConfig(ProviderConfig):
400 401
             'diskimages': [provider_diskimage],
401 402
             'cloud-images': [provider_cloud_images],
402 403
         })
404
+        return v.Schema(schema)
403 405
 
404 406
     def getSupportedLabels(self, pool_name=None):
405 407
         labels = set()

+ 3
- 1
nodepool/driver/static/config.py View File

@@ -112,7 +112,9 @@ class StaticProviderConfig(ProviderConfig):
112 112
             'name': str,
113 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 119
     def getSupportedLabels(self, pool_name=None):
118 120
         labels = set()

+ 3
- 1
nodepool/driver/test/config.py View File

@@ -58,7 +58,9 @@ class TestConfig(ProviderConfig):
58 58
             'name': str,
59 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 65
     def getSupportedLabels(self, pool_name=None):
64 66
         return self.labels

Loading…
Cancel
Save