Merge "Scripts for running smoke tests on the undercloud VM. Tested against Apex...
[apex.git] / tests / test_apex_deploy_env.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_env import DeploySettings
14 from apex.deploy_env import DeploySettingsException
15
16 from nose.tools import assert_equal
17 from nose.tools import assert_raises
18
19 deploy_files = ('deploy_settings.yaml',
20                 'os-nosdn-nofeature-noha.yaml',
21                 'os-nosdn-ovs-noha.yaml',
22                 'os-ocl-nofeature-ha.yaml',
23                 'os-odl_l2-sdnvpn-ha.yaml',
24                 'os-odl_l3-nofeature-ha.yaml',
25                 'os-nosdn-nofeature-ha.yaml',
26                 'os-nosdn-ovs-ha.yaml',
27                 'os-nosdn-performance-ha.yaml',
28                 'os-odl_l2-nofeature-ha.yaml',
29                 'os-odl_l2-sfc-noha.yaml',
30                 'os-onos-nofeature-ha.yaml',
31                 'os-onos-sfc-ha.yaml')
32
33 test_deploy_content = (
34     'global_params:',
35     'deploy_options: string',
36     """deploy_options: string
37 global_params:""",
38     """global_params:
39 deploy_options:
40   error: error
41 """,
42     """global_params:
43 deploy_options:
44   performance: string
45 """,
46     """global_params:
47 deploy_options:
48   dataplane: invalid
49 """,
50     """global_params:
51 deploy_options:
52   performance:
53     Controller:
54       error: error
55 """,)
56
57
58 class TestIpUtils(object):
59     @classmethod
60     def setup_class(klass):
61         """This method is run once for each class before any tests are run"""
62
63     @classmethod
64     def teardown_class(klass):
65         """This method is run once for each class _after_ all tests are run"""
66
67     def setUp(self):
68         """This method is run once before _each_ test method is executed"""
69
70     def teardown(self):
71         """This method is run once after _each_ test method is executed"""
72
73     def test_init(self):
74         for f in deploy_files:
75             ds = DeploySettings('../config/deploy/{}'.format(f))
76
77     def test__validate_settings(self):
78         for c in test_deploy_content:
79             f = open('/tmp/apex_deploy_test_file', 'w')
80             f.write(c)
81             f.close()
82             assert_raises(DeploySettingsException,
83                           DeploySettings, '/tmp/apex_deploy_test_file')
84
85     def test_dump_bash(self):
86         # the performance file has the most use of the function
87         # so using that as the test case
88         ds = DeploySettings('../config/deploy/os-nosdn-performance-ha.yaml')
89         assert_equal(ds.dump_bash(), None)
90         assert_equal(ds.dump_bash(path='/dev/null'), None)