1 ##############################################################################
2 # Copyright (c) 2016 Dan Radez (Red Hat)
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 ##############################################################################
10 from apex.network_settings import (
12 NetworkSettingsException,
15 from nose.tools import (
22 class TestNetworkSettings(object):
24 def setup_class(klass):
25 """This method is run once for each class before any tests are run"""
28 def teardown_class(klass):
29 """This method is run once for each class _after_ all tests are run"""
32 """This method is run once before _each_ test method is executed"""
35 """This method is run once after _each_ test method is executed"""
38 NetworkSettings('../config/network/network_settings.yaml', True)
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)
45 def test_get_network_settings(self):
46 ns = NetworkSettings('../config/network/network_settings.yaml', True)
47 assert_is_instance(ns.get_network_settings(), dict)
48 for role in ['controller', 'compute']:
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)
56 def test_get_network_settings_unspecified_nics(self):
58 '../tests/config/network_settings_nics_not_specified.yaml',
60 assert_is_instance(ns.get_network_settings(), dict)
61 for role in ['controller', 'compute']:
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)
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)
73 def test_negative_network_settings(self):
74 assert_raises(NetworkSettingsException, NetworkSettings,
75 '../tests/config/network_settings_duplicate_nic.yaml',
77 assert_raises(NetworkSettingsException, NetworkSettings,
78 '../tests/config/network_settings_nic1_reserved.yaml',
80 assert_raises(NetworkSettingsException, NetworkSettings,
81 '../tests/config/network_settings_missing_required_nic'