1 # -*- coding: utf-8 -*-
3 # Copyright 2020 Whitestack, LLC
4 # *************************************************************
6 # This file is part of OSM common repository.
7 # All Rights Reserved to Whitestack, LLC
9 # Licensed under the Apache License, Version 2.0 (the "License"); you may
10 # not use this file except in compliance with the License. You may obtain
11 # a copy of the License at
13 # http://www.apache.org/licenses/LICENSE-2.0
15 # Unless required by applicable law or agreed to in writing, software
16 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
17 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
18 # License for the specific language governing permissions and limitations
21 # For those usages not covered by the Apache License, Version 2.0 please
22 # contact: agarcia@whitestack.com
25 from osm_im
.im_translation
import translate_im_vnfd_to_sol006
, translate_im_nsd_to_sol006
29 TESTS_EXAMPLES_FOLDER
= 'tests/examples/'
31 IM_TO_SOL006_VNFD_FILES
= {
32 'cirros_vnfd_im.yaml': 'cirros_vnfd_sol006.yaml',
33 'alternative_image_im.yaml': 'alternative_image_sol006.yaml',
34 'epa_im.yaml': 'epa_sol006.yaml',
35 'magma_knf_im.yaml': 'magma_knf_sol006.yaml',
36 'vnfd_im.yaml': 'vnfd_sol006.yaml',
37 'vepc_im.yaml': 'vepc_sol006.yaml',
38 'hackfest_charmed_vnfd_im.yaml': 'hackfest_charmed_vnfd_sol006.yaml',
41 IM_TO_SOL006_NSD_FILES
= {
42 'cirros_nsd_im.yaml': 'cirros_nsd_sol006.yaml',
43 'vepc_nsd_im.yaml': 'vepc_nsd_sol006.yaml',
44 'hackfest_charmed_nsd_im.yaml': 'hackfest_charmed_nsd_sol006.yaml',
48 class TranslationTest(unittest
.TestCase
):
49 def _sort_descriptor(self
, descriptor
):
50 if isinstance(descriptor
, dict):
51 return sorted((k
, self
._sort
_descriptor
(v
)) for k
, v
in descriptor
.items())
52 if isinstance(descriptor
, list):
53 return sorted(self
._sort
_descriptor
(x
) for x
in descriptor
)
57 def _get_descriptor_file_data_as_dict(self
, descriptor_file_path
):
58 with
open(descriptor_file_path
, 'r') as descriptor_file
:
59 descriptor_dict
= yaml
.safe_load(descriptor_file
.read())
60 return descriptor_dict
62 def test_translate_im_vnfd_to_sol006(self
):
63 for im_file
in IM_TO_SOL006_VNFD_FILES
:
64 im_file_path
= TESTS_EXAMPLES_FOLDER
+ im_file
65 sol006_file_path
= TESTS_EXAMPLES_FOLDER
+ IM_TO_SOL006_VNFD_FILES
[im_file
]
66 im_vnfd
= self
._get
_descriptor
_file
_data
_as
_dict
(im_file_path
)
67 sol006_vnfd
= self
._get
_descriptor
_file
_data
_as
_dict
(sol006_file_path
)
69 translated_vnfd
= translate_im_vnfd_to_sol006(im_vnfd
)
70 self
.assertEqual(self
._sort
_descriptor
(sol006_vnfd
), self
._sort
_descriptor
(translated_vnfd
))
72 def test_translate_im_nsd_to_sol006(self
):
73 for im_file
in IM_TO_SOL006_NSD_FILES
:
74 im_file_path
= TESTS_EXAMPLES_FOLDER
+ im_file
75 sol006_file_path
= TESTS_EXAMPLES_FOLDER
+ IM_TO_SOL006_NSD_FILES
[im_file
]
76 im_nsd
= self
._get
_descriptor
_file
_data
_as
_dict
(im_file_path
)
77 sol006_nsd
= self
._get
_descriptor
_file
_data
_as
_dict
(sol006_file_path
)
79 translated_nsd
= translate_im_nsd_to_sol006(im_nsd
)
80 self
.assertEqual(self
._sort
_descriptor
(sol006_nsd
), self
._sort
_descriptor
(translated_nsd
))