[VVP] update PLATFORM PROVIDED param in env check
[vvp/validation-scripts.git] / ice_validator / tests / test_nesting_nova_server.py
1 # -*- coding: utf8 -*-
2 # ============LICENSE_START====================================================
3 # org.onap.vvp/validation-scripts
4 # ===================================================================
5 # Copyright © 2017 AT&T Intellectual Property. All rights reserved.
6 # ===================================================================
7 #
8 # Unless otherwise specified, all software contained herein is licensed
9 # under the Apache License, Version 2.0 (the "License");
10 # you may not use this software except in compliance with the License.
11 # You may obtain a copy of the License at
12 #
13 #             http://www.apache.org/licenses/LICENSE-2.0
14 #
15 # Unless required by applicable law or agreed to in writing, software
16 # distributed under the License is distributed on an "AS IS" BASIS,
17 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 # See the License for the specific language governing permissions and
19 # limitations under the License.
20 #
21 #
22 #
23 # Unless otherwise specified, all documentation contained herein is licensed
24 # under the Creative Commons License, Attribution 4.0 Intl. (the "License");
25 # you may not use this documentation except in compliance with the License.
26 # You may obtain a copy of the License at
27 #
28 #             https://creativecommons.org/licenses/by/4.0/
29 #
30 # Unless required by applicable law or agreed to in writing, documentation
31 # distributed under the License is distributed on an "AS IS" BASIS,
32 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
33 # See the License for the specific language governing permissions and
34 # limitations under the License.
35 #
36 # ============LICENSE_END============================================
37 #
38 #
39
40 """
41 test nesting level
42 0 -> 1 -> 2 -> too many levels.
43 """
44
45 import pytest
46
47 from .utils import nested_files
48 from .helpers import validates
49
50 VERSION = "1.0.0"
51
52
53 def get_nova_server_count(heat):
54     """return the number of OS::Nova::Server
55     resources in heat
56     """
57     return len(heat.get_resource_by_type("OS::Nova::Server"))
58
59
60 # pylint: disable=invalid-name
61
62
63 @validates("R-17528")
64 def test_nesting_nova_server(yaml_files):
65     """
66     A VNF's Heat Orchestration Template's first level Nested YAML file
67     **MUST NOT** contain more than one ``OS::Nova::Server`` resource.
68     A VNF's Heat Orchestration Template's second level Nested YAML file
69     **MUST NOT** contain an ``OS::Nova::Server`` resource.
70
71     level: 0    1         2         3
72     template -> nested -> nested -> too many levels
73     """
74     bad, __, heat, depths = nested_files.get_nesting(yaml_files)
75     if bad:
76         pytest.skip("nesting depth exceeded")
77     for parent, depth in depths.items():
78         for depth_tuple in depth:
79             depth, context = depth_tuple
80             if depth > 1:
81                 fname = context[0]
82                 nservers = get_nova_server_count(heat[fname])
83                 if nservers > 1:
84                     bad.append(
85                         "nested template %s must have only have 1 "
86                         "OS::Nova::Server defined, but %s were found"
87                         % (fname, nservers)
88                     )
89             if depth > 2:
90                 fname = context[1]
91                 nservers = get_nova_server_count(heat[fname])
92                 if nservers > 0:
93                     bad.append(
94                         "nested template %s must not have an "
95                         "OS::Nova::Server defined, but %s were found"
96                         % (fname, nservers)
97                     )
98     assert not bad, "; ".join(bad)