Skip to content

Commit 75336d2

Browse files
committed
Pass series info into origin for ResolveCharm
Without the series the ResolveCharm will select the latest base for the charm. E.g. even if we want focal, the ResolveCharm will return 22.04 (jammy) for the base channel in the resulting origin if the charm supports both jammy and focal. This communicates the series info with the ResolveCharm via the inputted origin so the resulting origin will have the correct base channel. Fixes #822
1 parent 302021e commit 75336d2

1 file changed

Lines changed: 18 additions & 14 deletions

File tree

juju/model.py

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -552,23 +552,14 @@ async def resolve(self, url, architecture, app_name=None, channel=None, series=N
552552
origin = client.CharmOrigin(source="charm-hub",
553553
architecture=architecture,
554554
risk=ch.risk,
555-
track=ch.track)
555+
track=ch.track,
556+
series=series)
556557

557-
charm_url_str, origin, supported_series = await self.charm_resolver(url, origin)
558-
charm_url = URL.parse(charm_url_str)
558+
charm_url, origin = await self.charm_resolver(url, origin, force)
559559

560560
if app_name is None:
561561
app_name = url.name
562562

563-
if series:
564-
# Check whether the charm supports this series
565-
# or we force it
566-
if series in supported_series or force:
567-
origin.series = series
568-
charm_url.series = series
569-
else:
570-
raise JujuError("Series {} not supported for {}. Only {}".format(series, url, supported_series))
571-
572563
return DeployTypeResult(
573564
identifier=str(charm_url),
574565
app_name=app_name,
@@ -1722,7 +1713,7 @@ async def _add_charm(self, charm_url, origin):
17221713
client_facade = client.ClientFacade.from_connection(self.connection())
17231714
return await client_facade.AddCharm(channel=str(origin.risk), url=charm_url, force=False)
17241715

1725-
async def _resolve_charm(self, url, origin):
1716+
async def _resolve_charm(self, url, origin, force):
17261717
charms_cls = client.CharmsFacade
17271718
if charms_cls.best_facade_version(self.connection()) < 3:
17281719
raise JujuError("resolve charm")
@@ -1733,9 +1724,11 @@ async def _resolve_charm(self, url, origin):
17331724
source = "charm-store"
17341725
else:
17351726
source = "charm-hub"
1727+
17361728
resp = await charms_facade.ResolveCharms(resolve=[{
17371729
'reference': str(url),
17381730
'charm-origin': {
1731+
'series': origin.series,
17391732
'source': source,
17401733
'architecture': origin.architecture,
17411734
'track': origin.track,
@@ -1749,7 +1742,18 @@ async def _resolve_charm(self, url, origin):
17491742
if result.error:
17501743
raise JujuError(result.error.message)
17511744

1752-
return (result.url, result.charm_origin, result.supported_series)
1745+
supported_series = result.supported_series
1746+
charm_url = URL.parse(result.url)
1747+
if origin.series:
1748+
# Check whether the charm supports this series
1749+
# or we force it
1750+
if origin.series in supported_series or force:
1751+
result.charm_origin.series = origin.series
1752+
charm_url.series = origin.series
1753+
else:
1754+
raise JujuError("Series {} not supported for {}. Only {}".format(origin.series, result.url, supported_series))
1755+
1756+
return charm_url, result.charm_origin
17531757

17541758
async def _resolve_architecture(self, url):
17551759
if url.architecture:

0 commit comments

Comments
 (0)