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 ##############################################################################
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
21 from nose.tools import assert_equal
22 from nose.tools import assert_raises
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'
32 class TestCommonUtils(object):
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()
40 def teardown_class(klass):
41 """This method is run once for each class _after_ all tests are run"""
44 """This method is run once before _each_ test method is executed"""
47 """This method is run once after _each_ test method is executed"""
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',
57 assert_equal(main(), None)
59 def test_parse_net_settings(self):
60 args = self.parser.parse_args(['parse-net-settings',
64 assert_equal(parse_net_settings(args), None)
66 def test_parse_deploy_settings(self):
67 args = self.parser.parse_args(['parse-deploy-settings',
69 assert_equal(parse_deploy_settings(args), None)
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)
76 def test_build_nic_template(self):
77 args = self.parser.parse_args(['nic-template',
81 assert_equal(build_nic_template(args), None)
83 def test_parse_inventory(self):
84 args = self.parser.parse_args(['parse-inventory',
86 assert_equal(parse_inventory(args), None)