87e7d50bc538a6b267a8eed1b8fd5b86395228fc
[apex.git] / apex / 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 import os
11
12 from nose.tools import (
13     assert_equal,
14     assert_is_instance,
15     assert_raises)
16
17 from apex import Inventory
18 from apex.inventory.inventory import InventoryException
19 from apex.tests.constants import (
20     TEST_CONFIG_DIR,
21     TEST_DUMMY_CONFIG
22 )
23
24 inventory_files = ('intel_pod2_settings.yaml',
25                    'nokia_pod1_settings.yaml',
26                    'pod_example_settings.yaml')
27
28 files_dir = os.path.join(TEST_CONFIG_DIR, 'inventory')
29
30
31 class TestInventory:
32     @classmethod
33     def setup_class(cls):
34         """This method is run once for each class before any tests are run"""
35
36     @classmethod
37     def teardown_class(cls):
38         """This method is run once for each class _after_ all tests are run"""
39
40     def setup(self):
41         """This method is run once before _each_ test method is executed"""
42
43     def teardown(self):
44         """This method is run once after _each_ test method is executed"""
45
46     def test_inventory_baremetal(self):
47         for f in inventory_files:
48             i = Inventory(os.path.join(files_dir, f))
49             assert_equal(i.dump_instackenv_json(), None)
50
51     def test_inventory_invalid_ha_count(self):
52         assert_raises(InventoryException, Inventory,
53                       os.path.join(TEST_DUMMY_CONFIG, 'inventory-virt.yaml'),
54                       virtual=True, ha=True)
55
56     def test_inventory_invalid_noha_count(self):
57         assert_raises(InventoryException, Inventory,
58                       os.path.join(TEST_DUMMY_CONFIG,
59                                    'inventory-virt-1-node.yaml'),
60                       virtual=True, ha=False)
61
62     def test_inventory_virtual(self):
63         i = Inventory(os.path.join(TEST_DUMMY_CONFIG, 'inventory-virt.yaml'),
64                       virtual=True, ha=False)
65         assert_equal(i.dump_instackenv_json(), None)
66
67     def test_exception(self):
68         e = InventoryException("test")
69         print(e)
70         assert_is_instance(e, InventoryException)