From 9a63e8d905b4b98f567acccce745b39919fa6860 Mon Sep 17 00:00:00 2001 From: David Garcia Date: Tue, 3 Nov 2020 20:37:06 +0100 Subject: [PATCH] Feature 9952: Distributed Proxy Charms 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 --- n2vc/n2vc_juju_conn.py | 34 +++++++++++++++++++++++--- n2vc/tests/unit/test_n2vc_juju_conn.py | 6 ++++- 2 files changed, 35 insertions(+), 5 deletions(-) diff --git a/n2vc/n2vc_juju_conn.py b/n2vc/n2vc_juju_conn.py index 50c0c99..2566b0c 100644 --- a/n2vc/n2vc_juju_conn.py +++ b/n2vc/n2vc_juju_conn.py @@ -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: diff --git a/n2vc/tests/unit/test_n2vc_juju_conn.py b/n2vc/tests/unit/test_n2vc_juju_conn.py index 663f2ba..bad5fc3 100644 --- a/n2vc/tests/unit/test_n2vc_juju_conn.py +++ b/n2vc/tests/unit/test_n2vc_juju_conn.py @@ -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", -- 2.25.1