Initial commit
[ta/storage.git] / partfs_rootdisk / tests / localstorage_test.py
1 # Copyright 2019 Nokia
2   
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 #     http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14 import unittest
15 import json
16 import jinja2
17 from ansible.plugins.filter.core import regex_search
18
19
20 class LocalstorageTest(unittest.TestCase):
21
22     def setUp(self):
23         env = jinja2.Environment(
24            loader=jinja2.FileSystemLoader('./role/templates')
25            )
26         env.filters['search'] = regex_search
27         env.tests['search'] = regex_search
28         self.template = env.get_template('localstorage.j2')
29
30     def ordered(self, obj):
31         if isinstance(obj, dict):
32             return sorted((k, self.ordered(v)) for k, v in obj.items())
33         if isinstance(obj, list):
34             return sorted(self.ordered(x) for x in obj)
35         return obj
36
37     def verify(self, usecase):
38         with open('./tests/inputs/%s.json' % usecase) as data:
39             inventory = json.load(data)
40         rendered = self.template.render(inventory)
41         actual = json.loads(rendered)
42         with open('./tests/outputs/%s.json' % usecase) as data:
43             expected = json.load(data)
44         self.assertEqual(self.ordered(actual), self.ordered(expected))
45
46     def test_single_profile(self):
47         self.verify('single_profile')
48
49     def test_double_profile(self):
50         self.verify('double_profile')
51
52     def test_triple_profile(self):
53         self.verify('triple_profile')
54
55     def test_missing_volume(self):
56         self.verify('missing_volume')
57
58     def test_missing_volume2(self):
59         self.verify('missing_volume2')
60
61     def test_fewer_partition(self):
62         self.verify('fewer_partition')
63
64     def test_multinode_hybrid1(self):
65         self.verify('multinode_hybrid1')
66
67     def test_multinode_hybrid2(self):
68         self.verify('multinode_hybrid2')
69
70     def test_multinode_hybrid3(self):
71         self.verify('multinode_hybrid3')
72
73     def test_multinode_hybrid4(self):
74         self.verify('multinode_hybrid4')
75
76     def test_multinode_hybrid5(self):
77         self.verify('multinode_hybrid5')
78
79     def test_multinode_hybrid6(self):
80         self.verify('multinode_hybrid6')
81
82     def test_multinode_hybrid7(self):
83         self.verify('multinode_hybrid7')
84
85     def test_multinode_hybrid8(self):
86         self.verify('multinode_hybrid8')
87
88     def test_multinode_hybrid9(self):
89         self.verify('multinode_hybrid9')
90
91 if __name__ == '__main__':
92     unittest.main()