Fixes sdnvpn (again)
[apex.git] / tests / test_apex_python_utils_py.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 sys
11
12 from test_apex_ip_utils import get_default_gateway_linux
13 from apex_python_utils import main
14 from apex_python_utils import get_parser
15 from apex_python_utils import parse_net_settings
16 from apex_python_utils import parse_deploy_settings
17 from apex_python_utils import find_ip
18 from apex_python_utils import build_nic_template
19
20 from nose.tools import assert_equal
21 from nose.tools import assert_raises
22
23
24 net_sets = '../config/network/network_settings.yaml'
25 net_env = '../build/network-environment.yaml'
26 deploy_sets = '../config/deploy/deploy_settings.yaml'
27 nic_template = '../build/nics-template.yaml.jinja2'
28
29
30 class TestCommonUtils(object):
31     @classmethod
32     def setup_class(klass):
33         """This method is run once for each class before any tests are run"""
34         klass.parser = get_parser()
35         klass.iface_name = get_default_gateway_linux()
36
37     @classmethod
38     def teardown_class(klass):
39         """This method is run once for each class _after_ all tests are run"""
40
41     def setUp(self):
42         """This method is run once before _each_ test method is executed"""
43
44     def teardown(self):
45         """This method is run once after _each_ test method is executed"""
46
47     def test_main(self):
48         sys.argv = ['apex_python_utils', '-l', '/dev/null']
49         assert_raises(SystemExit, main)
50         sys.argv = ['apex_python_utils', '--debug', '-l', '/dev/null']
51         assert_raises(SystemExit, main)
52         sys.argv = ['apex_python_utils', '-l', '/dev/null',
53                                          'parse-deploy-settings',
54                                          '-f', deploy_sets]
55         assert_equal(main(), None)
56
57     def test_parse_net_settings(self):
58         args = self.parser.parse_args(['parse-net-settings',
59                                        '-s', net_sets,
60                                        '--flat',
61                                        '-e', net_env])
62         assert_equal(parse_net_settings(args), None)
63
64     def test_parse_deploy_settings(self):
65         args = self.parser.parse_args(['parse-deploy-settings',
66                                        '-f', deploy_sets])
67         assert_equal(parse_deploy_settings(args), None)
68
69     def test_find_ip(self):
70         args = self.parser.parse_args(['find-ip',
71                                        '-i', self.iface_name])
72         assert_equal(find_ip(args), None)
73
74     def test_build_nic_template(self):
75         args = self.parser.parse_args(['nic-template',
76                                        '-s', net_sets,
77                                        '-r', 'compute',
78                                        '-t', nic_template,
79                                        '-n', 'admin_network'])
80         assert_equal(build_nic_template(args), None)