Fix bug 2149 07/12507/3
authorPatricia Reinoso <patricia.reinoso@canonical.com>
Tue, 30 Aug 2022 16:08:48 +0000 (16:08 +0000)
committercalvinosanc1 <guillermo.calvino@canonical.com>
Thu, 1 Sep 2022 13:53:34 +0000 (15:53 +0200)
Set appropriate delete method for
cluster role bindings in case of exception

Change-Id: I187ec50dbec37ed9ff51e18234ab51e02c42ce40
Signed-off-by: Patricia Reinoso <patricia.reinoso@canonical.com>
n2vc/k8s_juju_conn.py
n2vc/tests/unit/test_k8s_juju_conn.py

index 396d79b..6708748 100644 (file)
@@ -156,7 +156,7 @@ class K8sJujuConnector(K8sConnector):
             self.log.debug("Role binding created")
             cleanup_data.append(
                 {
-                    "delete": kubectl.delete_service_account,
+                    "delete": kubectl.delete_cluster_role_binding,
                     "args": (metadata_name,),
                 }
             )
index 3e35494..6119d50 100644 (file)
@@ -134,9 +134,15 @@ class InitEnvTest(K8sJujuConnTestCase):
             uuid, created = self.loop.run_until_complete(
                 self.k8s_juju_conn.init_env(k8s_creds=kubeconfig)
             )
-
         self.assertIsNone(created)
         self.assertIsNone(uuid)
+        self.kubectl.create_cluster_role.assert_called_once()
+        self.kubectl.create_service_account.assert_called_once()
+        self.kubectl.create_cluster_role_binding.assert_called_once()
+        self.kubectl.get_default_storage_class.assert_called_once()
+        self.kubectl.delete_cluster_role.assert_called_once()
+        self.kubectl.delete_service_account.assert_called_once()
+        self.kubectl.delete_cluster_role_binding.assert_called_once()
         self.k8s_juju_conn.libjuju.add_k8s.assert_called_once()