Skip to content

Commit 92bc56a

Browse files
authored
Merge pull request #846 from juju/fix-local-charm-base-channel-discovery
#846 #### Description `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 #### QA Steps So a trivial way to reproduce the #839 is to deploy a local charm with a `--channel='stable'` argument. You may try to use one of the examples to validate this. Additionally an integration test is added (see below), so passing that should be enough. I also suggest getting a confirmation from [@gcalvinos](https://github.com/gcalvinos), just in case. ``` tox -e integration -- tests/integration/test_model.py::test_deploy_local_charm_channel ``` All CI tests need to pass. We might have a couple of time-outs from previously known CI test failures.
2 parents d91ccb0 + a74208b commit 92bc56a

4 files changed

Lines changed: 32 additions & 44 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):

tests/integration/test_charmhub.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,5 +103,5 @@ async def test_subordinate_charm_zero_units(event_loop):
103103
@pytest.mark.asyncio
104104
async def test_list_resources(event_loop):
105105
async with base.CleanModel() as model:
106-
resources = await model.charmhub.list_resources('postgresql')
106+
resources = await model.charmhub.list_resources('hello-kubecon')
107107
assert type(resources) == list and len(resources) > 0

tests/integration/test_model.py

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,18 @@ async def test_deploy_local_charm(event_loop):
149149
assert model.units['charm/0'].workload_status == 'active'
150150

151151

152+
@base.bootstrapped
153+
@pytest.mark.asyncio
154+
async def test_deploy_local_charm_channel(event_loop):
155+
charm_path = TESTS_DIR / 'charm'
156+
157+
async with base.CleanModel() as model:
158+
await model.deploy(str(charm_path), channel='stable')
159+
assert 'charm' in model.applications
160+
await model.wait_for_idle(status="active")
161+
assert model.units['charm/0'].workload_status == 'active'
162+
163+
152164
@base.bootstrapped
153165
@pytest.mark.asyncio
154166
async def test_wait_local_charm_blocked(event_loop):
@@ -181,9 +193,10 @@ async def test_wait_local_charm_waiting_timeout(event_loop):
181193
@pytest.mark.asyncio
182194
async def test_deploy_bundle(event_loop):
183195
async with base.CleanModel() as model:
184-
await model.deploy('canonical-livepatch-onprem', channel='edge', trust=True)
196+
await model.deploy('anbox-cloud-core', channel='stable',
197+
trust=True)
185198

186-
for app in ('haproxy', 'livepatch', 'postgresql', 'ubuntu-advantage'):
199+
for app in ('ams', 'etcd', 'ams-node-controller', 'etcd-ca', 'lxd'):
187200
assert app in model.applications
188201

189202

@@ -269,10 +282,11 @@ async def test_deploy_local_charm_folder_symlink(event_loop):
269282
@base.bootstrapped
270283
@pytest.mark.asyncio
271284
async def test_deploy_trusted_bundle(event_loop):
285+
pytest.skip("skip until we have a deployable bundle available. Right now the landscape-dense fails because postgresql is broken")
272286
async with base.CleanModel() as model:
273-
await model.deploy('canonical-livepatch-onprem', channel='stable', trust=True)
287+
await model.deploy('landscape-dense', channel='stable', trust=True)
274288

275-
for app in ('haproxy', 'livepatch', 'postgresql', 'ubuntu-advantage'):
289+
for app in ('haproxy', 'landscape-server', 'postgresql', 'rabbit-mq-server'):
276290
assert app in model.applications
277291

278292
haproxy_app = model.applications['haproxy']

0 commit comments

Comments
 (0)