Generalization of recursive function
[apex.git] / apex / tests / test_apex_common_parsers.py
1 ##############################################################################
2 # Copyright (c) 2016 Dan Radez (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 apex.tests import constants as con
13 from apex.common import parsers as apex_parsers
14 from apex.common.exceptions import ApexDeployException
15 from nose.tools import (
16     assert_is_instance,
17     assert_dict_equal,
18     assert_raises
19 )
20
21
22 class TestCommonParsers:
23     @classmethod
24     def setup_class(cls):
25         """This method is run once for each class before any tests are run"""
26
27     @classmethod
28     def teardown_class(cls):
29         """This method is run once for each class _after_ all tests are run"""
30
31     def setup(self):
32         """This method is run once before _each_ test method is executed"""
33
34     def teardown(self):
35         """This method is run once after _each_ test method is executed"""
36
37     def test_parse_nova_output(self):
38         output = apex_parsers.parse_nova_output(
39             os.path.join(con.TEST_DUMMY_CONFIG, 'nova_output.json'))
40         assert_is_instance(output, dict)
41         nodes = {
42             'overcloud-controller-0': '192.30.9.8',
43             'overcloud-novacompute-0': '192.30.9.10',
44             'overcloud-novacompute-1': '192.30.9.9'
45         }
46         assert_dict_equal(output, nodes)
47
48     def test_negative_parse_nova_output(self):
49         assert_raises(ApexDeployException, apex_parsers.parse_nova_output,
50                       os.path.join(con.TEST_DUMMY_CONFIG,
51                                    'bad_nova_output.json'))
52
53     def test_parse_overcloudrc(self):
54         output = apex_parsers.parse_overcloudrc(
55             os.path.join(con.TEST_DUMMY_CONFIG, 'test_overcloudrc'))
56         assert_is_instance(output, dict)
57         assert 'OS_AUTH_TYPE' in output.keys()
58         assert output['OS_AUTH_TYPE'] == 'password'
59         assert 'OS_PASSWORD' in output.keys()
60         assert output['OS_PASSWORD'] == 'Wd8ruyf6qG8cmcms6dq2HM93f'
61
62     def test_parse_ifcfg(self):
63         output = apex_parsers.parse_ifcfg_file(
64             os.path.join(con.TEST_DUMMY_CONFIG, 'ifcfg-br-external'))
65         assert_is_instance(output, dict)
66         assert 'IPADDR' in output.keys()
67         assert output['IPADDR'] == '172.30.9.66'
68         assert 'NETMASK' in output.keys()
69         assert output['NETMASK'] == '255.255.255.0'
70         assert 'DNS1' in output.keys()
71         assert not output['DNS1']