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 ##############################################################################
14 from nose.tools import (
20 from apex.common.constants import (
26 from apex import NetworkEnvironment
27 from apex.network.network_environment import NetworkEnvException
28 from apex import NetworkSettings
29 from apex.tests.constants import TEST_CONFIG_DIR
30 from apex.tests.constants import TEST_BUILD_DIR
33 class TestNetworkEnvironment:
36 """This method is run once for each class before any tests are run"""
37 cls.ns = NetworkSettings(
38 os.path.join(TEST_CONFIG_DIR, 'network/network_settings.yaml'))
39 cls.ns_vlans = NetworkSettings(
40 os.path.join(TEST_CONFIG_DIR,
41 'network/network_settings_vlans.yaml'))
42 cls.ns_ipv6 = NetworkSettings(
43 os.path.join(TEST_CONFIG_DIR, 'network/network_settings_v6.yaml'))
46 def teardown_class(klass):
47 """This method is run once for each class _after_ all tests are run"""
50 """This method is run once before _each_ test method is executed"""
53 """This method is run once after _each_ test method is executed"""
56 assert_raises(NetworkEnvException, NetworkEnvironment,
57 None, os.path.join(TEST_BUILD_DIR, NET_ENV_FILE))
59 def test_netenv_settings_external_network_vlans(self):
61 ne = NetworkEnvironment(self.ns_vlans,
62 os.path.join(TEST_BUILD_DIR, NET_ENV_FILE))
63 assert_equal(ne['parameter_defaults']['NeutronExternalNetworkBridge'],
65 assert_equal(ne['parameter_defaults']['ExternalNetworkVlanID'], 501)
67 def test_netenv_settings_external_network_ipv6(self):
69 ne = NetworkEnvironment(self.ns_ipv6,
70 os.path.join(TEST_BUILD_DIR, NET_ENV_FILE))
71 regstr = ne['resource_registry']['OS::TripleO::Network::External']
72 assert_equal(regstr.split('/')[-1], 'external_v6.yaml')
74 def test_netenv_settings_external_network_removed(self):
76 # Test removing EXTERNAL_NETWORK
77 ns.enabled_network_list.remove(EXTERNAL_NETWORK)
78 ne = NetworkEnvironment(ns, os.path.join(TEST_BUILD_DIR, NET_ENV_FILE))
79 regstr = ne['resource_registry']['OS::TripleO::Network::External']
80 assert_equal(regstr.split('/')[-1], 'OS::Heat::None')
82 def test_netenv_settings_tenant_network_vlans(self):
84 ne = NetworkEnvironment(self.ns_vlans,
85 os.path.join(TEST_BUILD_DIR, NET_ENV_FILE))
86 assert_equal(ne['parameter_defaults']['TenantNetworkVlanID'], 401)
88 # Apex is does not support v6 tenant networks
89 # Though there is code that would fire if a
90 # v6 cidr was passed in, just uncomment this to
92 # def test_netenv_settings_tenant_network_v6(self):
94 # ne = NetworkEnvironment(self.ns_ipv6,
95 # '../build/network-environment.yaml')
96 # regstr = ne['resource_registry'][next(iter(TENANT_RESOURCES.keys()))]
97 # assert_equal(regstr.split('/')[-1], 'tenant_v6.yaml')
99 def test_netenv_settings_tenant_network_removed(self):
101 # Test removing TENANT_NETWORK
102 ns.enabled_network_list.remove(TENANT_NETWORK)
103 ne = NetworkEnvironment(ns, os.path.join(TEST_BUILD_DIR, NET_ENV_FILE))
104 regstr = ne['resource_registry']['OS::TripleO::Network::Tenant']
105 assert_equal(regstr.split('/')[-1], 'OS::Heat::None')
107 def test_netenv_settings_storage_network_vlans(self):
109 ne = NetworkEnvironment(self.ns_vlans,
110 os.path.join(TEST_BUILD_DIR, NET_ENV_FILE))
111 assert_equal(ne['parameter_defaults']['StorageNetworkVlanID'], 201)
113 def test_netenv_settings_storage_network_v6(self):
115 ne = NetworkEnvironment(self.ns_ipv6,
116 os.path.join(TEST_BUILD_DIR, NET_ENV_FILE))
117 regstr = ne['resource_registry']['OS::TripleO::Network::Storage']
118 assert_equal(regstr.split('/')[-1], 'storage_v6.yaml')
120 def test_netenv_settings_storage_network_removed(self):
122 # Test removing STORAGE_NETWORK
123 ns.enabled_network_list.remove(STORAGE_NETWORK)
124 ne = NetworkEnvironment(ns, os.path.join(TEST_BUILD_DIR, NET_ENV_FILE))
125 regstr = ne['resource_registry']['OS::TripleO::Network::Storage']
126 assert_equal(regstr.split('/')[-1], 'OS::Heat::None')
128 def test_netenv_settings_api_network_v4(self):
129 ns = copy(self.ns_vlans)
130 ns['networks'][API_NETWORK]['enabled'] = True
131 ns['networks'][API_NETWORK]['cidr'] = '10.11.12.0/24'
132 ns = NetworkSettings(ns)
134 ne = NetworkEnvironment(ns, os.path.join(TEST_BUILD_DIR, NET_ENV_FILE))
135 assert_equal(ne['parameter_defaults']['InternalApiNetworkVlanID'], 101)
137 def test_netenv_settings_api_network_vlans(self):
138 ns = copy(self.ns_vlans)
139 ns['networks'][API_NETWORK]['enabled'] = True
140 ns = NetworkSettings(ns)
142 ne = NetworkEnvironment(ns, os.path.join(TEST_BUILD_DIR, NET_ENV_FILE))
143 assert_equal(ne['parameter_defaults']['InternalApiNetworkVlanID'], 101)
145 def test_netenv_settings_api_network_v6(self):
147 ne = NetworkEnvironment(self.ns_ipv6,
148 os.path.join(TEST_BUILD_DIR, NET_ENV_FILE))
149 regstr = ne['resource_registry']['OS::TripleO::Network::InternalApi']
150 assert_equal(regstr.split('/')[-1], 'internal_api_v6.yaml')
152 def test_netenv_settings_api_network_removed(self):
154 # API_NETWORK is not in the default network settings file
155 ne = NetworkEnvironment(ns, os.path.join(TEST_BUILD_DIR, NET_ENV_FILE))
156 regstr = ne['resource_registry']['OS::TripleO::Network::InternalApi']
157 assert_equal(regstr.split('/')[-1], 'OS::Heat::None')
159 def test_numa_configs(self):
160 ne = NetworkEnvironment(self.ns,
161 os.path.join(TEST_BUILD_DIR, NET_ENV_FILE),
162 compute_pre_config=True,
163 controller_pre_config=True)
164 assert_is_instance(ne, dict)
165 assert_not_equal(ne, {})
167 def test_exception(self):
168 e = NetworkEnvException("test")
170 assert_is_instance(e, NetworkEnvException)