summaryrefslogtreecommitdiffstats
path: root/tests/test_apex_python_utils_py.py
blob: 237c55893ad874ffe4d9c2816a5737cb61c877f9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
##############################################################################
# Copyright (c) 2016 Dan Radez (Red Hat)
#
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Apache License, Version 2.0
# which accompanies this distribution, and is available at
# http://www.apache.org/licenses/LICENSE-2.0
##############################################################################

import sys

from test_apex_ip_utils import get_default_gateway_linux
from apex_python_utils import main
from apex_python_utils import get_parser
from apex_python_utils import parse_net_settings
from apex_python_utils import parse_deploy_settings
from apex_python_utils import find_ip
from apex_python_utils import build_nic_template
from apex_python_utils import parse_inventory

from nose.tools import assert_equal
from nose.tools import assert_raises


net_sets = '../config/network/network_settings.yaml'
net_env = '../build/network-environment.yaml'
deploy_sets = '../config/deploy/deploy_settings.yaml'
nic_template = '../build/nics-template.yaml.jinja2'
inventory = '../config/inventory/pod_example_settings.yaml'


class TestCommonUtils(object):
    @classmethod
    def setup_class(klass):
        """This method is run once for each class before any tests are run"""
        klass.parser = get_parser()
        klass.iface_name = get_default_gateway_linux()

    @classmethod
    def teardown_class(klass):
        """This method is run once for each class _after_ all tests are run"""

    def setUp(self):
        """This method is run once before _each_ test method is executed"""

    def teardown(self):
        """This method is run once after _each_ test method is executed"""

    def test_main(self):
        sys.argv = ['apex_python_utils', '-l', '/dev/null']
        assert_raises(SystemExit, main)
        sys.argv = ['apex_python_utils', '--debug', '-l', '/dev/null']
        assert_raises(SystemExit, main)
        sys.argv = ['apex_python_utils', '-l', '/dev/null',
                                         'parse-deploy-settings',
                                         '-f', deploy_sets]
        assert_equal(main(), None)

    def test_parse_net_settings(self):
        args = self.parser.parse_args(['parse-net-settings',
                                       '-s', net_sets,
                                       '--flat',
                                       '-e', net_env])
        assert_equal(parse_net_settings(args), None)

    def test_parse_deploy_settings(self):
        args = self.parser.parse_args(['parse-deploy-settings',
                                       '-f', deploy_sets])
        assert_equal(parse_deploy_settings(args), None)

    def test_find_ip(self):
        args = self.parser.parse_args(['find-ip',
                                       '-i', self.iface_name])
        assert_equal(find_ip(args), None)

    def test_build_nic_template(self):
        args = self.parser.parse_args(['nic-template',
                                       '-s', net_sets,
                                       '-r', 'compute',
                                       '-t', nic_template])
        assert_equal(build_nic_template(args), None)

    def test_parse_inventory(self):
        args = self.parser.parse_args(['parse-inventory',
                                       '-f', inventory])
        assert_equal(parse_inventory(args), None)