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
20 from nose.tools import assert_equal
21 from nose.tools import assert_raises
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'
30 class TestCommonUtils(object):
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()
38 def teardown_class(klass):
39 """This method is run once for each class _after_ all tests are run"""
42 """This method is run once before _each_ test method is executed"""
45 """This method is run once after _each_ test method is executed"""
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',
55 assert_equal(main(), None)
57 def test_parse_net_settings(self):
58 args = self.parser.parse_args(['parse-net-settings',
62 assert_equal(parse_net_settings(args), None)
64 def test_parse_deploy_settings(self):
65 args = self.parser.parse_args(['parse-deploy-settings',
67 assert_equal(parse_deploy_settings(args), None)
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)
74 def test_build_nic_template(self):
75 args = self.parser.parse_args(['nic-template',
79 '-n', 'admin_network'])
80 assert_equal(build_nic_template(args), None)