Merge "Update the nfv tosca definietion against the latest spec"
[parser.git] / tosca2heat / heat-translator / translator / hot / tosca / tests / test_tosca_objectstore.py
1 #    Licensed under the Apache License, Version 2.0 (the "License"); you may
2 #    not use this file except in compliance with the License. You may obtain
3 #    a copy of the License at
4 #
5 #         http://www.apache.org/licenses/LICENSE-2.0
6 #
7 #    Unless required by applicable law or agreed to in writing, software
8 #    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
9 #    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
10 #    License for the specific language governing permissions and limitations
11 #    under the License.
12
13 from toscaparser.nodetemplate import NodeTemplate
14 from toscaparser.tests.base import TestCase
15 from toscaparser.utils.gettextutils import _
16 import toscaparser.utils.yamlparser
17 from translator.hot.tosca.tosca_object_storage import ToscaObjectStorage
18
19
20 class ToscaObjectStoreTest(TestCase):
21
22     def _tosca_objectstore_test(self, tpl_snippet, expectedprops):
23         nodetemplates = (toscaparser.utils.yamlparser.
24                          simple_parse(tpl_snippet)['node_templates'])
25         name = list(nodetemplates.keys())[0]
26         try:
27             nodetemplate = NodeTemplate(name, nodetemplates)
28             tosca_object_store = ToscaObjectStorage(nodetemplate)
29             tosca_object_store.handle_properties()
30             if not self._compare_properties(tosca_object_store.properties,
31                                             expectedprops):
32                 raise Exception(_("Hot Properties are not"
33                                   " same as expected properties"))
34         except Exception:
35             # for time being rethrowing. Will be handled future based
36             # on new development
37             raise
38
39     def _compare_properties(self, hotprops, expectedprops):
40         return all(item in hotprops.items() for item in expectedprops.items())
41
42     def test_node_objectstorage_with_properties(self):
43         tpl_snippet = '''
44         node_templates:
45           server:
46             type: tosca.nodes.ObjectStorage
47             properties:
48               name: test
49               size: 1024 KB
50               maxsize: 1 MB
51         '''
52         expectedprops = {'name': 'test',
53                          'X-Container-Meta': {'Quota-Bytes': 1000000}}
54         self._tosca_objectstore_test(
55             tpl_snippet,
56             expectedprops)
57
58     def test_node_objectstorage_with_few_properties(self):
59         tpl_snippet = '''
60         node_templates:
61           server:
62             type: tosca.nodes.ObjectStorage
63             properties:
64               name: test
65               size: 1024 B
66         '''
67         expectedprops = {'name': 'test',
68                          'X-Container-Meta': {'Quota-Bytes': 1024}}
69         self._tosca_objectstore_test(
70             tpl_snippet,
71             expectedprops)