Bumps OVS version to 2.8 for OVN
[apex.git] / 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 io
12 import tempfile
13
14 from apex.deploy_settings import DeploySettings
15 from apex.deploy_settings import DeploySettingsException
16
17 from nose.tools import assert_equal
18 from nose.tools import assert_raises
19 from nose.tools import assert_is_instance
20
21 deploy_files = ('deploy_settings.yaml',
22                 'os-nosdn-nofeature-noha.yaml',
23                 'os-nosdn-ovs_dpdk-noha.yaml',
24                 'os-ocl-nofeature-ha.yaml',
25                 'os-odl-bgpvpn-ha.yaml',
26                 'os-odl-bgpvpn-noha.yaml',
27                 'os-odl-nofeature-ha.yaml',
28                 'os-nosdn-nofeature-ha.yaml',
29                 'os-nosdn-ovs_dpdk-ha.yaml',
30                 'os-nosdn-performance-ha.yaml',
31                 'os-odl-nofeature-ha.yaml',
32                 'os-onos-nofeature-ha.yaml',
33                 'os-onos-sfc-ha.yaml')
34
35 test_deploy_content = (
36     'global_params:',
37     'deploy_options: string',
38     """deploy_options: string
39 global_params:""",
40     """global_params:
41 deploy_options:
42   error: error
43 """,
44     """global_params:
45 deploy_options:
46   performance: string
47 """,
48     """global_params:
49 deploy_options:
50   dataplane: invalid
51 """,
52     """global_params:
53 deploy_options:
54   performance:
55     Controller:
56       error: error
57 """,
58     """global_params:
59 deploy_options:
60   performance:
61     InvalidRole:
62       error: error
63 """,)
64
65
66 class TestIpUtils(object):
67     @classmethod
68     def setup_class(klass):
69         """This method is run once for each class before any tests are run"""
70
71     @classmethod
72     def teardown_class(klass):
73         """This method is run once for each class _after_ all tests are run"""
74
75     def setUp(self):
76         """This method is run once before _each_ test method is executed"""
77
78     def teardown(self):
79         """This method is run once after _each_ test method is executed"""
80
81     def test_init(self):
82         for f in deploy_files:
83             ds = DeploySettings('../config/deploy/{}'.format(f))
84             ds = DeploySettings(ds)
85
86     def test__validate_settings(self):
87         for c in test_deploy_content:
88             try:
89                 f = tempfile.NamedTemporaryFile(mode='w')
90                 f.write(c)
91                 f.flush()
92                 assert_raises(DeploySettingsException,
93                               DeploySettings, f.name)
94             finally:
95                 f.close()
96
97     def test_dump_bash(self):
98         # the performance file has the most use of the function
99         # so using that as the test case
100         ds = DeploySettings('../config/deploy/os-nosdn-performance-ha.yaml')
101         assert_equal(ds.dump_bash(), None)
102         assert_equal(ds.dump_bash(path='/dev/null'), None)
103
104     def test_exception(sefl):
105         e = DeploySettingsException("test")
106         print(e)
107         assert_is_instance(e, DeploySettingsException)