Updates to Inventory object
[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 ApexInventoryException
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             i['nodes'][0]['arch'] = 'aarch64'
51             i = Inventory(i)
52             assert_equal(i['nodes'][0]['arch'], 'aarch64')
53
54     def test_inventory_invalid_ha_count(self):
55         assert_raises(ApexInventoryException, Inventory,
56                       os.path.join(TEST_DUMMY_CONFIG, 'inventory-virt.yaml'),
57                       virtual=True, ha=True)
58
59     def test_inventory_invalid_noha_count(self):
60         assert_raises(ApexInventoryException, Inventory,
61                       os.path.join(TEST_DUMMY_CONFIG,
62                                    'inventory-virt-1-node.yaml'),
63                       virtual=True, ha=False)
64
65     def test_inventory_virtual(self):
66         i = Inventory(os.path.join(TEST_DUMMY_CONFIG, 'inventory-virt.yaml'),
67                       virtual=True, ha=False)
68         assert_equal(i.dump_instackenv_json(), None)
69
70     def test_get_node_counts(self):
71         i = Inventory(os.path.join(TEST_DUMMY_CONFIG, 'inventory-virt.yaml'),
72                       virtual=True, ha=False)
73         assert_equal(i.get_node_counts(), (1, 1))