Manage a pool of nodes for a distributed test infrastructure
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

81 lines
2.3KB

  1. # Licensed under the Apache License, Version 2.0 (the "License"); you may
  2. # not use this file except in compliance with the License. You may obtain
  3. # a copy of the License at
  4. #
  5. # http://www.apache.org/licenses/LICENSE-2.0
  6. #
  7. # Unless required by applicable law or agreed to in writing, software
  8. # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  9. # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  10. # License for the specific language governing permissions and limitations
  11. # under the License.
  12. import logging
  13. import voluptuous as v
  14. import yaml
  15. from nodepool.driver import ProviderConfig
  16. from nodepool.config import get_provider_config
  17. log = logging.getLogger(__name__)
  18. class ConfigValidator:
  19. """Check the layout and certain configuration options"""
  20. def __init__(self, config_file):
  21. self.config_file = config_file
  22. def validate(self):
  23. provider = ProviderConfig.getCommonSchemaDict()
  24. label = {
  25. 'name': str,
  26. 'min-ready': int,
  27. 'max-ready-age': int,
  28. }
  29. diskimage = {
  30. 'name': str,
  31. 'pause': bool,
  32. 'elements': [str],
  33. 'formats': [str],
  34. 'release': v.Any(str, int),
  35. 'rebuild-age': int,
  36. 'env-vars': {str: str},
  37. 'username': str,
  38. 'build-timeout': int,
  39. }
  40. webapp = {
  41. 'port': int,
  42. 'listen_address': str,
  43. }
  44. top_level = {
  45. 'webapp': webapp,
  46. 'elements-dir': str,
  47. 'images-dir': str,
  48. 'build-log-dir': str,
  49. 'build-log-retention': int,
  50. 'zookeeper-servers': [{
  51. 'host': str,
  52. 'port': int,
  53. 'chroot': str,
  54. }],
  55. 'providers': list,
  56. 'labels': [label],
  57. 'diskimages': [diskimage],
  58. 'max-hold-age': int,
  59. }
  60. log.info("validating %s" % self.config_file)
  61. config = yaml.load(open(self.config_file))
  62. # validate the overall schema
  63. schema = v.Schema(top_level)
  64. schema(config)
  65. for provider_dict in config.get('providers', []):
  66. provider_schema = get_provider_config(provider_dict).getSchema()
  67. provider_schema.extend(provider)(provider_dict)