[VVP] udpating scripts for casablanca 2
[vvp/validation-scripts.git] / ice_validator / tests / test_heat_template_structure.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 # ECOMP is a trademark and service mark of AT&T Intellectual Property.
39 #
40
41 """Test heat template structure
42 """
43
44 from tests import cached_yaml as yaml
45 from .helpers import validates
46
47 VERSION = '1.2.0'
48
49 # pylint: disable=invalid-name
50
51
52 @validates('R-27078')
53 def test_heat_template_structure_contains_heat_template_version(yaml_file):
54     '''
55     Check that all heat templates have the required sections
56     '''
57     required_key_values = ["heat_template_version"]
58
59     with open(yaml_file) as fh:
60         yml = yaml.load(fh)
61     assert all([k in yml for k in required_key_values]), (
62         "{} doesn't contain the {} section, but it is required"
63         .format(yaml_file, required_key_values[0]))
64
65
66 @validates('R-39402')
67 def test_heat_template_structure_contains_description(yaml_file):
68     '''
69     Check that all heat templates have the required sections
70     '''
71     required_key_values = ["description"]
72
73     with open(yaml_file) as fh:
74         yml = yaml.load(fh)
75     assert all([k in yml for k in required_key_values]), (
76         "{} doesn't contain the {} section, but it is required"
77         .format(yaml_file, required_key_values[0]))
78
79
80 @validates('R-35414')
81 def test_heat_template_structure_contains_parameters(yaml_file):
82     '''
83     Check that all heat templates have the required sections
84     '''
85     required_key_values = ["parameters"]
86
87     with open(yaml_file) as fh:
88         yml = yaml.load(fh)
89     assert all([k in yml for k in required_key_values]), (
90         "{} doesn't contain the {} section, but it is required"
91         .format(yaml_file, required_key_values[0]))
92
93
94 @validates('R-23664')
95 def test_heat_template_structure_contains_resources(heat_template):
96     '''
97     Check that all heat templates have the required sections
98     '''
99     required_key_values = ["resources"]
100
101     with open(heat_template) as fh:
102         yml = yaml.load(fh)
103     assert all([k in yml for k in required_key_values]), (
104         "{} doesn't contain the {} section, but it is required"
105         .format(heat_template, required_key_values[0]))
106
107
108 @validates('R-11441')
109 def test_parameter_type(yaml_file):
110     '''A VNF's Heat Orchestration Template's parameter type **MUST**
111     be one of the following values:
112     '''
113     types = ['string',
114              'number',
115              'json',
116              'comma_delimited_list',
117              'boolean']
118     with open(yaml_file) as fh:
119         yml = yaml.load(fh)
120     for key, param in yml.get('parameters', {}).items():
121         assert isinstance(param, dict), '%s parameter %s is not dict' % (
122             yaml_file,
123             key)
124         assert 'type' in param, '%s parameter %s has no "type"' % (
125             yaml_file,
126             key)
127         typ = param['type']
128         assert typ in types, '%s parameter %s has invalid type "%s"' % (
129             yaml_file,
130             key,
131             typ)
132