Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add warning message if series is in metadata.yaml #616

Merged
merged 1 commit into from
Jul 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 7 additions & 9 deletions charmtools/charms.py
Original file line number Diff line number Diff line change
Expand Up @@ -807,22 +807,20 @@ def validate_min_juju_version(charm, linter):


def validate_series(charm, linter):
"""Validate supported series list in charm metadata.
"""Validate series list in charm metadata.

We don't validate the actual series names because:

1. `charm push` does that anyway
2. our list of valid series would be constantly falling out-of-date
The `series` parameter is deprecated because charmcraft ignores it and
uses `bases` from `charmcraft.yaml`. This function checks if the series
is in metadata.yaml and displays a warning message if so.

:param charm: dict of charm metadata parsed from metadata.yaml
:param linter: :class:`CharmLinter` object to which info/warning/error
messages will be written

"""
if 'series' not in charm:
linter.err('missing series: must be a list of series names')
elif not isinstance(charm['series'], list):
linter.err('series: must be a list of series names')
if 'series' in charm:
linter.warn('DEPRECATED: series parameter is ignored by charmcraft,'
'use bases in charmcraft.yaml')


def validate_storage(charm, linter, proof_extensions=None):
Expand Down
27 changes: 4 additions & 23 deletions tests/test_charm_proof.py
Original file line number Diff line number Diff line change
Expand Up @@ -1256,31 +1256,12 @@ def test_juju_functions_fail(self):


class SeriesValidationTest(TestCase):
def test_series_not_list(self):
"""Charm has a series key, but the value is not a list."""
def test_series(self):
"""Charm does have a series key."""
linter = Mock()
charm = {
'series': 'trusty',
}
validate_series(charm, linter)
linter.err.assert_called_once_with(
'series: must be a list of series names')

def test_series_list(self):
"""Charm has a series key that is a list."""
linter = Mock()
charm = {
'series': ['trusty'],
}
validate_series(charm, linter)
self.assertFalse(linter.err.called)

def test_no_series(self):
"""Charm does not have a series key."""
linter = Mock()
charm = {}
charm = {"series": []}
validate_series(charm, linter)
self.assertTrue(linter.err.called)
self.assertTrue(linter.warn.called)


class TermsValidationTest(TestCase):
Expand Down