Skip to content

Commit e2ee1b1

Browse files
committed
Provide Base to be filled in ResolveCharms, user series arg if provided
fixes #759
1 parent f2be28e commit e2ee1b1

2 files changed

Lines changed: 38 additions & 1 deletion

File tree

juju/model.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -548,10 +548,16 @@ async def resolve(self, url, architecture, app_name=None, channel=None, series=N
548548
if channel is not None:
549549
ch = Channel.parse(channel).normalize()
550550

551+
base = client.Base()
552+
if series:
553+
base.channel = ch.normalize().compute_base_channel(series=series)
554+
base.name = 'ubuntu'
551555
origin = client.CharmOrigin(source="charm-hub",
552556
architecture=architecture,
553557
risk=ch.risk,
554-
track=ch.track)
558+
track=ch.track,
559+
base=base,
560+
)
555561

556562
charm_url_str, origin, supported_series = await self.charm_resolver(url, origin)
557563
charm_url = URL.parse(charm_url_str)
@@ -1856,12 +1862,28 @@ async def _add_charm(self, charm_url, origin):
18561862
return await client_facade.AddCharm(channel=str(origin.risk), url=charm_url, force=False)
18571863

18581864
async def _resolve_charm(self, url, origin):
1865+
"""Calls Charms.ResolveCharms to resolve all the fields of the
1866+
charm_origin and also the url and the supported_series
1867+
1868+
:param str url: The url of the charm
1869+
:param client.CharmOrigin origin: The manually constructed origin
1870+
based on what we know about the charm and the deployment so far
1871+
1872+
Returns the confirmed origin returned by the Juju API to be used in
1873+
calls like ApplicationFacade.Deploy
1874+
1875+
:returns str, client.CharmOrigin, [str]
1876+
"""
18591877
charms_cls = client.CharmsFacade
18601878
if charms_cls.best_facade_version(self.connection()) < 3:
18611879
raise JujuError("resolve charm")
18621880

18631881
charms_facade = charms_cls.from_connection(self.connection())
18641882

1883+
# TODO (cderici): following part can be refactored out, since the
1884+
# origin should be set (including the base) before calling this,
1885+
# though all tests need to run (in earlier versions too) before
1886+
# committing to make sure there's no regression
18651887
if Schema.CHARM_STORE.matches(url.schema):
18661888
source = "charm-store"
18671889
else:

juju/origin.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
from enum import Enum
22
from .errors import JujuError
33

4+
from . import utils
5+
46

57
class Source(Enum):
68
"""Source defines a origin source. Providing a hint to the controller about
@@ -112,6 +114,19 @@ def __str__(self):
112114
path = "{}/{}".format(self.track, path)
113115
return path
114116

117+
def compute_base_channel(self, series=None):
118+
"""Determines the channel for a client.Base
119+
A base channel is a track/risk/branch
120+
121+
"""
122+
_ch = [self.risk]
123+
tr = self.track
124+
if series:
125+
tr = utils.get_series_version(series)
126+
if tr:
127+
_ch = [tr] + _ch
128+
return "/".join(_ch)
129+
115130

116131
class Platform:
117132
"""ParsePlatform parses a string representing a store platform.

0 commit comments

Comments
 (0)