Update helm repo after adding the repo 70/11870/4
authorgarciadeblas <gerardo.garciadeblas@telefonica.com>
Wed, 4 May 2022 08:57:36 +0000 (10:57 +0200)
committergarciadav <david.garcia@canonical.com>
Fri, 6 May 2022 11:49:19 +0000 (13:49 +0200)
Change-Id: I4cd2a073cb862fac4d7646e65f7b3df6068a1c5a
Signed-off-by: garciadeblas <gerardo.garciadeblas@telefonica.com>
n2vc/k8s_helm_base_conn.py
n2vc/tests/unit/test_k8s_helm3_conn.py
n2vc/tests/unit/test_k8s_helm_conn.py

index 57010d1..9b0ca86 100644 (file)
@@ -175,15 +175,6 @@ class K8sHelmBaseConnector(K8sConnector):
         # sync local dir
         self.fs.sync(from_path=cluster_uuid)
 
-        # helm repo update
-        command = "env KUBECONFIG={} {} repo update".format(
-            paths["kube_config"], self._helm_command
-        )
-        self.log.debug("updating repo: {}".format(command))
-        await self._local_async_exec(
-            command=command, raise_exception_on_error=False, env=env
-        )
-
         # helm repo add name url
         command = ("env KUBECONFIG={} {} repo add {} {}").format(
             paths["kube_config"], self._helm_command, name, url
@@ -209,6 +200,15 @@ class K8sHelmBaseConnector(K8sConnector):
             command=command, raise_exception_on_error=True, env=env
         )
 
+        # helm repo update
+        command = "env KUBECONFIG={} {} repo update".format(
+            paths["kube_config"], self._helm_command
+        )
+        self.log.debug("updating repo: {}".format(command))
+        await self._local_async_exec(
+            command=command, raise_exception_on_error=False, env=env
+        )
+
         # sync fs
         self.fs.reverse_sync(from_path=cluster_uuid)
 
index 91e1729..775b0a7 100644 (file)
@@ -86,7 +86,7 @@ class TestK8sHelm3Conn(asynctest.TestCase):
     async def test_repo_add(self):
         repo_name = "bitnami"
         repo_url = "https://charts.bitnami.com/bitnami"
-        self.helm_conn._local_async_exec = asynctest.CoroutineMock(return_value=("", 0))
+        self.helm_conn._local_async_exec = asynctest.CoroutineMock(return_value=(0, ""))
 
         await self.helm_conn.repo_add(self.cluster_uuid, repo_name, repo_url)
 
@@ -110,24 +110,24 @@ class TestK8sHelm3Conn(asynctest.TestCase):
         call0_kargs = calls[0][1]
         self.assertEqual(
             call0_kargs.get("command"),
-            repo_update_command,
-            "Invalid repo update command: {}".format(call0_kargs.get("command")),
+            repo_add_command,
+            "Invalid repo add command: {}".format(call0_kargs.get("command")),
         )
         self.assertEqual(
             call0_kargs.get("env"),
             self.env,
-            "Invalid env for update command: {}".format(call0_kargs.get("env")),
+            "Invalid env for add command: {}".format(call0_kargs.get("env")),
         )
         call1_kargs = calls[1][1]
         self.assertEqual(
             call1_kargs.get("command"),
-            repo_add_command,
-            "Invalid repo add command: {}".format(call1_kargs.get("command")),
+            repo_update_command,
+            "Invalid repo update command: {}".format(call1_kargs.get("command")),
         )
         self.assertEqual(
             call1_kargs.get("env"),
             self.env,
-            "Invalid env for add command: {}".format(call1_kargs.get("env")),
+            "Invalid env for update command: {}".format(call1_kargs.get("env")),
         )
 
     @asynctest.fail_on(active_handles=True)
index 736405f..ae9338d 100644 (file)
@@ -42,7 +42,7 @@ class TestK8sHelmConn(asynctest.TestCase):
         # pass fake kubectl and helm commands to make sure it does not call actual commands
         K8sHelmConnector._check_file_exists = asynctest.Mock(return_value=True)
         K8sHelmConnector._local_async_exec = asynctest.CoroutineMock(
-            return_value=("", 0)
+            return_value=(0, "")
         )
         cluster_dir = self.fs.path + self.cluster_id
         self.kube_config = self.fs.path + self.cluster_id + "/.kube/config"
@@ -87,24 +87,24 @@ class TestK8sHelmConn(asynctest.TestCase):
         call0_kargs = calls[0][1]
         self.assertEqual(
             call0_kargs.get("command"),
-            repo_update_command,
-            "Invalid repo update command: {}".format(call0_kargs.get("command")),
+            repo_add_command,
+            "Invalid repo add command: {}".format(call0_kargs.get("command")),
         )
         self.assertEqual(
             call0_kargs.get("env"),
             self.env,
-            "Invalid env for update command: {}".format(call0_kargs.get("env")),
+            "Invalid env for add command: {}".format(call0_kargs.get("env")),
         )
         call1_kargs = calls[1][1]
         self.assertEqual(
             call1_kargs.get("command"),
-            repo_add_command,
-            "Invalid repo add command: {}".format(call1_kargs.get("command")),
+            repo_update_command,
+            "Invalid repo update command: {}".format(call1_kargs.get("command")),
         )
         self.assertEqual(
             call1_kargs.get("env"),
             self.env,
-            "Invalid env for add command: {}".format(call1_kargs.get("env")),
+            "Invalid env for update command: {}".format(call1_kargs.get("env")),
         )
 
     @asynctest.fail_on(active_handles=True)