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