Skip to content

Commit 786f238

Browse files
committed
Include check in charmcraft.yaml for base info for local charms
Fixes #765
1 parent c3eebd2 commit 786f238

2 files changed

Lines changed: 25 additions & 14 deletions

File tree

juju/model.py

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1797,27 +1797,26 @@ async def deploy(
17971797
# We have a local charm dir that needs to be uploaded
17981798
charm_dir = os.path.abspath(os.path.expanduser(identifier))
17991799
charm_origin = res.origin
1800+
base = None
18001801

18011802
metadata = utils.get_local_charm_metadata(charm_dir)
18021803
charm_series = charm_series or await get_charm_series(metadata,
18031804
self)
18041805

1805-
# If we're using a newer client, then the CharmOrigin needs a
1806-
# base
1807-
if not self.connection().is_using_old_client:
1808-
charm_origin.base = utils.get_local_charm_base(charm_series,
1809-
channel,
1810-
metadata,
1811-
charm_dir,
1812-
client.Base)
1813-
1806+
if not self.connection().is_using_old_client or \
1807+
not charm_series:
1808+
base = utils.get_local_charm_base(charm_series,
1809+
channel,
1810+
metadata,
1811+
charm_dir,
1812+
client.Base)
1813+
charm_origin.base = base
18141814
if not application_name:
18151815
application_name = metadata['name']
1816-
if self.connection().is_using_old_client and not charm_series:
1816+
if base is None and charm_series is None:
18171817
raise JujuError(
1818-
"Couldn't determine series for charm at {}. "
1819-
"Pass a 'series' kwarg to Model.deploy().".format(
1820-
charm_dir))
1818+
"Either series or base is needed to deploy the "
1819+
"charm at {}. ".format(charm_dir))
18211820
identifier = await self.add_local_charm_dir(charm_dir,
18221821
charm_series)
18231822
resources = await self.add_local_resources(application_name,

juju/utils.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ def get_local_charm_data(path, yaml_file):
239239
240240
:patam str path: Path of charm directory or .charm file
241241
:patam str yaml_file: name of the yaml file, can be either
242-
"metadata.yaml", or "manifest.yaml"
242+
"metadata.yaml", or "manifest.yaml", or "charmcraft.yaml"
243243
244244
:return: Object of charm metadata
245245
"""
@@ -249,6 +249,8 @@ def get_local_charm_data(path, yaml_file):
249249
else:
250250
entity_path = Path(path)
251251
metadata_path = entity_path / yaml_file
252+
if not metadata_path.exists():
253+
return {}
252254
metadata = yaml.load(metadata_path.read_text(), Loader=yaml.FullLoader)
253255

254256
return metadata
@@ -262,6 +264,10 @@ def get_local_charm_manifest(path):
262264
return get_local_charm_data(path, 'manifest.yaml')
263265

264266

267+
def get_local_charm_charmcraft_yaml(path):
268+
return get_local_charm_data(path, 'charmcraft.yaml')
269+
270+
265271
PRECISE = "precise"
266272
QUANTAL = "quantal"
267273
RARING = "raring"
@@ -376,6 +382,12 @@ def get_local_charm_base(series, channel_from_arg, charm_metadata,
376382
if 'bases' in charm_manifest:
377383
channel_for_base = charm_manifest['bases'][0]['channel']
378384
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']
379391

380392
if channel_for_base == '':
381393
raise errors.JujuError("Unable to determine base for charm : %s" %

0 commit comments

Comments
 (0)