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 ##############################################################################
13 from apex.common import utils
14 from apex.settings.network_settings import NetworkSettings
15 from apex.tests.constants import (
19 from nose.tools import (
22 assert_not_is_instance,
25 NET_SETS = os.path.join(TEST_CONFIG_DIR, 'network', 'network_settings.yaml')
28 class TestCommonUtils:
31 """This method is run once for each class before any tests are run"""
34 def teardown_class(cls):
35 """This method is run once for each class _after_ all tests are run"""
38 """This method is run once before _each_ test method is executed"""
41 """This method is run once after _each_ test method is executed"""
43 def test_str2bool(self):
44 assert_equal(utils.str2bool(True), True)
45 assert_equal(utils.str2bool(False), False)
46 assert_equal(utils.str2bool("True"), True)
47 assert_equal(utils.str2bool("YES"), True)
49 def test_parse_yaml(self):
50 assert_is_instance(utils.parse_yaml(NET_SETS), dict)
52 def test_dict_to_string(self):
53 net_settings = NetworkSettings(NET_SETS)
54 output = utils.dict_objects_to_str(net_settings)
55 assert_is_instance(output, dict)
56 for k, v in output.items():
57 assert_is_instance(k, str)
58 assert_not_is_instance(v, ipaddress.IPv4Address)
60 def test_run_ansible(self):
61 playbook = 'apex/tests/playbooks/test_playbook.yaml'
62 assert_equal(utils.run_ansible(None, os.path.join(playbook),
65 def test_failed_run_ansible(self):
66 playbook = 'apex/tests/playbooks/test_failed_playbook.yaml'
67 assert_raises(Exception, utils.run_ansible, None,
68 os.path.join(playbook), dry_run=True)