1 ##############################################################################
2 # Copyright (c) 2017 Tim Rozet (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 ##############################################################################
12 from nose.tools import (
18 from apex.common.constants import (
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
28 files_dir = os.path.join(TEST_CONFIG_DIR, 'network')
38 class TestNetworkData:
41 """This method is run once for each class before any tests are run"""
44 def teardown_class(cls):
45 """This method is run once for each class _after_ all tests are run"""
48 """This method is run once before _each_ test method is executed"""
51 """This method is run once after _each_ test method is executed"""
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
60 assert_is_instance(net, dict)
61 for key in REQUIRED_KEYS:
63 if key == 'vip' or key == 'enabled':
64 assert_is_instance(net[key], bool)
66 assert net[key] is not None
68 def test_negative_create_network_data(self):
69 assert_raises(network_data.NetworkDataException,
70 network_data.create_network_data, 'blah')
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')