1212from .bundle import get_charm_series , is_local_charm
1313from .client import client
1414from .errors import JujuApplicationConfigError , JujuError
15- from .origin import Channel , Source
15+ from .origin import Channel
1616from .placement import parse as parse_placement
1717from .relation import Relation
1818from .status import derive_status
1919from .url import URL
2020from .utils import block_until
21+ from .version import DEFAULT_ARCHITECTURE
2122
2223log = logging .getLogger (__name__ )
2324
@@ -691,13 +692,15 @@ async def refresh(
691692 if charm_url_origin_result .error is not None :
692693 err = charm_url_origin_result .error
693694 raise JujuError (f'{ err .code } : { err .message } ' )
694- origin = charm_url_origin_result .charm_origin
695695
696+ current_origin = charm_url_origin_result .charm_origin
696697 if path is not None or (switch is not None and is_local_charm (switch )):
697- await self .local_refresh (origin , force , force_series ,
698+ await self .local_refresh (current_origin , force , force_series ,
698699 force_units , path or switch , resources )
699700 return
700701
702+ origin = _refresh_origin (current_origin , channel , revision )
703+
701704 # If switch is not None at this point, that means it's a switch to a store charm
702705 charm_url = switch or charm_url_origin_result .url
703706 parsed_url = URL .parse (charm_url )
@@ -706,20 +709,6 @@ async def refresh(
706709 if parsed_url .schema is None :
707710 raise JujuError (f'A ch: or cs: schema is required for application refresh, given : { str (parsed_url )} ' )
708711
709- if revision is not None :
710- origin .revision = revision
711-
712- # Make the source-specific changes to the origin/channel/url
713- # (and also get the resources necessary to deploy the (destination) charm -- for later)
714- origin .source = Source .CHARM_HUB .value
715- if channel :
716- ch = Channel .parse (channel ).normalize ()
717- origin .risk = ch .risk
718- origin .track = ch .track
719-
720- charmhub = self .model .charmhub
721- charm_resources = await charmhub .list_resources (charm_name )
722-
723712 # Resolve the given charm URLs with an optionally specified preferred channel.
724713 # Channel provided via CharmOrigin.
725714 resolved_charm_with_channel_results = await charms_facade .ResolveCharms (
@@ -761,8 +750,7 @@ async def refresh(
761750 else :
762751 _arg_res_filenames [res ] = filename_or_rev
763752
764- # Already prepped the charm_resources
765- # Now get the existing resources from the ResourcesFacade
753+ # Get the existing resources from the ResourcesFacade
766754 request_data = [client .Entity (self .tag )]
767755 resources_facade = client .ResourcesFacade .from_connection (self .connection )
768756 response = await resources_facade .ListResources (entities = request_data )
@@ -771,6 +759,9 @@ async def refresh(
771759 for resource in response .results [0 ].resources
772760 }
773761
762+ charmhub = self .model .charmhub
763+ charm_resources = await charmhub .list_resources (charm_name )
764+
774765 # Compute the difference btw resources needed and the existing resources
775766 resources_to_update = []
776767 for resource in charm_resources :
@@ -917,6 +908,20 @@ async def get_metrics(self):
917908 return await self .model .get_metrics (self .tag )
918909
919910
911+ def _refresh_origin (current_origin : client .CharmOrigin , channel = None , revision = None ) -> client .CharmOrigin :
912+ if channel is not None :
913+ channel = Channel .parse (channel ).normalize ()
914+
915+ return client .CharmOrigin (
916+ source = current_origin .source ,
917+ track = channel .track if channel else current_origin .track ,
918+ risk = channel .risk if channel else current_origin .risk ,
919+ revision = revision if revision is not None else current_origin .revision ,
920+ base = current_origin .base ,
921+ architecture = current_origin .get ('architecture' , DEFAULT_ARCHITECTURE ),
922+ )
923+
924+
920925class ExposedEndpoint :
921926 """ExposedEndpoint stores the list of CIDRs and space names which should be
922927 allowed access to the port ranges that the application has opened for a
0 commit comments