Skip to content

Commit 6642cfe

Browse files
committed
Fix base channel discovery for local charms
`utils.get_local_charm_base()` was incorrectly using the `--channel` argument (the charm's channel) for discovering the channel part of the base. (we should stop using the word 'channel' for two different things). This fixes that by taking out the incorrect part of the code. Should fix #839
1 parent d91ccb0 commit 6642cfe

2 files changed

Lines changed: 13 additions & 39 deletions

File tree

juju/model.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1682,13 +1682,11 @@ async def deploy(
16821682
# We have a local charm dir that needs to be uploaded
16831683
charm_dir = os.path.abspath(os.path.expanduser(identifier))
16841684
charm_origin = res.origin
1685-
base = None
16861685

16871686
metadata = utils.get_local_charm_metadata(charm_dir)
16881687
charm_series = charm_series or await get_charm_series(metadata,
16891688
self)
1690-
base = utils.get_local_charm_base(
1691-
charm_series, channel, metadata, charm_dir, client.Base)
1689+
base = utils.get_local_charm_base(charm_series, charm_dir, client.Base)
16921690
charm_origin.base = base
16931691
if not application_name:
16941692
application_name = metadata['name']

juju/utils.py

Lines changed: 12 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -329,46 +329,21 @@ def get_version_series(version):
329329
return list(UBUNTU_SERIES.keys())[list(UBUNTU_SERIES.values()).index(version)]
330330

331331

332-
def get_local_charm_base(series, channel_from_arg, charm_metadata,
333-
charm_path, baseCls):
332+
def get_local_charm_base(series, charm_path, base_class):
334333
"""Deduce the base [channel/osname] of a local charm based on what we
335334
know already
336335
337336
:param str series: This may come from the argument or the metadata.yaml
338-
:param str channel_from_arg: This is channel passed as argument, if any.
339-
:param dict charm_metadata: metadata.yaml
340337
:param str charm_path: Path of charm directory/.charm file
341-
:param class baseCls:
338+
:param class base_class:
342339
:return: Instance of the baseCls with channel/osname informaiton
343340
"""
344341

345342
channel_for_base = ''
346343
os_name_for_base = ''
347-
# If user passed a channel_arg, then check the supported series against
348-
# the channel's track
349-
chnl_check = origin.Channel.parse(channel_from_arg) if channel_from_arg \
350-
else None
351-
if chnl_check:
352-
not_supported_error = errors.JujuError(
353-
"Given channel [track/risk] is not supported --"
354-
"\n - Given channel : %s"
355-
"\n - Series in Charm Metadata : %s" %
356-
(channel_from_arg, charm_metadata['series']))
357-
channel_for_base = chnl_check.track
358-
intented_series = get_version_series(channel_for_base)
359-
if intented_series not in charm_metadata['series']:
360-
raise not_supported_error
361-
# Also check the manifest if there's one
362-
charm_manifest = get_local_charm_manifest(charm_path)
363-
if 'bases' in charm_manifest:
364-
for base in charm_manifest['bases']:
365-
if channel_for_base == base['channel']:
366-
break
367-
else:
368-
raise not_supported_error
369344

370-
# If we know the series, use it to get a channel
371-
if channel_for_base == '':
345+
# We should know the series, so use it to get a channel
346+
if series:
372347
channel_for_base = get_series_version(series) if series else ''
373348
if channel_for_base:
374349
# we currently only support ubuntu series (statically)
@@ -382,18 +357,19 @@ def get_local_charm_base(series, channel_from_arg, charm_metadata,
382357
if 'bases' in charm_manifest:
383358
channel_for_base = charm_manifest['bases'][0]['channel']
384359
os_name_for_base = charm_manifest['bases'][0]['name']
385-
else:
386-
# Also check the charmcraft.yaml
387-
charmcraft_yaml = get_local_charm_charmcraft_yaml(charm_path)
388-
if 'bases' in charmcraft_yaml:
389-
channel_for_base = charmcraft_yaml['bases'][0]['run-on'][0]['channel']
390-
os_name_for_base = charmcraft_yaml['bases'][0]['run-on'][0]['name']
360+
361+
# Also check the charmcraft.yaml
362+
if channel_for_base == '':
363+
charmcraft_yaml = get_local_charm_charmcraft_yaml(charm_path)
364+
if 'bases' in charmcraft_yaml:
365+
channel_for_base = charmcraft_yaml['bases'][0]['run-on'][0]['channel']
366+
os_name_for_base = charmcraft_yaml['bases'][0]['run-on'][0]['name']
391367

392368
if channel_for_base == '':
393369
raise errors.JujuError("Unable to determine base for charm : %s" %
394370
charm_path)
395371

396-
return baseCls(channel_for_base, os_name_for_base)
372+
return base_class(channel_for_base, os_name_for_base)
397373

398374

399375
def base_channel_to_series(channel):

0 commit comments

Comments
 (0)