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,
):
"""Add relation
- :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 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)
-
# Add relation
try:
- 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))
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_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")
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_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(
- relation1="app1:relation1", relation2="app2:relation2"
+ "app1:relation1", "saas_name"
)
mock_disconnect_controller.assert_called_once()
mock_disconnect_model.assert_called_once()