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 apex.inventory import Inventory
13 from apex.inventory import InventoryException
15 from nose.tools import assert_is_instance
16 from nose.tools import assert_raises
17 from nose.tools import assert_equal
18 from nose.tools import assert_regexp_matches
19 from io import StringIO
21 inventory_files = ('intel_pod2_settings.yaml',
22 'nokia_pod1_settings.yaml',
23 'pod_example_settings.yaml')
26 class TestInventory(object):
28 def setup_class(klass):
29 """This method is run once for each class before any tests are run"""
32 def teardown_class(klass):
33 """This method is run once for each class _after_ all tests are run"""
36 """This method is run once before _each_ test method is executed"""
39 """This method is run once after _each_ test method is executed"""
42 for f in inventory_files:
43 i = Inventory('../config/inventory/{}'.format(f))
44 assert_equal(i.dump_instackenv_json(), None)
47 i = Inventory(i, virtual=True)
48 assert_equal(i.dump_instackenv_json(), None)
50 # Remove nodes to violate HA node count
51 while len(i['nodes']) >= 5:
53 assert_raises(InventoryException,
56 # Remove nodes to violate non-HA node count
57 while len(i['nodes']) >= 2:
59 assert_raises(InventoryException,
60 Inventory, i, ha=False)
62 def test_exception(sefl):
63 e = InventoryException("test")
65 assert_is_instance(e, InventoryException)
67 def test_dump_bash_default(self):
68 i = Inventory('../config/inventory/intel_pod2_settings.yaml')
72 output = out.getvalue().strip()
73 assert_regexp_matches(output, 'root_disk_list=sda')
75 def test_dump_bash_set_root_device(self):
76 i = Inventory('../config/inventory/pod_example_settings.yaml')
80 output = out.getvalue().strip()
81 assert_regexp_matches(output, 'root_disk_list=sdb')