Fix bug 1467
[osm/N2VC.git] / n2vc / tests / unit / test_n2vc_juju_conn.py
index 4044637..64b93cc 100644 (file)
@@ -26,6 +26,7 @@ from n2vc.exceptions import (
 
 
 class N2VCJujuConnTestCase(asynctest.TestCase):
 
 
 class N2VCJujuConnTestCase(asynctest.TestCase):
+    @asynctest.mock.patch("n2vc.libjuju.Libjuju._create_health_check_task")
     @asynctest.mock.patch("juju.controller.Controller.update_endpoints")
     @asynctest.mock.patch("juju.client.connector.Connector.connect")
     @asynctest.mock.patch("juju.controller.Controller.connection")
     @asynctest.mock.patch("juju.controller.Controller.update_endpoints")
     @asynctest.mock.patch("juju.client.connector.Connector.connect")
     @asynctest.mock.patch("juju.controller.Controller.connection")
@@ -36,7 +37,9 @@ class N2VCJujuConnTestCase(asynctest.TestCase):
         mock_connection=None,
         mock_connect=None,
         mock_update_endpoints=None,
         mock_connection=None,
         mock_connect=None,
         mock_update_endpoints=None,
+        mock__create_health_check_task=None,
     ):
     ):
+        mock__get_api_endpoints_db.return_value = ["2.2.2.2:17070"]
         loop = asyncio.get_event_loop()
         db = {}
         vca_config = {
         loop = asyncio.get_event_loop()
         db = {}
         vca_config = {
@@ -78,6 +81,7 @@ class GetMetricssTest(N2VCJujuConnTestCase):
         mock_get_metrics.assert_called_once()
 
 
         mock_get_metrics.assert_called_once()
 
 
+@asynctest.mock.patch("n2vc.libjuju.Libjuju.model_exists")
 @asynctest.mock.patch("osm_common.fslocal.FsLocal.file_exists")
 @asynctest.mock.patch(
     "osm_common.fslocal.FsLocal.path", new_callable=asynctest.PropertyMock, create=True
 @asynctest.mock.patch("osm_common.fslocal.FsLocal.file_exists")
 @asynctest.mock.patch(
     "osm_common.fslocal.FsLocal.path", new_callable=asynctest.PropertyMock, create=True
@@ -89,8 +93,9 @@ class K8sProxyCharmsTest(N2VCJujuConnTestCase):
         super(K8sProxyCharmsTest, self).setUp()
 
     def test_success(
         super(K8sProxyCharmsTest, self).setUp()
 
     def test_success(
-        self, mock_add_model, mock_deploy_charm, mock_path, mock_file_exists,
+        self, mock_add_model, mock_deploy_charm, mock_path, mock_file_exists, mock_model_exists
     ):
     ):
+        mock_model_exists.return_value = None
         mock_file_exists.return_value = True
         mock_path.return_value = "/path"
         ee_id = self.loop.run_until_complete(
         mock_file_exists.return_value = True
         mock_path.return_value = "/path"
         ee_id = self.loop.run_until_complete(
@@ -99,7 +104,11 @@ class K8sProxyCharmsTest(N2VCJujuConnTestCase):
             )
         )
 
             )
         )
 
-        mock_add_model.assert_called_once_with("ns-id-k8s", "k8s_cloud")
+        mock_add_model.assert_called_once_with(
+            "ns-id-k8s",
+            cloud_name=self.n2vc.k8s_cloud,
+            credential_name=self.n2vc.k8s_cloud
+        )
         mock_deploy_charm.assert_called_once_with(
             model_name="ns-id-k8s",
             application_name="app-vnf-vnf-id-vdu-vdu",
         mock_deploy_charm.assert_called_once_with(
             model_name="ns-id-k8s",
             application_name="app-vnf-vnf-id-vdu-vdu",
@@ -124,6 +133,7 @@ class K8sProxyCharmsTest(N2VCJujuConnTestCase):
         mock_deploy_charm,
         mock_path,
         mock_file_exists,
         mock_deploy_charm,
         mock_path,
         mock_file_exists,
+        mock_model_exists,
     ):
         mock_k8s_cloud.return_value = None
         with self.assertRaises(JujuK8sProxycharmNotSupported):
     ):
         mock_k8s_cloud.return_value = None
         with self.assertRaises(JujuK8sProxycharmNotSupported):
@@ -135,7 +145,7 @@ class K8sProxyCharmsTest(N2VCJujuConnTestCase):
             self.assertIsNone(ee_id)
 
     def test_no_artifact_path(
             self.assertIsNone(ee_id)
 
     def test_no_artifact_path(
-        self, mock_add_model, mock_deploy_charm, mock_path, mock_file_exists,
+        self, mock_add_model, mock_deploy_charm, mock_path, mock_file_exists, mock_model_exists,
     ):
         with self.assertRaises(N2VCBadArgumentsException):
             ee_id = self.loop.run_until_complete(
     ):
         with self.assertRaises(N2VCBadArgumentsException):
             ee_id = self.loop.run_until_complete(
@@ -146,7 +156,7 @@ class K8sProxyCharmsTest(N2VCJujuConnTestCase):
             self.assertIsNone(ee_id)
 
     def test_no_db(
             self.assertIsNone(ee_id)
 
     def test_no_db(
-        self, mock_add_model, mock_deploy_charm, mock_path, mock_file_exists,
+        self, mock_add_model, mock_deploy_charm, mock_path, mock_file_exists, mock_model_exists,
     ):
         with self.assertRaises(N2VCBadArgumentsException):
             ee_id = self.loop.run_until_complete(
     ):
         with self.assertRaises(N2VCBadArgumentsException):
             ee_id = self.loop.run_until_complete(
@@ -157,7 +167,7 @@ class K8sProxyCharmsTest(N2VCJujuConnTestCase):
             self.assertIsNone(ee_id)
 
     def test_file_not_exists(
             self.assertIsNone(ee_id)
 
     def test_file_not_exists(
-        self, mock_add_model, mock_deploy_charm, mock_path, mock_file_exists,
+        self, mock_add_model, mock_deploy_charm, mock_path, mock_file_exists, mock_model_exists,
     ):
         mock_file_exists.return_value = False
         with self.assertRaises(N2VCBadArgumentsException):
     ):
         mock_file_exists.return_value = False
         with self.assertRaises(N2VCBadArgumentsException):
@@ -169,8 +179,9 @@ class K8sProxyCharmsTest(N2VCJujuConnTestCase):
             self.assertIsNone(ee_id)
 
     def test_exception(
             self.assertIsNone(ee_id)
 
     def test_exception(
-        self, mock_add_model, mock_deploy_charm, mock_path, mock_file_exists,
+        self, mock_add_model, mock_deploy_charm, mock_path, mock_file_exists, mock_model_exists,
     ):
     ):
+        mock_model_exists.return_value = None
         mock_file_exists.return_value = True
         mock_path.return_value = "/path"
         mock_deploy_charm.side_effect = Exception()
         mock_file_exists.return_value = True
         mock_path.return_value = "/path"
         mock_deploy_charm.side_effect = Exception()