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