Skip to content

Commit cfc12d9

Browse files
authored
Merge pull request #825 from cderici/communicate-series-to-resolve-charm-for-29
#825 #### Description Without the series the ResolveCharm will select the latest base for the charm. E.g. even if we want `focal`, the `ResolveCharms` 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 `ResolveCharms` via the inputted origin so the resulting origin will have the correct base channel. Fixes #822 #### QA Steps This is against 2.9, so get a juju 2.9 and bootstrap a `2.9` controller. ```sh $ sudo snap install juju --channel=2.9/stable --classic $ juju bootstrap localhost test ``` Then copy paste the following code from #822 deploy command into the `examples/deploy.py` ```python LCM_CHARM = "osm-lcm" LCM_APP = "lcm" LCM_CHANNEL = "latest/beta" LCM_SERIES = "focal" LCM_RESOURCES = {"lcm-image": "opensourcemano/lcm:testing-daily"} async def deploy(): model = Model() await model.connect_current() try: await model.deploy( LCM_CHARM, application_name=LCM_APP, resources=LCM_RESOURCES, channel=LCM_CHANNEL, series=LCM_SERIES, ) finally: await model.disconnect() ``` Then just run it from the top: ```sh $ python examples/deploy.py ``` After starting this (doesn't need to return), just check the `juju status` and you should see the revision 174 according to the `juju info osm-lcm`. I suggest trying it with different channels and revisions, as well as different charms too. I did try with different channels and it seems to be working well. I haven't tried it with different charms. Also we need to be careful about the CI tests, as this might change things, so we need to make sure all the charm related teests are passing. #### Notes & Discussion I haven't tried this in > 3.0, we might need to cherry pick this into the master as well.
2 parents 302021e + 75336d2 commit cfc12d9

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)