Newer
Older
#!/bin/bash
import doc2tosca as d2t
def test_match_definition_incipit():
assert d2t.match_definition_incipit("tosca.")
assert d2t.match_definition_incipit("tosca.definitions")
assert not d2t.match_definition_incipit("<node_template>")
def test_parse_versione_from_filename():
'''
Test parsing version out of filenames
'''
assert d2t.parse_version_from_filename("gs_NFV-SOL001v020601p.docx") == "v2.6.1"
assert d2t.parse_version_from_filename("gs_nfv-sol001v020801p.docx") == "v2.8.1"
def test_is_lvl1_section_hdn():
assert d2t.is_lvl1_section_hdn("6\tVNFD TOSCA model")
assert d2t.is_lvl1_section_hdn("Annex A (informative)")
assert d2t.is_lvl1_section_hdn("Annex C (normative):\tConformance\t284")
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
def test_section_init():
ssss = d2t.Section(0, 10, "6\tVNFD TOSCA model")
assert ssss.number == 6
assert ssss.title == "VNFD TOSCA model"
assert not ssss.is_annex
aaaa = d2t.Section(11, 20, "Annex A (informative): My title")
assert aaaa.is_annex
assert aaaa.title == "My title"
assert aaaa.letter == "A"
def test_is_example_start():
assert d2t.is_start_of_example("tosca_definitions_version: tosca_simple_yaml_1_1")
txt = '''
The contents of MyExampleNs_Type.yaml file with the node type definition are as follows:
tosca_definitions_version: tosca_simple_yaml_1_2
description: type definition of tosca.MyExampleNS
imports:
- etsi_nfv_sol001_nsd_types.yaml # all of TOSCA types as defined in ETSI GS NFVSOL 001
node_types:
tosca.MyExampleNS:
derived_from: tosca.nodes.nfv.NS
properties:
descriptor_id:
type: string
constraints: [ valid_values: [ b1bb0ce7-ebca-4fa7-95ed-4840d70a1177 ] ]
default: b1bb0ce7-ebca-4fa7-95ed-4840d70a1177
designer:
type: string
constraints: [ valid_values: [ MyCompany] ]
default: MyCompany
name:
type: string
constraints: [ valid_values: [ ExampleService ] ]
default: ExampleService
version:
type: string
constraints: [ valid_values: [ '1.0' ] ]
default: '1.0'
invariant_id:
type: string
constraints: [ valid_values: [ 1111-2222-aaaa-bbbb ] ]
default: 1111-2222-aaaa-bbbb
flavour_id:
type: string
constraints: [ valid_values: [ small, big ] ]
default: small
requirements:
- virtual_link:
capability: tosca.capabilities.nfv.VirtualLinkable
interfaces:
Nslcm:
type: tosca.interfaces.nfv.Nslcm
The following snippet shows the service template representing the NSD NS_2. In this example, NS_2 supports one single deployment flavour.
MyExampleNS_2.yaml:
tosca_definitions_version: tosca_simple_yaml_1_1
description: Relational database, simple
imports:
- etsi_nfv_sol001_nsd_types.yaml # all of NSD related TOSCA types as defined in ETSI GS NFV-SOL 001
- example_VNF3.yaml # uri of the yaml file which contains the definition of tosca.nodes.nfv.example_VNF3, this file might be included in the NSD file structure
- example_VNF4.yaml # uri of the yaml file which contains the definition of tosca.nodes.nfv.example_VNF4, this file might be included in the NSD file structure
node_types:
tosca.myExample.NS_2:
derived_from: tosca.nodes.nfv.NS
properties:
descriptor_id:
type: string
constraints: [ valid_values: [ c1bb0ab8-deab-4fa7-95ed-4840d70a3574 ] ]
default: c1bb0ab8-deab-4fa7-95ed-4840d70a3574
designer:
type: string
constraints: [ valid_values: [ MyCompany] ]
default: MyCompany
name:
type: string
constraints: [ valid_values: [ myExample2Service ] ]
default: myExample2Service
version:
type: string
constraints: [ valid_values: [ '1.0.0.0' ] ]
default: '1.0.0.0'
invariant_id:
type: string
constraints: [ valid_values: [ aaaa-bbbb-cccc-dddd ] ]
default: aaaa-bbbb-cccc-dddd
flavour_id:
type: string
constraints: [ valid_values: [ simple ] ]
default: simple
topology_template:
substitution_mappings:
node_type: tosca.myExample.NS_2
requirements:
virtual_link: [ VNF_4, virtual_link_2 ] # the External connection point of
# VNF_2 is exposed as the Sap
node_templates:
NS_2:
type: tosca.myExample.NS_2
interfaces:
Nslcm:
instantiate:
implementation: instantiate.workflow.yaml
terminate:
implementation: terminate.workflow.yaml
VNF_3:
type: tosca.nodes.nfv.example_VNF3
properties:
# no property assignments needed for required properties that have a default value assigned in the node type definition, e.g. descriptor_id
flavour_id: simple
vnf_profile:
instantiation_level: level_1
min_number_of_instances: 2
max_number_of_instances: 6
requirements:
- virtual_link: NS_VL_2
VNF_4:
type: tosca.nodes.nfv.example_VNF4
properties:
flavour_id: simple
vnf_profile:
instantiation_level: level_1
min_number_of_instances: 1
max_number_of_instances: 3
requirements:
- virtual_link_1: NS_VL_2
# - virtual_link_2: # map to virtual_link requirement of the NS node
NS_VL_2:
type: tosca.nodes.nfv.NsVirtualLink
properties:
connectivity_type:
layer_protocols: [ipv4]
flow_pattern: mesh
vl_profile:
max_bitrate_requirements:
root: 1000
min_bitrate_requirements:
root: 1000
Arial A.13 Virtual IP address connection point
Virtual IP address connection points (VipCps) are used to allocate one or multiple IP addresses that are shared by other CP instances, which may be instances of the same or of different VduCp or VnfExtCp nodes.
Load balancing
'''
txt_short = '''
The contents of MyExampleNs_Type.yaml file with the node type definition are as follows:
tosca_definitions_version: tosca_simple_yaml_1_2
description: type definition of tosca.MyExampleNS
imports:
- etsi_nfv_sol001_nsd_types.yaml # all of TOSCA types as defined in ETSI GS NFVSOL 001
node_types:
tosca.MyExampleNS:
derived_from: tosca.nodes.nfv.NS
properties:
descriptor_id:
type: string
constraints: [ valid_values: [ b1bb0ce7-ebca-4fa7-95ed-4840d70a1177 ] ]
default: b1bb0ce7-ebca-4fa7-95ed-4840d70a1177
designer:
type: string
constraints: [ valid_values: [ MyCompany] ]
default: MyCompany
The following snippet shows the service template representing the NSD NS_2. In this example, NS_2 supports one single deployment flavour.
MyExampleNS_2.yaml:
tosca_definitions_version: tosca_simple_yaml_1_1
description: Relational database, simple
imports:
- etsi_nfv_sol001_nsd_types.yaml # all of NSD related TOSCA types as defined in ETSI GS NFV-SOL 001
node_types:
tosca.myExample.NS_2:
derived_from: tosca.nodes.nfv.NS
properties:
descriptor_id:
type: string
constraints: [ valid_values: [ c1bb0ab8-deab-4fa7-95ed-4840d70a3574 ] ]
default: c1bb0ab8-deab-4fa7-95ed-4840d70a3574
topology_template:
substitution_mappings:
node_type: tosca.myExample.NS_2
requirements:
virtual_link: [ VNF_4, virtual_link_2 ] # the External connection point of
# VNF_2 is exposed as the Sap
VNF_4:
type: tosca.nodes.nfv.example_VNF4
properties:
flavour_id: simple
vnf_profile:
instantiation_level: level_1
min_number_of_instances: 1
max_number_of_instances: 3
requirements:
- virtual_link_1: NS_VL_2
# - virtual_link_2: # map to virtual_link requirement of the NS node
Arial A.13 Virtual IP address connection point
Virtual IP address connection points (VipCps) are used to allocate one or multiple IP addresses that are shared by other CP instances, which may be instances of the same or of different VduCp or VnfExtCp nodes.
Load balancing
'''
def test_parse_example_short():
examples = d2t.parse_all_examples(txt_short.split("\n"))
assert len(examples) == 2
assert len(examples[1].text.split("\n")) == 37 # MyExampleNS_2.yaml
def test_parse_example_long():
examples = d2t.parse_all_examples(txt.split("\n"))
assert len(examples) == 2
assert len(examples[1].text.split("\n")) == 93 # MyExampleNS_2.yaml
def test_get_example_file_name():
line1 = """The following snippet shows the service template representing the NSD NS_2. In this example, NS_2 supports one single deployment flavour.
MyExampleNS_2.yaml:"""
line2 = """The contents of MyExampleNs_Type.yaml file with the node type definition are as follows:"""
line3 = """Virtual IP address connection points (VipCps) are used to allocate one or multiple IP addresses that are shared by other CP instances, which may be instances of the same or of different VduCp or VnfExtCp nodes."""
assert d2t.get_example_file_name(line1) == "MyExampleNS_2.yaml"
assert d2t.get_example_file_name(line2) == "MyExampleNs_Type.yaml"
assert d2t.get_example_file_name(line3) == ""