Bumps OVS version to 2.8 for OVN
[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 import sys
11
12 from apex.inventory import Inventory
13 from apex.inventory import InventoryException
14
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
20
21 inventory_files = ('intel_pod2_settings.yaml',
22                    'nokia_pod1_settings.yaml',
23                    'pod_example_settings.yaml')
24
25
26 class TestInventory(object):
27     @classmethod
28     def setup_class(klass):
29         """This method is run once for each class before any tests are run"""
30
31     @classmethod
32     def teardown_class(klass):
33         """This method is run once for each class _after_ all tests are run"""
34
35     def setUp(self):
36         """This method is run once before _each_ test method is executed"""
37
38     def teardown(self):
39         """This method is run once after _each_ test method is executed"""
40
41     def test_init(self):
42         for f in inventory_files:
43             i = Inventory('../config/inventory/{}'.format(f))
44             assert_equal(i.dump_instackenv_json(), None)
45
46         # test virtual
47         i = Inventory(i, virtual=True)
48         assert_equal(i.dump_instackenv_json(), None)
49
50         # Remove nodes to violate HA node count
51         while len(i['nodes']) >= 5:
52             i['nodes'].pop()
53         assert_raises(InventoryException,
54                       Inventory, i)
55
56         # Remove nodes to violate non-HA node count
57         while len(i['nodes']) >= 2:
58             i['nodes'].pop()
59         assert_raises(InventoryException,
60                       Inventory, i, ha=False)
61
62     def test_exception(sefl):
63         e = InventoryException("test")
64         print(e)
65         assert_is_instance(e, InventoryException)
66
67     def test_dump_bash_default(self):
68         i = Inventory('../config/inventory/intel_pod2_settings.yaml')
69         out = StringIO()
70         sys.stdout = out
71         i.dump_bash()
72         output = out.getvalue().strip()
73         assert_regexp_matches(output, 'root_disk_list=sda')
74
75     def test_dump_bash_set_root_device(self):
76         i = Inventory('../config/inventory/pod_example_settings.yaml')
77         out = StringIO()
78         sys.stdout = out
79         i.dump_bash()
80         output = out.getvalue().strip()
81         assert_regexp_matches(output, 'root_disk_list=sdb')