diff --git a/juju/application.py b/juju/application.py index 6e05e091..7d6b481c 100644 --- a/juju/application.py +++ b/juju/application.py @@ -4,7 +4,7 @@ import hashlib import json import logging -import pathlib +from pathlib import Path from . import model, tag, utils, jasyncio from .url import URL, Schema @@ -12,7 +12,7 @@ from .annotationhelper import _get_annotations, _set_annotations from .client import client from .errors import JujuError, JujuApplicationConfigError -from .bundle import get_charm_series +from .bundle import get_charm_series, is_local_charm from .placement import parse as parse_placement from .origin import Channel @@ -654,14 +654,14 @@ async def refresh( if charm_url_origin_result.error is not None: err = charm_url_origin_result.error raise JujuError("%s : %s" % (err.code, err.message)) - charm_url = switch or charm_url_origin_result.url origin = charm_url_origin_result.charm_origin - if path is not None: + if path is not None or (switch is not None and is_local_charm(switch)): await self.local_refresh(origin, force, force_series, - force_units, path, resources) + force_units, path or switch, resources) return + charm_url = switch or charm_url_origin_result.url parsed_url = URL.parse(charm_url) charm_name = parsed_url.name @@ -810,8 +810,9 @@ async def local_refresh( """ app_facade = self._facade() - if not isinstance(path, pathlib.Path): - path = pathlib.Path(path) + if isinstance(path, str) and path.startswith("local:"): + path = path[6:] + path = Path(path) charm_dir = path.expanduser().resolve() model_config = await self.get_config() diff --git a/tests/integration/test_application.py b/tests/integration/test_application.py index d9bf3d64..5b22c4e7 100644 --- a/tests/integration/test_application.py +++ b/tests/integration/test_application.py @@ -241,6 +241,20 @@ async def test_upgrade_charm_resource_same_rev_no_update(event_loop): assert ress['policyd-override'].fingerprint == ress2['policyd-override'].fingerprint +@base.bootstrapped +@pytest.mark.asyncio +async def test_refresh_charmhub_to_local(event_loop): + charm_path = INTEGRATION_TEST_DIR / 'charm' + async with base.CleanModel() as model: + app = await model.deploy('ubuntu', application_name='ubu-path') + await app.refresh(path=str(charm_path)) + assert app.data['charm-url'].startswith('local:') + + app = await model.deploy('ubuntu', application_name='ubu-switch') + await app.refresh(switch=str(charm_path)) + assert app.data['charm-url'].startswith('local:') + + @base.bootstrapped @pytest.mark.asyncio async def test_upgrade_local_charm_with_resource(event_loop):