Skip to content

Commit 768d7ff

Browse files
authored
Merge pull request #660 from jack-w-shaw/JUJU-796_use_relate
[JUJU-796] Add relate method and deprecate add-relation #### Description This is to follow the pattern we are following going ahead with Juju. change the name of add-relation to relate, but keep add-relation, which calls relate for backwards compatibility This method should then be removed at the next major version bump See this PR for more details juju/juju#13907 #### QA Steps ```sh tox -e integration tox -e unit ```
2 parents 8c938c9 + d810ec6 commit 768d7ff

10 files changed

Lines changed: 30 additions & 16 deletions

File tree

docs/narrative/application.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ application. The `mysql_app` object is an instance of
9595
9696
Adding and Removing Relations
9797
-----------------------------
98-
The :meth:`juju.application.Application.add_relation` method returns a
98+
The :meth:`juju.application.Application.relate` method returns a
9999
:class:`juju.relation.Relation` instance.
100100

101101
.. code:: python
@@ -122,7 +122,7 @@ The :meth:`juju.application.Application.add_relation` method returns a
122122
)
123123
124124
# Add the master-slave relation
125-
relation = await mysql_master.add_relation(
125+
relation = await mysql_master.relate(
126126
# Name of the relation on the local (mysql-master) side
127127
'master',
128128
# Name of the app:relation on the remote side

examples/crossmodel_relation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ async def main():
6666
lambda: all(unit.agent_status == 'executing'
6767
for unit in application_2.units))
6868

69-
await consuming_model.add_relation('wordpress', 'admin/test-cmr-1.mysql')
69+
await consuming_model.relate('wordpress', 'admin/test-cmr-1.mysql')
7070

7171
print('Exporting bundle')
7272
with tempfile.TemporaryDirectory() as dirpath:

examples/future.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ async def main():
2929
channel='stable',
3030
num_units=0,
3131
)
32-
await model.add_relation(
32+
await model.relate(
3333
'ubuntu',
3434
'nrpe',
3535
)

examples/relate.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ async def main():
8383
# subordinates must be deployed without units
8484
num_units=0,
8585
)
86-
my_relation = await model.add_relation(
86+
my_relation = await model.relate(
8787
'ubuntu',
8888
'nrpe',
8989
)

juju/application.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,13 @@ def tag(self):
107107
return tag.application(self.name)
108108

109109
async def add_relation(self, local_relation, remote_relation):
110+
"""
111+
.. deprecated:: 2.9.9
112+
Use ``relate()`` instead
113+
"""
114+
return await self.relate(local_relation, remote_relation)
115+
116+
async def relate(self, local_relation, remote_relation):
110117
"""Add a relation to another application.
111118
112119
:param str local_relation: Name of relation on this application
@@ -117,7 +124,7 @@ async def add_relation(self, local_relation, remote_relation):
117124
if ':' not in local_relation:
118125
local_relation = '{}:{}'.format(self.name, local_relation)
119126

120-
return await self.model.add_relation(local_relation, remote_relation)
127+
return await self.model.relate(local_relation, remote_relation)
121128

122129
async def add_unit(self, count=1, to=None):
123130
"""Add one or more units to this application.

juju/bundle.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -894,7 +894,7 @@ async def run(self, context):
894894
return existing[0]
895895

896896
log.info('Relating %s <-> %s', ep1, ep2)
897-
return await context.model.add_relation(ep1, ep2)
897+
return await context.model.relate(ep1, ep2)
898898

899899
def __str__(self):
900900
return "add relation {endpoint1} - {endpoint2}".format(endpoint1=self.endpoint1,

juju/model.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1342,6 +1342,13 @@ async def add_machine(
13421342
return await self._wait_for_new('machine', machine_id)
13431343

13441344
async def add_relation(self, relation1, relation2):
1345+
"""
1346+
.. deprecated:: 2.9.9
1347+
Use ``relate()`` instead
1348+
"""
1349+
return await self.relate(relation1, relation2)
1350+
1351+
async def relate(self, relation1, relation2):
13451352
"""Add a relation between two applications.
13461353
13471354
:param str relation1: '<application>[:<relation_name>]'

tests/integration/test_crossmodel.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ async def test_remove_saas(event_loop):
9393

9494
@base.bootstrapped
9595
@pytest.mark.asyncio
96-
async def test_add_relation_with_offer(event_loop):
96+
async def test_relate_with_offer(event_loop):
9797
pytest.skip('Revise: intermittent problem with the remove_saas call')
9898
async with base.CleanModel() as model_1:
9999
application = await model_1.deploy(
@@ -123,7 +123,7 @@ async def test_add_relation_with_offer(event_loop):
123123
lambda: all(unit.agent_status == 'idle'
124124
for unit in application.units))
125125

126-
await model_2.add_relation("mediawiki:db", "admin/{}.mysql".format(model_1.info.name))
126+
await model_2.relate("mediawiki:db", "admin/{}.mysql".format(model_1.info.name))
127127
status = await model_2.get_status()
128128
if 'mysql' not in status.remote_applications:
129129
raise Exception("Expected mysql in saas")

tests/integration/test_model.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -556,7 +556,7 @@ async def mock_AddRelation(*args, **kwargs):
556556

557557
with mock.patch.object(ApplicationFacade, 'from_connection',
558558
return_value=mock_app_facade):
559-
my_relation = await run_with_interrupt(model.add_relation(
559+
my_relation = await run_with_interrupt(model.relate(
560560
'ubuntu',
561561
'nrpe',
562562
), timeout)

tests/unit/test_bundle.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -559,7 +559,7 @@ async def test_run(self, event_loop):
559559
rel2 = mock.Mock(name="rel2", **{"matches.return_value": True})
560560

561561
model = mock.Mock()
562-
model.add_relation = base.AsyncMock(return_value=rel2)
562+
model.relate = base.AsyncMock(return_value=rel2)
563563

564564
context = mock.Mock()
565565
context.resolve_relation = mock.Mock(side_effect=['endpoint_1', 'endpoint_2'])
@@ -569,17 +569,17 @@ async def test_run(self, event_loop):
569569
result = await change.run(context)
570570
assert result is rel2
571571

572-
model.add_relation.assert_called_once()
573-
model.add_relation.assert_called_with("endpoint_1", "endpoint_2")
572+
model.relate.assert_called_once()
573+
model.relate.assert_called_with("endpoint_1", "endpoint_2")
574574

575575
# confirm that it's idempotent
576576
context.resolve_relation = mock.Mock(side_effect=['endpoint_1', 'endpoint_2'])
577-
model.add_relation.reset_mock()
578-
model.add_relation.return_value = None
577+
model.relate.reset_mock()
578+
model.relate.return_value = None
579579
model.relations = [rel1, rel2]
580580
result = await change.run(context)
581581
assert result is rel2
582-
assert not model.add_relation.called
582+
assert not model.relate.called
583583

584584

585585
class TestAddUnitChange(unittest.TestCase):

0 commit comments

Comments
 (0)