Updating OpenDaylight image script to use RDO trunk BGPVPN package.
[apex.git] / tests / test_apex_inventory.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 from apex.inventory import Inventory
11 from apex.inventory import InventoryException
12
13 from nose.tools import assert_is_instance
14 from nose.tools import assert_raises
15 from nose.tools import assert_equal
16
17 inventory_files = ('intel_pod2_settings.yaml',
18                    'nokia_pod1_settings.yaml',
19                    'pod_example_settings.yaml')
20
21
22 class TestInventory(object):
23     @classmethod
24     def setup_class(klass):
25         """This method is run once for each class before any tests are run"""
26
27     @classmethod
28     def teardown_class(klass):
29         """This method is run once for each class _after_ all tests are run"""
30
31     def setUp(self):
32         """This method is run once before _each_ test method is executed"""
33
34     def teardown(self):
35         """This method is run once after _each_ test method is executed"""
36
37     def test_init(self):
38         for f in inventory_files:
39             i = Inventory('../config/inventory/{}'.format(f))
40             assert_equal(i.dump_instackenv_json(), None)
41
42         # test virtual
43         i = Inventory(i, virtual=True)
44         assert_equal(i.dump_instackenv_json(), None)
45
46         # Remove nodes to violate HA node count
47         while len(i['nodes']) >= 5:
48             i['nodes'].pop()
49         assert_raises(InventoryException,
50                       Inventory, i)
51
52         # Remove nodes to violate non-HA node count
53         while len(i['nodes']) >= 2:
54             i['nodes'].pop()
55         assert_raises(InventoryException,
56                       Inventory, i, ha=False)
57
58     def test_exception(sefl):
59         e = InventoryException("test")
60         print(e)
61         assert_is_instance(e, InventoryException)