Skip to content

Commit b59ef43

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 d33a98e commit b59ef43

1 file changed

Lines changed: 20 additions & 15 deletions

File tree

juju/model.py

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -515,28 +515,19 @@ async def resolve(self, url, architecture, app_name=None, channel=None, series=N
515515
track=ch.track,
516516
base=base,
517517
revision=revision,
518+
series=series
518519
)
519520

520-
charm_url_str, origin, supported_series = await self.charm_resolver(url, origin)
521-
522521
is_bundle = origin.type_ == "bundle"
523522
if is_bundle and revision and channel:
524523
raise JujuError('revision and channel are mutually exclusive when deploying a bundle. Please choose one.')
525524

526-
charm_url = URL.parse(charm_url_str)
525+
526+
charm_url, origin = await self.charm_resolver(url, origin, force)
527527

528528
if app_name is None:
529529
app_name = url.name
530530

531-
if series:
532-
# Check whether the charm supports this series
533-
# or we force it
534-
if series in supported_series or force:
535-
origin.series = series
536-
charm_url.series = series
537-
else:
538-
raise JujuError("Series {} not supported for {}. Only {}".format(series, url, supported_series))
539-
540531
return DeployTypeResult(
541532
identifier=str(charm_url),
542533
app_name=app_name,
@@ -1799,7 +1790,8 @@ async def _add_charm(self, charm_url, origin):
17991790
client_facade = client.ClientFacade.from_connection(self.connection())
18001791
return await client_facade.AddCharm(channel=str(origin.risk), url=charm_url, force=False)
18011792

1802-
async def _resolve_charm(self, url, origin):
1793+
1794+
async def _resolve_charm(self, url, origin, force):
18031795
"""Calls Charms.ResolveCharms to resolve all the fields of the
18041796
charm_origin and also the url and the supported_series
18051797
@@ -1826,7 +1818,9 @@ async def _resolve_charm(self, url, origin):
18261818

18271819
resolve_origin = {'source': source, 'architecture': origin.architecture,
18281820
'track': origin.track, 'risk': origin.risk,
1829-
'base': origin.base}
1821+
'base': origin.base, 'series': origin.series,
1822+
'revision': origin.revision,
1823+
}
18301824

18311825
resp = await charms_facade.ResolveCharms(resolve=[{
18321826
'reference': str(url),
@@ -1839,7 +1833,18 @@ async def _resolve_charm(self, url, origin):
18391833
if result.error:
18401834
raise JujuError(result.error.message)
18411835

1842-
return (result.url, result.charm_origin, result.supported_series)
1836+
supported_series = result.supported_series
1837+
charm_url = URL.parse(result.url)
1838+
if origin.series:
1839+
# Check whether the charm supports this series
1840+
# or we force it
1841+
if origin.series in supported_series or force:
1842+
result.charm_origin.series = origin.series
1843+
charm_url.series = origin.series
1844+
else:
1845+
raise JujuError("Series {} not supported for {}. Only {}".format(origin.series, result.url, supported_series))
1846+
1847+
return charm_url, result.charm_origin
18431848

18441849
async def _resolve_architecture(self, url):
18451850
if url.architecture:

0 commit comments

Comments
 (0)