diff options
| author | Mark Goddard <mark@stackhpc.com> | 2020-02-26 12:52:44 +0000 |
|---|---|---|
| committer | Mark Goddard <mark@stackhpc.com> | 2020-02-26 13:46:45 +0000 |
| commit | 5e7979f31d8e30980a6e31490d00345e51a14006 (patch) | |
| tree | ad714285e7923aee5ecca97d9676d4e21f0e7e9a /kolla | |
| parent | 1fe8012ce2aec549430212d90ffd728889d6e4aa (diff) | |
| download | kolla-5e7979f31d8e30980a6e31490d00345e51a14006.tar.gz kolla-5e7979f31d8e30980a6e31490d00345e51a14006.zip | |
Throw TypeError in repository enable/disable macros
Currently we do not validate the type of the reponames argument to the
enable_extra_repos and disable_extra_repos macros. It should be a list,
but we merged a call where the argument was a string, which interpreted
as a list of single characters ('e', 'p', 'e', 'l'), and silently
ignored.
This change validates that the reponames argument is a list to avoid
this issue.
Change-Id: I497c8b2c1dc548e678698474d3604664cf8eeb07
Diffstat (limited to 'kolla')
| -rw-r--r-- | kolla/template/methods.py | 3 | ||||
| -rw-r--r-- | kolla/tests/test_methods.py | 13 |
2 files changed, 16 insertions, 0 deletions
diff --git a/kolla/template/methods.py b/kolla/template/methods.py index 66c5dcfa9..fb470a65f 100644 --- a/kolla/template/methods.py +++ b/kolla/template/methods.py @@ -88,6 +88,9 @@ def handle_repos(context, reponames, mode): else: raise KeyError + if not isinstance(reponames, list): + raise TypeError("First argument should be a list of repositories") + repofile = os.path.dirname(os.path.realpath(__file__)) + '/repos.yaml' with open(repofile, 'r') as repos_file: repo_data = {} diff --git a/kolla/tests/test_methods.py b/kolla/tests/test_methods.py index d2f6eff9d..c33aba7f9 100644 --- a/kolla/tests/test_methods.py +++ b/kolla/tests/test_methods.py @@ -150,3 +150,16 @@ class MethodsTest(base.TestCase): result = methods.handle_repos(template_vars, ['grafana'], 'disable') expectCmd = '' self.assertEqual(expectCmd, result) + + def test_handle_repos_string(self): + template_vars = { + 'base_arch': 'x86_64', + 'base_distro': 'debian', + 'base_package_type': 'deb' + } + + self.assertRaisesRegex(TypeError, + r'First argument should be a list of ' + r'repositories', + methods.handle_repos, template_vars, 'grafana', + 'disable') |
