Skip to content

Commit da81293

Browse files
committed
In consume use controller from offer url
consume takes a controller_name argument. This is not needed and should be automatically generated from the offer url. A deprecation warning is logged and the variable is not used. Also update offer and consume integration tests to no longer be skipped.
1 parent fdf5e3c commit da81293

2 files changed

Lines changed: 16 additions & 7 deletions

File tree

juju/model.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1526,8 +1526,7 @@ async def integrate(self, relation1, relation2):
15261526
remote_endpoint.source = current.controller_name
15271527
# consume the remote endpoint
15281528
await self.consume(remote_endpoint.string(),
1529-
application_alias=remote_endpoint.application,
1530-
controller_name=remote_endpoint.source)
1529+
application_alias=remote_endpoint.application)
15311530

15321531
log.debug(
15331532
'Adding relation %s <-> %s', endpoints[0], endpoints[1])
@@ -2535,7 +2534,15 @@ async def consume(self, endpoint, application_alias="", controller_name=None, co
25352534
"""
25362535
Adds a remote offer to the model. Relations can be created later using
25372536
"juju relate".
2537+
2538+
If consuming a relation from a model on different controller the
2539+
controller name must be included in the endpoint. The controller_name
2540+
argument is being deprecated.
25382541
"""
2542+
if controller_name:
2543+
log.warning(
2544+
'controller_name argument will soon be deprecated, controller '
2545+
'should be specified in endpoint url')
25392546
if controller and controller_name:
25402547
raise JujuError("cannot set both controller_name and controller")
25412548
try:
@@ -2549,9 +2556,8 @@ async def consume(self, endpoint, application_alias="", controller_name=None, co
25492556
offer.user = self.info.username
25502557
endpoint = offer.string()
25512558

2552-
source = None
2553-
if controller_name:
2554-
source = await self._get_source_api(offer, controller_name=controller_name)
2559+
if offer.source:
2560+
source = await self._get_source_api(offer)
25552561
else:
25562562
if controller:
25572563
source = controller
@@ -2766,12 +2772,15 @@ async def revoke_secret(self, secret_name, application, *applications):
27662772
if result_error.error is not None:
27672773
raise JujuAPIError(result_error.error)
27682774

2769-
async def _get_source_api(self, url, controller_name=None):
2775+
async def _get_source_api(self, url):
27702776
controller = Controller()
27712777
if url.has_empty_source():
27722778
async with ConnectedController(self.connection()) as current:
27732779
if current.controller_name is not None:
27742780
controller_name = current.controller_name
2781+
else:
2782+
controller_name = url.source
2783+
27752784
await controller.connect(controller_name=controller_name)
27762785
return controller
27772786

tests/integration/test_crossmodel.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,4 +188,4 @@ async def test_add_bundle():
188188
await model_2.deploy('local:{}'.format(tmp_path))
189189
await model_2.wait_for_idle(status="active")
190190

191-
await model_1.remove_offer("admin/{}.influxdb".format(model_1.name), force=True)
191+
await model_1.remove_offer("admin/{}.influxdb".format(model_1.name), force=True)

0 commit comments

Comments
 (0)