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