Feature 11002: Deorecate helmv2
[osm/LCM.git] / osm_lcm / tests / test_vim_sdn.py
index 970dd00..6ee3fd8 100644 (file)
@@ -19,7 +19,7 @@ from unittest.mock import Mock, patch, MagicMock
 
 from osm_common import msgbase
 from osm_common.dbbase import DbException
-from osm_lcm.vim_sdn import VcaLcm
+from osm_lcm.vim_sdn import K8sClusterLcm, VcaLcm
 
 
 class AsyncMock(MagicMock):
@@ -35,7 +35,7 @@ class TestVcaLcm(TestCase):
         self.msg = Mock(msgbase.MsgBase())
         self.lcm_tasks = Mock()
         self.config = {"database": {"driver": "mongo"}}
-        self.vca_lcm = VcaLcm(self.msg, self.lcm_tasks, self.config, self.loop)
+        self.vca_lcm = VcaLcm(self.msg, self.lcm_tasks, self.config)
         self.vca_lcm.db = Mock()
         self.vca_lcm.fs = Mock()
 
@@ -316,3 +316,88 @@ class TestVcaLcm(TestCase):
         )
         self.lcm_tasks.unlock_HA.not_called()
         self.lcm_tasks.remove.assert_called_with("vca", "id", "order-id")
+
+
+class TestK8SClusterLcm(TestCase):
+    @patch("osm_lcm.vim_sdn.K8sHelm3Connector")
+    @patch("osm_lcm.vim_sdn.K8sJujuConnector")
+    @patch("osm_lcm.lcm_utils.Database")
+    @patch("osm_lcm.lcm_utils.Filesystem")
+    def setUp(
+        self,
+        mock_filesystem,
+        mock_database,
+        juju_connector,
+        helm3_connector,
+    ):
+        self.loop = asyncio.get_event_loop()
+        self.msg = Mock(msgbase.MsgBase())
+        self.lcm_tasks = Mock()
+        self.config = {"database": {"driver": "mongo"}}
+        self.vca_config = {
+            "VCA": {
+                "helm3path": "/usr/local/bin/helm3",
+                "kubectlpath": "/usr/bin/kubectl",
+            }
+        }
+        self.k8scluster_lcm = K8sClusterLcm(self.msg, self.lcm_tasks, self.vca_config)
+        self.k8scluster_lcm.db = Mock()
+        self.k8scluster_lcm.fs = Mock()
+
+    def test_k8scluster_edit(self):
+        k8scluster_content = {"op_id": "op-id", "_id": "id"}
+        order_id = "order-id"
+        self.lcm_tasks.lock_HA.return_value = True
+        self.loop.run_until_complete(
+            self.k8scluster_lcm.edit(k8scluster_content, order_id)
+        )
+        self.lcm_tasks.unlock_HA.assert_called_with(
+            "k8scluster",
+            "edit",
+            "op-id",
+            operationState="COMPLETED",
+            detailed_status="Not implemented",
+        )
+        self.lcm_tasks.remove.assert_called_with("k8scluster", "id", order_id)
+
+    def test_k8scluster_edit_lock_false(self):
+        k8scluster_content = {"op_id": "op-id", "_id": "id"}
+        order_id = "order-id"
+        self.lcm_tasks.lock_HA.return_value = False
+        self.loop.run_until_complete(
+            self.k8scluster_lcm.edit(k8scluster_content, order_id)
+        )
+        self.lcm_tasks.unlock_HA.assert_not_called()
+        self.lcm_tasks.remove.assert_not_called()
+
+    def test_k8scluster_edit_no_opid(self):
+        k8scluster_content = {"_id": "id"}
+        order_id = "order-id"
+        self.lcm_tasks.lock_HA.return_value = True
+        self.loop.run_until_complete(
+            self.k8scluster_lcm.edit(k8scluster_content, order_id)
+        )
+        self.lcm_tasks.unlock_HA.assert_called_with(
+            "k8scluster",
+            "edit",
+            None,
+            operationState="COMPLETED",
+            detailed_status="Not implemented",
+        )
+        self.lcm_tasks.remove.assert_called_with("k8scluster", "id", order_id)
+
+    def test_k8scluster_edit_no_orderid(self):
+        k8scluster_content = {"op_id": "op-id", "_id": "id"}
+        order_id = None
+        self.lcm_tasks.lock_HA.return_value = True
+        self.loop.run_until_complete(
+            self.k8scluster_lcm.edit(k8scluster_content, order_id)
+        )
+        self.lcm_tasks.unlock_HA.assert_called_with(
+            "k8scluster",
+            "edit",
+            "op-id",
+            operationState="COMPLETED",
+            detailed_status="Not implemented",
+        )
+        self.lcm_tasks.remove.assert_called_with("k8scluster", "id", order_id)