summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
bc538e4)
Before, app_1, endpoint1, app_2, endpoint2 parameters were needed.
Now we directly pass the endpoint names of the relation with the right format.
If "app:endpoint", it is understood that the endpoint it of a charm in the current model.
If "name", it is understood that the endpoint is a consumed endpoint from another model.
This function allows to cross-model-relate charms to external models
Change-Id: I84ab45ba735a1960ab742d9ec731c357ec1042c6
Signed-off-by: David Garcia <david.garcia@canonical.com>
async def add_relation(
self,
model_name: str,
async def add_relation(
self,
model_name: str,
- application_name_1: str,
- application_name_2: str,
- relation_1: str,
- relation_2: str,
+ endpoint_1: str,
+ endpoint_2: str,
- :param: model_name: Model name
- :param: application_name_1 First application name
- :param: application_name_2: Second application name
- :param: relation_1: First relation name
- :param: relation_2: Second relation name
+ :param: model_name: Model name
+ :param: endpoint_1 First endpoint name
+ ("app:endpoint" format or directly the saas name)
+ :param: endpoint_2: Second endpoint name (^ same format)
- self.log.debug("Adding relation: {} -> {}".format(relation_1, relation_2))
+ self.log.debug("Adding relation: {} -> {}".format(endpoint_1, endpoint_2))
# Get controller
controller = await self.get_controller()
# Get controller
controller = await self.get_controller()
# Get model
model = await self.get_model(controller, model_name)
# Get model
model = await self.get_model(controller, model_name)
- # Build relation strings
- r1 = "{}:{}".format(application_name_1, relation_1)
- r2 = "{}:{}".format(application_name_2, relation_2)
-
- await model.add_relation(relation1=r1, relation2=r2)
+ await model.add_relation(endpoint_1, endpoint_2)
except JujuAPIError as e:
if "not found" in e.message:
self.log.warning("Relation not found: {}".format(e.message))
except JujuAPIError as e:
if "not found" in e.message:
self.log.warning("Relation not found: {}".format(e.message))
try:
await self.libjuju.add_relation(
model_name=model_1,
try:
await self.libjuju.add_relation(
model_name=model_1,
- application_name_1=app_1,
- application_name_2=app_2,
- relation_1=endpoint_1,
- relation_2=endpoint_2,
+ endpoint_1="{}:{}".format(app_1, endpoint_1),
+ endpoint_2="{}:{}".format(app_2, endpoint_2),
)
except Exception as e:
message = "Error adding relation between {} and {}: {}".format(
)
except Exception as e:
message = "Error adding relation between {} and {}: {}".format(
mock_add_relation.side_effect = JujuAPIError(result)
self.loop.run_until_complete(
mock_add_relation.side_effect = JujuAPIError(result)
self.loop.run_until_complete(
- self.libjuju.add_relation(
- "model", "app1", "app2", "relation1", "relation2",
- )
+ self.libjuju.add_relation("model", "app1:relation1", "app2:relation2",)
)
mock_warning.assert_called_with("Relation not found: not found")
)
mock_warning.assert_called_with("Relation not found: not found")
mock_add_relation.side_effect = JujuAPIError(result)
self.loop.run_until_complete(
mock_add_relation.side_effect = JujuAPIError(result)
self.loop.run_until_complete(
- self.libjuju.add_relation(
- "model", "app1", "app2", "relation1", "relation2",
- )
+ self.libjuju.add_relation("model", "app1:relation1", "app2:relation2",)
)
mock_warning.assert_called_with("Relation already exists: already exists")
)
mock_warning.assert_called_with("Relation already exists: already exists")
with self.assertRaises(JujuAPIError):
self.loop.run_until_complete(
with self.assertRaises(JujuAPIError):
self.loop.run_until_complete(
- self.libjuju.add_relation(
- "model", "app1", "app2", "relation1", "relation2",
- )
+ self.libjuju.add_relation("model", "app1:relation1", "app2:relation2",)
)
mock_disconnect_controller.assert_called_once()
)
mock_disconnect_controller.assert_called_once()
mock_get_model.return_value = juju.model.Model()
self.loop.run_until_complete(
mock_get_model.return_value = juju.model.Model()
self.loop.run_until_complete(
- self.libjuju.add_relation(
- "model", "app1", "app2", "relation1", "relation2",
- )
+ self.libjuju.add_relation("model", "app1:relation1", "app2:relation2",)
+ )
+
+ mock_add_relation.assert_called_with(
+ "app1:relation1", "app2:relation2"
+ )
+ mock_disconnect_controller.assert_called_once()
+ mock_disconnect_model.assert_called_once()
+
+ def test_saas(
+ self,
+ mock_add_relation,
+ mock_disconnect_controller,
+ mock_disconnect_model,
+ mock_get_model,
+ mock_get_controller,
+ ):
+ mock_get_model.return_value = juju.model.Model()
+
+ self.loop.run_until_complete(
+ self.libjuju.add_relation("model", "app1:relation1", "saas_name",)
)
mock_add_relation.assert_called_with(
)
mock_add_relation.assert_called_with(
- relation1="app1:relation1", relation2="app2:relation2"
+ "app1:relation1", "saas_name"
)
mock_disconnect_controller.assert_called_once()
mock_disconnect_model.assert_called_once()
)
mock_disconnect_controller.assert_called_once()
mock_disconnect_model.assert_called_once()