Adds ability to deploy from upstream openstack
[apex.git] / apex / tests / test_apex_network_data.py
1 ##############################################################################
2 # Copyright (c) 2017 Tim Rozet (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 os
11
12 from nose.tools import (
13     assert_equal,
14     assert_is_instance,
15     assert_raises
16 )
17
18 from apex.common.constants import (
19     EXTERNAL_NETWORK,
20     STORAGE_NETWORK,
21     ADMIN_NETWORK,
22 )
23 from apex import NetworkSettings
24 from apex.network import network_data
25 from apex.settings.network_settings import NetworkSettingsException
26 from apex.tests.constants import TEST_CONFIG_DIR
27
28 files_dir = os.path.join(TEST_CONFIG_DIR, 'network')
29
30 REQUIRED_KEYS = [
31     'name',
32     'vip',
33     'name_lower',
34     'enabled'
35 ]
36
37
38 class TestNetworkData:
39     @classmethod
40     def setup_class(cls):
41         """This method is run once for each class before any tests are run"""
42
43     @classmethod
44     def teardown_class(cls):
45         """This method is run once for each class _after_ all tests are run"""
46
47     def setup(self):
48         """This method is run once before _each_ test method is executed"""
49
50     def teardown(self):
51         """This method is run once after _each_ test method is executed"""
52
53     def test_create_network_data(self):
54         ns = NetworkSettings(os.path.join(files_dir, 'network_settings.yaml'))
55         output = network_data.create_network_data(ns)
56         assert_is_instance(output, list)
57         # TODO(trozet) change this back to 4 after OOO bug is fixed
58         assert len(output) is 5
59         for net in output:
60             assert_is_instance(net, dict)
61             for key in REQUIRED_KEYS:
62                 assert key in net
63                 if key == 'vip' or key == 'enabled':
64                     assert_is_instance(net[key], bool)
65                 else:
66                     assert net[key] is not None
67
68     def test_negative_create_network_data(self):
69         assert_raises(network_data.NetworkDataException,
70                       network_data.create_network_data, 'blah')
71
72     def test_create_network_data_with_write(self):
73         ns = NetworkSettings(os.path.join(files_dir, 'network_settings.yaml'))
74         network_data.create_network_data(ns, '/tmp/blah_network_data.yaml')
75         assert os.path.isfile('/tmp/blah_network_data.yaml')
76         os.remove('/tmp/blah_network_data.yaml')