1 ##############################################################################
2 # Copyright (c) 2016 Dan Radez (Red Hat)
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 ##############################################################################
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
23 from nose.tools import assert_equal
24 from nose.tools import assert_raises
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'
34 class TestCommonUtils(object):
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()
42 def teardown_class(klass):
43 """This method is run once for each class _after_ all tests are run"""
46 """This method is run once before _each_ test method is executed"""
49 """This method is run once after _each_ test method is executed"""
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',
59 assert_equal(main(), None)
61 def test_parse_net_settings(self):
62 tmp_dir = tempfile.mkdtemp()
63 args = self.parser.parse_args(['parse-net-settings',
67 assert_equal(parse_net_settings(args), None)
68 shutil.rmtree(tmp_dir, ignore_errors=True)
70 def test_parse_deploy_settings(self):
71 args = self.parser.parse_args(['parse-deploy-settings',
73 assert_equal(parse_deploy_settings(args), None)
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)
80 def test_build_nic_template(self):
81 args = self.parser.parse_args(['nic-template',
85 '--deploy-settings-file', deploy_sets])
86 assert_equal(build_nic_template(args), None)
88 def test_parse_inventory(self):
89 args = self.parser.parse_args(['parse-inventory',
91 assert_equal(parse_inventory(args), None)