@@ -625,52 +625,30 @@ async def refresh(
625625
626626 app_facade = self ._facade ()
627627
628- charmstore = self .model .charmstore
629- charmstore_entity = None
630-
631- if switch is not None :
632- charm_url = switch
633- if not charm_url .startswith ('cs:' ):
634- charm_url = 'cs:' + charm_url
635- else :
636- charm_url = self .data ['charm-url' ]
637- charm_url = charm_url .rpartition ('-' )[0 ]
638- if revision is not None :
639- charm_url = "%s-%d" % (charm_url , revision )
640- else :
641- charmstore_entity = await charmstore .entity (charm_url ,
642- channel = channel )
643- charm_url = charmstore_entity ['Id' ]
644-
645- if charm_url == self .data ['charm-url' ]:
646- raise JujuError ('already running charm "%s"' % charm_url )
647-
648- # Update charm
649- await client_facade .AddCharm (
650- url = charm_url ,
651- force = force ,
652- channel = channel
653- )
654- charm_url = self .data ['charm-url' ]
655- parsed_url = URL .parse (charm_url )
628+ url = switch or self .data ['charm-url' ]
629+ parsed_url = URL .parse (url )
656630 charm_name = parsed_url .name
657631
658632 # First we need to make sure we have the resources for the charm that's
659633 # coming
660634
635+ if parsed_url .schema is None :
636+ raise JujuError (f'A ch: or cs: schema is required for application refresh, given : { str (parsed_url )} ' )
637+
661638 # Get the list of resources needed to deploy this charm
662639 if Schema .CHARM_HUB .matches (parsed_url .schema ):
663640 # Charmhub charms
664641 charmhub = self .model .charmhub
665642 charm_resources = await charmhub .list_resources (charm_name )
666643
667- charm_url_origin_result = await app_facade .GetCharmURLOrigin (application = charm_name )
644+ charm_url_origin_result = await app_facade .GetCharmURLOrigin (application = self . name )
668645
669646 if charm_url_origin_result .error is not None :
670647 err = charm_url_origin_result .error
671648 raise JujuError (f'{ err .code } : { err .message } ' )
672- charm_url = charm_url_origin_result .url
649+ charm_url = switch or charm_url_origin_result .url
673650 origin = charm_url_origin_result .charm_origin
651+ origin .source = 'charm-hub'
674652
675653 if channel :
676654 ch = Channel .parse (channel ).normalize ()
@@ -680,7 +658,7 @@ async def refresh(
680658 charms_facade = client .CharmsFacade .from_connection (self .connection )
681659 resolved_charm_with_channel_results = await charms_facade .ResolveCharms (resolve = [client .ResolveCharmWithChannel (
682660 charm_origin = origin ,
683- switch_charm = False ,
661+ switch_charm = True if switch else False , # rpc expects boolean type
684662 reference = charm_url ,
685663 )])
686664 resolved_charm = resolved_charm_with_channel_results .results [0 ]
0 commit comments