Feature 9952: Distributed Proxy Charms 37/9937/4
authorDavid Garcia <david.garcia@canonical.com>
Tue, 3 Nov 2020 19:37:06 +0000 (20:37 +0100)
committergarciadav <david.garcia@canonical.com>
Mon, 9 Nov 2020 13:06:29 +0000 (14:06 +0100)
Add cloud_name and cloud_credential arguments in these functions to
allow allocating proxy charms in different clouds:
  - create_execution_environment
  - register_execution_environment
  - install_k8s_proxy_charm
Change-Id: I3e57c6e5b9e25f9abfb7a579a188cf98d457e2b2
Signed-off-by: David Garcia <david.garcia@canonical.com>
n2vc/n2vc_juju_conn.py
n2vc/tests/unit/test_n2vc_juju_conn.py

index 50c0c99..2566b0c 100644 (file)
@@ -228,6 +228,8 @@ class N2VCJujuConnector(N2VCConnector):
         reuse_ee_id: str = None,
         progress_timeout: float = None,
         total_timeout: float = None,
+        cloud_name: str = None,
+        credential_name: str = None,
     ) -> (str, dict):
 
         self.log.info(
@@ -263,7 +265,13 @@ class N2VCJujuConnector(N2VCConnector):
         # create or reuse a new juju machine
         try:
             if not await self.libjuju.model_exists(model_name):
-                await self.libjuju.add_model(model_name, cloud_name=self.cloud)
+                cloud = cloud_name or self.cloud
+                credential = credential_name or cloud_name if cloud_name else self.cloud
+                await self.libjuju.add_model(
+                    model_name,
+                    cloud_name=cloud,
+                    credential_name=credential
+                )
             machine, new = await self.libjuju.create_machine(
                 model_name=model_name,
                 machine_id=machine_id,
@@ -308,6 +316,8 @@ class N2VCJujuConnector(N2VCConnector):
         db_dict: dict,
         progress_timeout: float = None,
         total_timeout: float = None,
+        cloud_name: str = None,
+        credential_name: str = None,
     ) -> str:
 
         self.log.info(
@@ -350,7 +360,13 @@ class N2VCJujuConnector(N2VCConnector):
         # register machine on juju
         try:
             if not await self.libjuju.model_exists(model_name):
-                await self.libjuju.add_model(model_name, cloud_name=self.cloud)
+                cloud = cloud_name or self.cloud
+                credential = credential_name or cloud_name if cloud_name else self.cloud
+                await self.libjuju.add_model(
+                    model_name,
+                    cloud_name=cloud,
+                    credential_name=credential
+                )
             machine_id = await self.libjuju.provision_machine(
                 model_name=model_name,
                 hostname=hostname,
@@ -472,6 +488,8 @@ class N2VCJujuConnector(N2VCConnector):
         progress_timeout: float = None,
         total_timeout: float = None,
         config: dict = None,
+        cloud_name: str = None,
+        credential_name: str = None,
     ) -> str:
         """
         Install a k8s proxy charm
@@ -490,6 +508,9 @@ class N2VCJujuConnector(N2VCConnector):
         :param float progress_timeout:
         :param float total_timeout:
         :param config: Dictionary with additional configuration
+        :param cloud_name: Cloud Name in which the charms will be deployed
+        :param credential_name: Credential Name to use in the cloud_name.
+                                If not set, cloud_name will be used as credential_name
 
         :returns ee_id: execution environment id.
         """
@@ -522,8 +543,13 @@ class N2VCJujuConnector(N2VCConnector):
 
         _, ns_id, _, _, _ = self._get_namespace_components(namespace=namespace)
         model_name = '{}-k8s'.format(ns_id)
-
-        await self.libjuju.add_model(model_name, self.k8s_cloud)
+        cloud = cloud_name or self.k8s_cloud
+        credential = credential_name or cloud_name if cloud_name else self.k8s_cloud
+        await self.libjuju.add_model(
+            model_name,
+            cloud_name=cloud,
+            credential_name=credential
+        )
         application_name = self._get_application_name(namespace)
 
         try:
index 663f2ba..bad5fc3 100644 (file)
@@ -102,7 +102,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",