RO Unit Tests for Feature: 10910 52/12152/4
authorelumalai <deepika.e@tataelxsi.co.in>
Wed, 1 Jun 2022 08:06:05 +0000 (13:36 +0530)
committerelumalai <deepika.e@tataelxsi.co.in>
Thu, 23 Jun 2022 15:00:43 +0000 (20:30 +0530)
Added unit tests in RO for feature 10910 - Migration of
Openstack based VM instances

Change-Id: I2bbca8db3fd253fccbfcfb1e5aaf732b571dbfb2
Signed-off-by: elumalai <deepika.e@tataelxsi.co.in>
NG-RO/osm_ng_ro/tests/test_ns.py
NG-RO/osm_ng_ro/tests/test_ns_thread.py
releasenotes/notes/feature_10910_Migration_of_Openstack_based_VM_instances_Unit_Tests-8dfb7f65da2b85bf.yaml [new file with mode: 0644]

index 129e668..c0ba426 100644 (file)
@@ -2756,3 +2756,48 @@ class TestNs(unittest.TestCase):
         )
 
         self.assertDictEqual(task, expected_result)
+
+    @patch("osm_ng_ro.ns.Ns._assign_vim")
+    def test_migrate_task(self, assign_vim):
+        self.ns = Ns()
+        extra_dict = {}
+        vdu_index = "1"
+        action_id = "bb937f49-3870-4169-b758-9732e1ff40f3"
+        nsr_id = "993166fe-723e-4680-ac4b-b1af2541ae31"
+        task_index = 1
+        target_record_id = (
+            "vnfrs:665b4165-ce24-4320-bf19-b9a45bade49f:"
+            "vdur.bb9c43f9-10a2-4569-a8a8-957c3528b6d1"
+        )
+
+        expected_result = {
+            "target_id": "vim:f9f370ac-0d44-41a7-9000-457f2332bc35",
+            "action_id": "bb937f49-3870-4169-b758-9732e1ff40f3",
+            "nsr_id": "993166fe-723e-4680-ac4b-b1af2541ae31",
+            "task_id": "bb937f49-3870-4169-b758-9732e1ff40f3:1",
+            "status": "SCHEDULED",
+            "action": "EXEC",
+            "item": "migrate",
+            "target_record": "vnfrs:665b4165-ce24-4320-bf19-b9a45bade49f:vdur.1",
+            "target_record_id": target_record_id,
+            "params": {
+                "vim_vm_id": "f37b18ef-3caa-4dc9-ab91-15c669b16396",
+                "migrate_host": "migrateToHost",
+            },
+        }
+        vdu = {
+            "id": "bb9c43f9-10a2-4569-a8a8-957c3528b6d1",
+            "vim_info": {
+                "vim:f9f370ac-0d44-41a7-9000-457f2332bc35": {"interfaces": []}
+            },
+        }
+        vnf = {"_id": "665b4165-ce24-4320-bf19-b9a45bade49f"}
+        extra_dict["params"] = {
+            "vim_vm_id": "f37b18ef-3caa-4dc9-ab91-15c669b16396",
+            "migrate_host": "migrateToHost",
+        }
+        task = self.ns.migrate_task(
+            vdu, vnf, vdu_index, action_id, nsr_id, task_index, extra_dict
+        )
+
+        self.assertDictEqual(task, expected_result)
index c1d23a0..86ba996 100644 (file)
@@ -21,6 +21,7 @@ from unittest.mock import MagicMock, patch
 
 from osm_ng_ro.ns_thread import (
     VimInteractionAffinityGroup,
+    VimInteractionMigration,
     VimInteractionNet,
     VimInteractionResize,
 )
@@ -1369,3 +1370,66 @@ class TestVimInteractionResize(unittest.TestCase):
             result = instance.exec(ro_task, task_index, self.task_depends)
             self.assertEqual(result[0], "DONE")
             self.assertEqual(result[1].get("vim_status"), "DONE")
+
+
+class TestVimInteractionMigration(unittest.TestCase):
+    def setUp(self):
+        module_name = "osm_ro_plugin"
+        self.target_vim = MagicMock(name=f"{module_name}.vimconn.VimConnector")
+        self.task_depends = None
+
+        patches = [patch(f"{module_name}.vimconn.VimConnector", self.target_vim)]
+
+        # Enabling mocks and add cleanups
+        for mock in patches:
+            mock.start()
+            self.addCleanup(mock.stop)
+
+    def test__exec_migration_done(self):
+        """
+        create migrate task
+        """
+        db = "test_db"
+        logger = "test_logger"
+        my_vims = "test-vim"
+        db_vims = {
+            0: {
+                "config": {},
+            },
+        }
+        target_record_id = (
+            "vnfrs:665b4165-ce24-4320-bf19-b9a45bade49f:"
+            "vdur.bb9c43f9-10a2-4569-a8a8-957c3528b6d1"
+        )
+
+        instance = VimInteractionMigration(db, logger, my_vims, db_vims)
+        with patch.object(instance, "my_vims", [self.target_vim]), patch.object(
+            instance, "logger", logging
+        ), patch.object(instance, "db_vims", db_vims):
+            ro_task = {
+                "target_id": 0,
+                "tasks": {
+                    "task_index_1": {
+                        "target_id": 0,
+                        "action_id": "bb937f49-3870-4169-b758-9732e1ff40f3",
+                        "nsr_id": "993166fe-723e-4680-ac4b-b1af2541ae31",
+                        "task_id": "bb937f49-3870-4169-b758-9732e1ff40f3:0",
+                        "status": "SCHEDULED",
+                        "action": "EXEC",
+                        "item": "migrate",
+                        "target_record": "vnfrs:665b4165-ce24-4320-bf19-b9a45bade49f:vdur.0",
+                        "target_record_id": target_record_id,
+                        "params": {
+                            "vim_vm_id": "f37b18ef-3caa-4dc9-ab91-15c669b16396",
+                            "migrate_host": "osm-test2",
+                            "vdu_vim_info": {0: {"interfaces": []}},
+                        },
+                    }
+                },
+            }
+            self.target_vim.migrate_instance.return_value = "ACTIVE", "test"
+
+            task_index = "task_index_1"
+            result = instance.exec(ro_task, task_index, self.task_depends)
+            self.assertEqual(result[0], "DONE")
+            self.assertEqual(result[1].get("vim_status"), "ACTIVE")
diff --git a/releasenotes/notes/feature_10910_Migration_of_Openstack_based_VM_instances_Unit_Tests-8dfb7f65da2b85bf.yaml b/releasenotes/notes/feature_10910_Migration_of_Openstack_based_VM_instances_Unit_Tests-8dfb7f65da2b85bf.yaml
new file mode 100644 (file)
index 0000000..3591352
--- /dev/null
@@ -0,0 +1,20 @@
+#######################################################################################
+# Copyright ETSI Contributors and Others.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#    http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+# implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#######################################################################################
+---
+other:
+  - |
+    Added unit test cases for Feature 10910 Migration of Openstack based VM instances from OSM