Newer
Older
import example as exp
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")
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 exp.is_start_of_example("tosca_definitions_version: tosca_simple_yaml_1_1")
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
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
'''
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
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
sunshine = '''
sunshineVNF.yaml
tosca_definitions_version: tosca_simple_yaml_1_3
description: Relational database, non-scalable
imports:
- etsi_nfv_sol001_vnfd_types.yaml # all of TOSCA VNFD types as defined in ETSI GS NFV-SOL 001
data_types:
MyCompany.datatypes.nfv.VnfInstantiateAdditionalParameters:
derived_from: tosca.datatypes.nfv.VnfOperationAdditionalParameters
properties:
parameter_1:
type: string
required: true
default: value_1
parameter_2:
type: string
required: true
default: value_2
node_types:
MyCompany.SunshineDB.1_0.1_0:
derived_from: tosca.nodes.nfv.VNF
properties:
descriptor_id:
type: string
constraints: [ equal: b1bb0ce7-ebca-4fa7-95ed-4840d70a1177 ]
default: b1bb0ce7-ebca-4fa7-95ed-4840d70a1177
provider:
type: string
constraints: [ equal: MyCompany ]
default: MyCompany
product_name:
type: string
constraints: [ equal: SunshineDB ]
default: SunshineDB
software_version:
type: string
constraints: [ equal: '1.0' ]
default: '1.0'
descriptor_version:
type: string
constraints: [ equal: '1.0' ]
default: '1.0'
flavour_id:
type: string
constraints: [ valid_values: [ simple, complex ] ]
default: simple
flavour_description:
type: string
default: "" #empty string
vnfm_info:
type: list
entry_schema:
type: string
constraints: [ equal: '0:MyCompany-1.0.0' ]
default: [ '0:MyCompany-1.0.0' ]
requirements:
- virtual_link:
capability: tosca.capabilities.nfv.VirtualLinkable
occurrences: [ 0, 0 ]
- virtual_link_backend:
capability: tosca.capabilities.nfv.VirtualLinkable
occurrences: [ 0, 1 ]
- virtual_link_service:
capability: tosca.capabilities.nfv.VirtualLinkable
occurrences: [ 0, 1 ]
interfaces:
Vnflcm:
type: tosca.interfaces.nfv.Vnflcm
operations:
instantiate:
inputs:
additional_parameters:
type: MyCompany.datatypes.nfv.VnfInstantiateAdditionalParameters
The vnf node template in the sunshine.vnfd.tosca.yaml file is abstract and is subject to substitution; the lower-level templates
'''
sunshine_vnfd = '''
SunshineDB: VNFD-top level
sunshine.vnfd.tosca.yaml
tosca_definitions_version: tosca_simple_yaml_1_3
description: Relational database, non-scalable
imports:
- etsi_nfv_sol001_vnfd_types.yaml # all of TOSCA VNFD types as defined in ETSI GS NFV SOL 001
- sunshineVNF.yaml # contains the VNF node type definition
topology_template:
inputs:
flavour_id:
type: string
description: VNF deployment flavour selected by the consumer. It is provided in the API
node_templates:
SunshineDB:
type: MyCompany.SunshineDB.1_0.1_0
properties:
flavour_id: { get_input: flavour_id }
descriptor_id: b1bb0ce7-ebca-4fa7-95ed-4840d70a1177
provider: MyCompany
product_name: SunshineDB
software_version: '1.0'
descriptor_version: '1.0'
vnfm_info:
- '0:MyCompany-1.0.0'
# requirements:
#- virtual_link_backend # mapped in lower-level templates
#- virtual_link_service # mapped in lower-level templates
# get_input function would be used to process the template at run time to access the selected flavour id. If the TOSCA functions are not supported by VNFM, the above function may not be needed, what other mechanisms can be used by VNFM which provide the same function are out of scope of the present document.
Something
'''
def test_parse_example_short():
examples = exp.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 = exp.parse_all_examples(txt.split("\n"))
assert len(examples) == 2
assert len(examples[1].text.split("\n")) == 93 # MyExampleNS_2.yaml
def test_parse_example_sunshine():
examples = exp.parse_all_examples(sunshine.split("\n"))
assert len(examples) == 1
assert len(examples[0].text.split("\n")) == 78
def test_parse_example_sunshine_vnfd():
examples = exp.parse_all_examples(sunshine_vnfd.split("\n"))
assert len(examples) == 1
assert len(examples[0].text.split("\n")) == 32
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 exp.get_example_file_name(line1) == "MyExampleNS_2.yaml"
assert exp.get_example_file_name(line2) == "MyExampleNs_Type.yaml"
assert exp.get_example_file_name(line3) == ""