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 io import StringIO
14 from nose.tools import assert_equal
15 from nose.tools import assert_is_instance
16 from nose.tools import assert_raises
17 from nose.tools import assert_regexp_matches
19 from apex import Inventory
20 from apex.inventory.inventory import InventoryException
21 from apex.tests.constants import TEST_CONFIG_DIR
23 inventory_files = ('intel_pod2_settings.yaml',
24 'nokia_pod1_settings.yaml',
25 'pod_example_settings.yaml')
27 files_dir = os.path.join(TEST_CONFIG_DIR, 'inventory')
30 class TestInventory(object):
32 def setup_class(klass):
33 """This method is run once for each class before any tests are run"""
36 def teardown_class(klass):
37 """This method is run once for each class _after_ all tests are run"""
40 """This method is run once before _each_ test method is executed"""
43 """This method is run once after _each_ test method is executed"""
46 for f in inventory_files:
47 i = Inventory(os.path.join(files_dir, f))
48 assert_equal(i.dump_instackenv_json(), None)
51 i = Inventory(i, virtual=True)
52 assert_equal(i.dump_instackenv_json(), None)
54 # Remove nodes to violate HA node count
55 while len(i['nodes']) >= 5:
57 assert_raises(InventoryException,
60 # Remove nodes to violate non-HA node count
61 while len(i['nodes']) >= 2:
63 assert_raises(InventoryException,
64 Inventory, i, ha=False)
66 def test_exception(self):
67 e = InventoryException("test")
69 assert_is_instance(e, InventoryException)