From: garciadeblas Date: Wed, 4 May 2022 08:57:36 +0000 (+0200) Subject: Update helm repo after adding the repo X-Git-Tag: v12.0.0rc1~19 X-Git-Url: https://osm.etsi.org/gitweb/?p=osm%2FN2VC.git;a=commitdiff_plain;h=refs%2Fchanges%2F70%2F11870%2F4 Update helm repo after adding the repo Change-Id: I4cd2a073cb862fac4d7646e65f7b3df6068a1c5a Signed-off-by: garciadeblas --- diff --git a/n2vc/k8s_helm_base_conn.py b/n2vc/k8s_helm_base_conn.py index 57010d1..9b0ca86 100644 --- a/n2vc/k8s_helm_base_conn.py +++ b/n2vc/k8s_helm_base_conn.py @@ -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) diff --git a/n2vc/tests/unit/test_k8s_helm3_conn.py b/n2vc/tests/unit/test_k8s_helm3_conn.py index 91e1729..775b0a7 100644 --- a/n2vc/tests/unit/test_k8s_helm3_conn.py +++ b/n2vc/tests/unit/test_k8s_helm3_conn.py @@ -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) diff --git a/n2vc/tests/unit/test_k8s_helm_conn.py b/n2vc/tests/unit/test_k8s_helm_conn.py index 736405f..ae9338d 100644 --- a/n2vc/tests/unit/test_k8s_helm_conn.py +++ b/n2vc/tests/unit/test_k8s_helm_conn.py @@ -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)