312c1f3acd62c5e64408cf75074b152bda6de9a1
[apex.git] / apex / tests / test_apex_deploy_settings.py
1 ##############################################################################
2 # Copyright (c) 2016 Dan Radez (Red Hat)
3 #
4 # All rights reserved. This program and the accompanying materials
5 # are made available under the terms of the Apache License, Version 2.0
6 # which accompanies this distribution, and is available at
7 # http://www.apache.org/licenses/LICENSE-2.0
8 ##############################################################################
9
10 # https://docs.python.org/3/library/io.html
11 import os
12 import tempfile
13
14 from nose.tools import assert_equal
15 from nose.tools import assert_is_instance
16 from nose.tools import assert_raises
17
18 from apex.settings.deploy_settings import DeploySettings
19 from apex.settings.deploy_settings import DeploySettingsException
20 from apex.tests.constants import TEST_CONFIG_DIR
21
22 deploy_files = ('deploy_settings.yaml',
23                 'os-nosdn-nofeature-noha.yaml',
24                 'os-nosdn-ovs_dpdk-noha.yaml',
25                 'os-ocl-nofeature-ha.yaml',
26                 'os-odl-bgpvpn-ha.yaml',
27                 'os-odl-bgpvpn-noha.yaml',
28                 'os-odl-nofeature-ha.yaml',
29                 'os-nosdn-nofeature-ha.yaml',
30                 'os-nosdn-ovs_dpdk-ha.yaml',
31                 'os-nosdn-performance-ha.yaml',
32                 'os-odl-nofeature-ha.yaml',
33                 'os-onos-nofeature-ha.yaml',
34                 'os-onos-sfc-ha.yaml')
35
36 test_deploy_content = (
37     'global_params:',
38     'deploy_options: string',
39     """deploy_options: string
40 global_params:""",
41     """global_params:
42 deploy_options:
43   error: error
44 """,
45     """global_params:
46 deploy_options:
47   performance: string
48 """,
49     """global_params:
50 deploy_options:
51   dataplane: invalid
52 """,
53     """global_params:
54 deploy_options:
55   performance:
56     Controller:
57       error: error
58 """,
59     """global_params:
60 deploy_options:
61   performance:
62     InvalidRole:
63       error: error
64 """,)
65
66
67 class TestIpUtils(object):
68     @classmethod
69     def setup_class(klass):
70         """This method is run once for each class before any tests are run"""
71
72     @classmethod
73     def teardown_class(klass):
74         """This method is run once for each class _after_ all tests are run"""
75
76     def setUp(self):
77         """This method is run once before _each_ test method is executed"""
78
79     def teardown(self):
80         """This method is run once after _each_ test method is executed"""
81
82     def test_init(self):
83         for f in deploy_files:
84             ds = DeploySettings(os.path.join(TEST_CONFIG_DIR, 'deploy', f))
85             ds = DeploySettings(ds)
86
87     def test__validate_settings(self):
88         for c in test_deploy_content:
89             try:
90                 f = tempfile.NamedTemporaryFile(mode='w')
91                 f.write(c)
92                 f.flush()
93                 assert_raises(DeploySettingsException,
94                               DeploySettings, f.name)
95             finally:
96                 f.close()
97
98     def test_exception(self):
99         e = DeploySettingsException("test")
100         print(e)
101         assert_is_instance(e, DeploySettingsException)