Bug 2175: K8s-Cluster Update is not implemented 45/13745/1 v12.0 v12.0.7 v12.0.8
authordariofaccin <dario.faccin@canonical.com>
Mon, 23 Jan 2023 17:13:27 +0000 (18:13 +0100)
committercubag <gcuba@whitestack.com>
Tue, 25 Jul 2023 20:41:52 +0000 (22:41 +0200)
Fix: handle (as agreed) the edit operation.
The update operation does not perform any operation on the K8SCluster.

Change-Id: I8ea45b1479608cdcae2140f1aa3b4cf541b2e643
Signed-off-by: dariofaccin <dario.faccin@canonical.com>
(cherry picked from commit 8bbeeb07c4be6b2396549af9ca8c389d4b888809)

osm_lcm/lcm.py
osm_lcm/tests/test_vim_sdn.py
osm_lcm/vim_sdn.py

index 8932d89..7f949f3 100644 (file)
@@ -365,6 +365,13 @@ class Lcm:
                     "k8scluster", k8scluster_id, order_id, "k8scluster_create", task
                 )
                 return
+            elif command == "edit" or command == "edited":
+                k8scluster_id = params.get("_id")
+                task = asyncio.ensure_future(self.k8scluster.edit(params, order_id))
+                self.lcm_tasks.register(
+                    "k8scluster", k8scluster_id, order_id, "k8scluster_edit", task
+                )
+                return
             elif command == "delete" or command == "deleted":
                 k8scluster_id = params.get("_id")
                 task = asyncio.ensure_future(self.k8scluster.delete(params, order_id))
index f6b75e0..309fc1f 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):
@@ -158,3 +158,93 @@ 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.K8sHelmConnector")
+    @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,
+        helm_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": {
+                "helmpath": "/usr/local/bin/helm",
+                "helm3path": "/usr/local/bin/helm3",
+                "kubectlpath": "/usr/bin/kubectl",
+            }
+        }
+        self.k8scluster_lcm = K8sClusterLcm(
+            self.msg, self.lcm_tasks, self.vca_config, self.loop
+        )
+        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)
index c81969a..3f323d6 100644 (file)
@@ -1295,6 +1295,32 @@ class K8sClusterLcm(LcmBase):
                 self.logger.error(logging_text + "Cannot update database: {}".format(e))
             self.lcm_tasks.remove("k8scluster", k8scluster_id, order_id)
 
+    async def edit(self, k8scluster_content, order_id):
+
+        op_id = k8scluster_content.pop("op_id", None)
+        if not self.lcm_tasks.lock_HA("k8scluster", "edit", op_id):
+            return
+
+        k8scluster_id = k8scluster_content["_id"]
+        logging_text = "Task k8scluster_edit={} ".format(k8scluster_id)
+        self.logger.debug(logging_text + "Enter")
+
+        # TODO the implementation is pending and will be part of a new feature
+        # It will support rotation of certificates, update of credentials and K8S API endpoint
+        # At the moment the operation is set as completed
+
+        operation_state = "COMPLETED"
+        operation_details = "Not implemented"
+
+        self.lcm_tasks.unlock_HA(
+            "k8scluster",
+            "edit",
+            op_id,
+            operationState=operation_state,
+            detailed_status=operation_details,
+        )
+        self.lcm_tasks.remove("k8scluster", k8scluster_id, order_id)
+
     async def delete(self, k8scluster_content, order_id):
 
         # HA tasks and backward compatibility: