Adding developer/troubleshooting section to Installation Instructions
[apex.git] / tests / test_apex_network_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 from apex.network_settings import (
11     NetworkSettings,
12     NetworkSettingsException,
13 )
14
15 from nose.tools import (
16     assert_equal,
17     assert_is_instance,
18     assert_raises
19 )
20
21
22 class TestNetworkSettings(object):
23     @classmethod
24     def setup_class(klass):
25         """This method is run once for each class before any tests are run"""
26
27     @classmethod
28     def teardown_class(klass):
29         """This method is run once for each class _after_ all tests are run"""
30
31     def setUp(self):
32         """This method is run once before _each_ test method is executed"""
33
34     def teardown(self):
35         """This method is run once after _each_ test method is executed"""
36
37     def test_init(self):
38         NetworkSettings('../config/network/network_settings.yaml', True)
39
40     def test_dump_bash(self):
41         ns = NetworkSettings('../config/network/network_settings.yaml', True)
42         assert_equal(ns.dump_bash(), None)
43         assert_equal(ns.dump_bash(path='/dev/null'), None)
44
45     def test_get_network_settings(self):
46         ns = NetworkSettings('../config/network/network_settings.yaml', True)
47         assert_is_instance(ns, dict)
48         for role in ['controller', 'compute']:
49             nic_index = 1
50             for network in ['admin_network', 'private_network',
51                             'public_network', 'storage_network']:
52                 nic = 'nic' + str(nic_index)
53                 assert_equal(ns.nics[role][network], nic)
54                 nic_index += 1
55
56     def test_get_network_settings_unspecified_nics(self):
57         ns = NetworkSettings(
58             '../tests/config/network_settings_nics_not_specified.yaml',
59             True)
60         assert_is_instance(ns, dict)
61         for role in ['controller', 'compute']:
62             nic_index = 1
63             for network in ['admin_network', 'private_network',
64                             'public_network', 'storage_network']:
65                 nic = 'nic' + str(nic_index)
66                 assert_equal(ns.nics[role][network], nic)
67                 nic_index += 1
68
69     def test_get_enabled_networks(self):
70         ns = NetworkSettings('../config/network/network_settings.yaml', True)
71         assert_is_instance(ns.get_enabled_networks(), list)
72
73     def test_negative_network_settings(self):
74         assert_raises(NetworkSettingsException, NetworkSettings,
75                       '../tests/config/network_settings_duplicate_nic.yaml',
76                       True)
77         assert_raises(NetworkSettingsException, NetworkSettings,
78                       '../tests/config/network_settings_nic1_reserved.yaml',
79                       True)
80         assert_raises(NetworkSettingsException, NetworkSettings,
81                       '../tests/config/network_settings_missing_required_nic'
82                       '.yaml', True)