Skip to content

Commit 55690bb

Browse files
authored
Merge pull request #757 from cderici/local-refresh-with-resoruces
#757 #### Description This fixes the regression where we don't accept local refresh (`upgrade-charm`) with resources. Fixes #756 #### QA Steps Added an additional test to catch this in the future: ``` tox -e integration -- tests/integration/test_application.py::test_upgrade_local_charm_resource ```
2 parents 9812e91 + fc161ff commit 55690bb

2 files changed

Lines changed: 24 additions & 3 deletions

File tree

juju/application.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -637,14 +637,11 @@ async def refresh(
637637
:param str switch: Crossgrade charm url
638638
639639
"""
640-
if resources is not None:
641-
raise NotImplementedError("resources option is not implemented")
642640

643641
if switch is not None and revision is not None:
644642
raise ValueError("switch and revision are mutually exclusive")
645643

646644
app_facade = self._facade()
647-
resources_facade = client.ResourcesFacade.from_connection(self.connection)
648645
charms_facade = client.CharmsFacade.from_connection(self.connection)
649646

650647
# 1 - Figure out the destination origin and destination charm_url
@@ -664,6 +661,9 @@ async def refresh(
664661
force_units, path, resources)
665662
return
666663

664+
if resources is not None:
665+
raise NotImplementedError("resources option is not implemented")
666+
667667
parsed_url = URL.parse(charm_url)
668668
charm_name = parsed_url.name
669669

@@ -731,6 +731,7 @@ async def refresh(
731731
# Already prepped the charm_resources
732732
# Now get the existing resources from the ResourcesFacade
733733
request_data = [client.Entity(self.tag)]
734+
resources_facade = client.ResourcesFacade.from_connection(self.connection)
734735
response = await resources_facade.ListResources(entities=request_data)
735736
existing_resources = {
736737
resource.name: resource

tests/integration/test_application.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,26 @@ async def test_upgrade_local_charm(event_loop):
264264
assert app.data['charm-url'] == 'local:focal/ubuntu-0'
265265

266266

267+
@base.bootstrapped
268+
@pytest.mark.asyncio
269+
async def test_upgrade_local_charm_resource(event_loop):
270+
async with base.CleanModel() as model:
271+
tests_dir = Path(__file__).absolute().parent
272+
charm_path = tests_dir / 'file-resource-charm'
273+
resources = {"file-res": "test.file"}
274+
275+
app = await model.deploy(str(charm_path), resources=resources)
276+
assert 'file-resource-charm' in model.applications
277+
await model.wait_for_idle()
278+
assert app.units[0].agent_status == 'idle'
279+
280+
await app.upgrade_charm(path=charm_path, resources=resources)
281+
await model.wait_for_idle()
282+
ress = await app.get_resources()
283+
assert 'file-res' in ress
284+
assert ress['file-res']
285+
286+
267287
@base.bootstrapped
268288
@pytest.mark.asyncio
269289
@pytest.mark.skip('Update charm')

0 commit comments

Comments
 (0)