blob: 343dc47c4d5c8ffd36ff18051ed302eb09a796ba [file] [log] [blame]
James E. Blair47958382013-01-10 17:26:02 -08001#!/usr/bin/env python
2
3# Copyright 2013 OpenStack Foundation
4#
5# Licensed under the Apache License, Version 2.0 (the "License"); you may
6# not use this file except in compliance with the License. You may obtain
7# a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14# License for the specific language governing permissions and limitations
15# under the License.
16
17import unittest
18import os
19import re
20import yaml
21import voluptuous
22
23import zuul.layoutvalidator
24
25FIXTURE_DIR = os.path.join(os.path.dirname(__file__),
26 'fixtures')
27LAYOUT_RE = re.compile(r'^(good|bad)_.*\.yaml$')
28
29
30class testScheduler(unittest.TestCase):
31 def test_layouts(self):
32 """Test layout file validation"""
33 print
34 errors = []
35 for fn in os.listdir(os.path.join(FIXTURE_DIR, 'layouts')):
36 m = LAYOUT_RE.match(fn)
37 if not m:
38 continue
39 print fn
40 layout = os.path.join(FIXTURE_DIR, 'layouts', fn)
41 data = yaml.load(open(layout))
42 validator = zuul.layoutvalidator.LayoutValidator()
43 if m.group(1) == 'good':
44 try:
45 validator.validate(data)
46 except voluptuous.Invalid, e:
47 raise Exception(
48 'Unexpected YAML syntax error in %s:\n %s' %
49 (fn, str(e)))
50 else:
51 try:
52 validator.validate(data)
53 raise Exception("Expected a YAML syntax error in %s." %
54 fn)
55 except voluptuous.Invalid, e:
56 error = str(e)
57 print ' ', error
58 if error in errors:
59 raise Exception("Error has already beed tested: %s" %
60 error)
61 else:
62 errors.append(error)
63 pass