summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorDan Radez <dradez@redhat.com>2016-08-23 20:22:26 -0400
committerDan Radez <dradez@redhat.com>2016-08-24 14:02:23 -0400
commit3403334a7c1758bd81dafb3fad77470d91691580 (patch)
treeabcbe2b8f80248ef97e1059bfc35c72d8b81ce18 /tests
parent1895eba89b351b0f74a2280c023bbf799aa94e09 (diff)
adding more network_environment.py tests
- increasing required test coverage to 90% - also consolidating some repeated code into functions Change-Id: I6b582478c509c24fce43224a516414e1ead6c8e4 Signed-off-by: Dan Radez <dradez@redhat.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/test_apex_network_environment.py98
1 files changed, 95 insertions, 3 deletions
diff --git a/tests/test_apex_network_environment.py b/tests/test_apex_network_environment.py
index 9dcaffc0..673368e8 100644
--- a/tests/test_apex_network_environment.py
+++ b/tests/test_apex_network_environment.py
@@ -7,9 +7,21 @@
# http://www.apache.org/licenses/LICENSE-2.0
##############################################################################
+import ipaddress
+
+from apex.common.constants import (
+ PUBLIC_NETWORK,
+ PRIVATE_NETWORK,
+ STORAGE_NETWORK,
+ API_NETWORK)
from apex.network_settings import NetworkSettings
-from apex.network_environment import NetworkEnvironment
-from apex.network_environment import NetworkEnvException
+from apex.network_environment import (
+ NetworkEnvironment,
+ NetworkEnvException,
+ EXTERNAL_RESOURCES,
+ TENANT_RESOURCES,
+ STORAGE_RESOURCES,
+ API_RESOURCES)
from nose.tools import assert_equal
from nose.tools import assert_raises
@@ -36,10 +48,90 @@ class TestNetworkEnvironment(object):
assert_raises(NetworkEnvException, NetworkEnvironment,
None, '../build/network-environment.yaml')
- def test_get_netenv_settings(self):
+ def test_netenv_settings_public_network(self):
+ ns = NetworkSettings('../config/network/network_settings.yaml', True)
+ # test vlans
+ ns[PUBLIC_NETWORK]['vlan'] = 100
+ ne = NetworkEnvironment(ns, '../build/network-environment.yaml')
+ assert_equal(ne['parameter_defaults']['NeutronExternalNetworkBridge'],
+ '""')
+ assert_equal(ne['parameter_defaults']['ExternalNetworkVlanID'], 100)
+
+ # Test IPv6
+ ns[PUBLIC_NETWORK]['cidr'] = ipaddress.ip_network('::1/128')
+ ne = NetworkEnvironment(ns, '../build/network-environment.yaml')
+ regstr = ne['resource_registry'][next(iter(EXTERNAL_RESOURCES.keys()))]
+ assert_equal(regstr.split('/')[-1], 'external_v6.yaml')
+
+ def test_netenv_settings_private_network(self):
+ ns = NetworkSettings('../config/network/network_settings.yaml', True)
+ # test vlans
+ ns[PRIVATE_NETWORK]['vlan'] = 100
+ ne = NetworkEnvironment(ns, '../build/network-environment.yaml')
+ assert_equal(ne['parameter_defaults']['TenantNetworkVlanID'], 100)
+
+ # Test IPv6
+ ns[PRIVATE_NETWORK]['cidr'] = ipaddress.ip_network('::1/128')
+ ne = NetworkEnvironment(ns, '../build/network-environment.yaml')
+ regstr = ne['resource_registry'][next(iter(TENANT_RESOURCES.keys()))]
+ assert_equal(regstr.split('/')[-1], 'tenant_v6.yaml')
+
+ # Test removing PRIVATE_NETWORK
+ ns.enabled_network_list.remove(PRIVATE_NETWORK)
+ ne = NetworkEnvironment(ns, '../build/network-environment.yaml')
+ regstr = ne['resource_registry'][next(iter(TENANT_RESOURCES.keys()))]
+ assert_equal(regstr.split('/')[-1], 'noop.yaml')
+
+ def test_netenv_settings_storage_network(self):
+ ns = NetworkSettings('../config/network/network_settings.yaml', True)
+ # test vlans
+ ns[STORAGE_NETWORK]['vlan'] = 100
+ ne = NetworkEnvironment(ns, '../build/network-environment.yaml')
+ assert_equal(ne['parameter_defaults']['StorageNetworkVlanID'], 100)
+
+ # Test IPv6
+ ns[STORAGE_NETWORK]['cidr'] = ipaddress.ip_network('::1/128')
+ ne = NetworkEnvironment(ns, '../build/network-environment.yaml')
+ regstr = ne['resource_registry'][next(iter(STORAGE_RESOURCES.keys()))]
+ assert_equal(regstr.split('/')[-1], 'storage_v6.yaml')
+
+ # Test removing STORAGE_NETWORK
+ ns.enabled_network_list.remove(STORAGE_NETWORK)
+ ne = NetworkEnvironment(ns, '../build/network-environment.yaml')
+ regstr = ne['resource_registry'][next(iter(STORAGE_RESOURCES.keys()))]
+ assert_equal(regstr.split('/')[-1], 'noop.yaml')
+
+ def test_netenv_settings_api_network(self):
+ ns = NetworkSettings('../config/network/network_settings.yaml', True)
+ # test vlans
+ ns.enabled_network_list.append(API_NETWORK)
+ ns[API_NETWORK] = {'vlan': 100,
+ 'cidr': ipaddress.ip_network('10.10.10.0/24'),
+ 'usable_ip_range': '10.10.10.10,10.10.10.100'}
+ ne = NetworkEnvironment(ns, '../build/network-environment.yaml')
+ assert_equal(ne['parameter_defaults']['InternalApiNetworkVlanID'], 100)
+
+ # Test IPv6
+ ns[API_NETWORK]['cidr'] = ipaddress.ip_network('::1/128')
+ ne = NetworkEnvironment(ns, '../build/network-environment.yaml')
+ regstr = ne['resource_registry'][next(iter(API_RESOURCES.keys()))]
+ assert_equal(regstr.split('/')[-1], 'internal_api_v6.yaml')
+
+ # Test removing API_NETWORK
+ ns.enabled_network_list.remove(API_NETWORK)
+ ne = NetworkEnvironment(ns, '../build/network-environment.yaml')
+ regstr = ne['resource_registry'][next(iter(API_RESOURCES.keys()))]
+ assert_equal(regstr.split('/')[-1], 'noop.yaml')
+
+ def test_numa_configs(self):
ns = NetworkSettings('../config/network/network_settings.yaml', True)
ne = NetworkEnvironment(ns, '../build/network-environment.yaml',
compute_pre_config=True,
controller_pre_config=True)
assert_is_instance(ne, dict)
assert_not_equal(ne, {})
+
+ def test_exception(self):
+ e = NetworkEnvException("test")
+ print(e)
+ assert_is_instance(e, NetworkEnvException)