Adapts PLA to new SOL006 NSD descriptors format
[osm/PLA.git] / osm_pla / test / test_server.py
index bac8647..9d7582f 100644 (file)
@@ -13,6 +13,7 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 import asyncio
+import copy
 import os
 import sys
 from unittest import TestCase, mock
@@ -193,9 +194,7 @@ list_of_vims = [{"_id": "73cd1a1b-333e-4e29-8db2-00d23bd9b644", "vim_user": "adm
                  "schema_version": "1.1", "config": {}}]
 
 # FIXME this is not correct re mgmt-network setting.
-nsd_from_db = {"_id": "15fc1941-f095-4cd8-af2d-1000bd6d9eaa", "short-name": "three_vnf_constrained_nsd_low",
-               "name": "three_vnf_constrained_nsd_low", "version": "1.0",
-               "description": "Placement constraints NSD",
+nsd_from_db = {"_id": "15fc1941-f095-4cd8-af2d-1000bd6d9eaa",
                "_admin": {"modified": 1567672251.7531693,
                           "storage": {"pkg-dir": "ns_constrained_nsd", "fs": "local",
                                       "descriptor": "ns_constrained_nsd/ns_constrained_nsd.yaml",
@@ -205,33 +204,62 @@ nsd_from_db = {"_id": "15fc1941-f095-4cd8-af2d-1000bd6d9eaa", "short-name": "thr
                           "projects_write": ["0a5d0c5b-7e08-48a1-a686-642a038bbd70"], "operationalState": "ENABLED",
                           "userDefinedData": {}, "created": 1567672251.7531693,
                           "projects_read": ["0a5d0c5b-7e08-48a1-a686-642a038bbd70"]},
-               "constituent-vnfd": [{"vnfd-id-ref": "cirros_vnfd_v2", "member-vnf-index": "one"},
-                                    {"vnfd-id-ref": "cirros_vnfd_v2", "member-vnf-index": "two"},
-                                    {"vnfd-id-ref": "cirros_vnfd_v2", "member-vnf-index": "three"}],
-               "id": "three_vnf_constrained_nsd_low", "vendor": "ArctosLabs",
-               "vld": [{"type": "ELAN", "short-name": "ns_constrained_nsd_low_vld1",
-                        "link-constraint": [{"constraint-type": "LATENCY", "value": "100"},
-                                            {"constraint-type": "JITTER", "value": "30"}],
-                        "vim-network-name": "external", "mgmt-network": True,
-                        "id": "three_vnf_constrained_nsd_low_vld1",
-                        "vnfd-connection-point-ref": [
-                            {"vnfd-id-ref": "cirros_vnfd_v2", "member-vnf-index-ref": "one",
-                             "vnfd-connection-point-ref": "vnf-cp0"},
-                            {"vnfd-id-ref": "cirros_vnfd_v2",
-                             "member-vnf-index-ref": "two",
-                             "vnfd-connection-point-ref": "vnf-cp0"}],
-                        "name": "ns_constrained_nsd_vld1"},
-                       {"type": "ELAN", "short-name": "ns_constrained_nsd_low_vld2",
-                        "link-constraint": [{"constraint-type": "LATENCY", "value": "50"},
-                                            {"constraint-type": "JITTER", "value": "30"}],
-                        "vim-network-name": "lanretxe", "mgmt-network": True,
-                        "id": "three_vnf_constrained_nsd_low_vld2",
-                        "vnfd-connection-point-ref": [
-                            {"vnfd-id-ref": "cirros_vnfd_v2", "member-vnf-index-ref": "two",
-                             "vnfd-connection-point-ref": "vnf-cp0"},
-                            {"vnfd-id-ref": "cirros_vnfd_v2", "member-vnf-index-ref": "three",
-                             "vnfd-connection-point-ref": "vnf-cp0"}],
-                        "name": "ns_constrained_nsd_vld2"}]}
+               'id': 'three_vnf_constrained_nsd_low',
+               'name': 'three_vnf_constrained_nsd_low',
+               'description': 'Placement constraints NSD',
+               'designer': 'ArctosLabs',
+               'version': '1.0',
+               'vnfd-id': ['cirros_vnfd_v2'],
+               'df': [{
+                   'id': 'default-df',
+                   'vnf-profile': [{
+                       'id': 'one',
+                       'vnfd-id': 'cirros_vnfd_v2',
+                       'virtual-link-connectivity': [{
+                           'virtual-link-profile-id': 'three_vnf_constrained_nsd_low_vld1',
+                           'constituent-cpd-id': [{
+                               'constituent-base-element-id': 'one',
+                               'constituent-cpd-id': 'vnf-cp0-ext'
+                           }]
+                       }]
+                   }, {
+                       'id': 'two',
+                       'vnfd-id': 'cirros_vnfd_v2',
+                       'virtual-link-connectivity': [{
+                           'virtual-link-profile-id': 'three_vnf_constrained_nsd_low_vld1',
+                           'constituent-cpd-id': [{
+                               'constituent-base-element-id': 'two',
+                               'constituent-cpd-id': 'vnf-cp0-ext'
+                           }]
+                       }, {
+                           'virtual-link-profile-id': 'three_vnf_constrained_nsd_low_vld2',
+                           'constituent-cpd-id': [{
+                               'constituent-base-element-id': 'two',
+                               'constituent-cpd-id': 'vnf-cp0-ext'
+                           }]
+                       }]
+                   }, {
+                       'id': 'three',
+                       'vnfd-id': 'cirros_vnfd_v2',
+                       'virtual-link-connectivity': [{
+                           'virtual-link-profile-id': 'three_vnf_constrained_nsd_low_vld2',
+                           'constituent-cpd-id': [{
+                               'constituent-base-element-id': 'three',
+                               'constituent-cpd-id': 'vnf-cp0-ext'
+                           }]
+                       }]
+                   }]
+               }],
+               'virtual-link-desc': [{
+                   'id': 'three_vnf_constrained_nsd_low_vld1',
+                   'mgmt-network': True,
+                   'vim-network-name': 'external'
+               }, {
+                   'id': 'three_vnf_constrained_nsd_low_vld2',
+                   'mgmt-network': True,
+                   'vim-network-name': 'lanretxe'
+               }],
+            }
 
 
 ######################################################
@@ -309,6 +337,18 @@ class TestServer(TestCase):
         _ = server._get_nsd(nslcmop_record_wo_pinning['operationParams']['nsdId'])
         server.db.get_one.assert_called_with("nsds", {'_id': nslcmop_record_wo_pinning['operationParams']['nsdId']})
 
+    def test__create_vnf_id_maps(self):
+        server = self.serverSetup()
+        server.db = Mock()
+        expected_mvi2mzn = {'one': 'VNF0', 'two': 'VNF1', 'three': 'VNF2'}
+        expected_mzn2mvi = {'VNF0': 'one', 'VNF1': 'two', 'VNF2': 'three'}
+
+        nsd_for_test = copy.deepcopy(nsd_from_db)
+        mvi2mzn, mzn2mvi = server._create_vnf_id_maps(nsd_for_test)
+
+        self.assertDictEqual(expected_mvi2mzn, mvi2mzn, 'Faulty mzn2member-vnf-index mapping')
+        self.assertDictEqual(expected_mzn2mvi, mzn2mvi, 'Faulty mzn2member-vnf-index mapping')
+
     def test__get_vim_accounts(self):  # OK
         server = self.serverSetup()
         server.db = Mock()
@@ -368,13 +408,14 @@ class TestServer(TestCase):
         run _get_placement and check that things get called as expected
         :return:
         """
-        placement_ret_val = [{'vimAccountId': 'bbbbbbbb-38f5-438d-b8ee-3f93b3531f87', 'member-vnf-index': 'one'},
-                             {'vimAccountId': 'aaaaaaaa-38f5-438d-b8ee-3f93b3531f87', 'member-vnf-index': 'two'},
-                             {'vimAccountId': 'aaaaaaaa-38f5-438d-b8ee-3f93b3531f87', 'member-vnf-index': 'three'}]
+        placement_ret_val = [{'vimAccountId': 'bbbbbbbb-38f5-438d-b8ee-3f93b3531f87', 'member-vnf-index': 'VNF0'},
+                             {'vimAccountId': 'aaaaaaaa-38f5-438d-b8ee-3f93b3531f87', 'member-vnf-index': 'VNF1'},
+                             {'vimAccountId': 'aaaaaaaa-38f5-438d-b8ee-3f93b3531f87', 'member-vnf-index': 'VNF2'}]
         server = self.serverSetup()
 
         server.msgBus.aiowrite = _async_mock()
-        mock__get_nsd.return_value = nsd_from_db
+        nsd_for_test = copy.deepcopy(nsd_from_db)
+        mock__get_nsd.return_value = nsd_for_test
         mock__get_vim_accounts.return_value = list_of_vims
 
         # FIXME need update to match nslcmop, not for test but for consistency
@@ -437,13 +478,14 @@ class TestServer(TestCase):
         run _get_placement and check that things get called as expected
         :return:
         """
-        placement_ret_val = [{'vimAccountId': 'bbbbbbbb-38f5-438d-b8ee-3f93b3531f87', 'member-vnf-index': 'one'},
-                             {'vimAccountId': 'aaaaaaaa-38f5-438d-b8ee-3f93b3531f87', 'member-vnf-index': 'two'},
-                             {'vimAccountId': 'aaaaaaaa-38f5-438d-b8ee-3f93b3531f87', 'member-vnf-index': 'three'}]
+        placement_ret_val = [{'vimAccountId': 'bbbbbbbb-38f5-438d-b8ee-3f93b3531f87', 'member-vnf-index': 'VNF0'},
+                             {'vimAccountId': 'aaaaaaaa-38f5-438d-b8ee-3f93b3531f87', 'member-vnf-index': 'VNF1'},
+                             {'vimAccountId': 'aaaaaaaa-38f5-438d-b8ee-3f93b3531f87', 'member-vnf-index': 'VNF2'}]
         server = self.serverSetup()
 
         server.msgBus.aiowrite = _async_mock()
-        mock__get_nsd.return_value = nsd_from_db
+        nsd_for_test = copy.deepcopy(nsd_from_db)
+        mock__get_nsd.return_value = nsd_for_test
         mock__get_vim_accounts.return_value = list_of_vims
 
         # FIXME need update to match nslcmop, not for test but for consistency
@@ -506,7 +548,8 @@ class TestServer(TestCase):
         server = self.serverSetup()
 
         server.msgBus.aiowrite = _async_mock()
-        mock__get_nsd.return_value = nsd_from_db
+        nsd_for_test = copy.deepcopy(nsd_from_db)
+        mock__get_nsd.return_value = nsd_for_test
         mock__get_nsd.side_effect = RuntimeError('kaboom!')
         mock__get_vim_accounts.return_value = list_of_vims
         mock_do_placement_computation.return_value = \