Merge ~mthaddon/charm-k8s-unifi-poller/+git/charm-k8s-unifi-poller:master into charm-k8s-unifi-poller:master

Proposed by Tom Haddon
Status: Merged
Approved by: Tom Haddon
Approved revision: 0f9d4bf0f9f6b50fab5b5771a4df675c70b8bb14
Merged at revision: c40952d1bfcdfa00e71f5f5c3d928911e4945f00
Proposed branch: ~mthaddon/charm-k8s-unifi-poller/+git/charm-k8s-unifi-poller:master
Merge into: charm-k8s-unifi-poller:master
Diff against target: 48 lines (+15/-1)
2 files modified
src/charm.py (+5/-1)
tests/unit/test_charm.py (+10/-0)
Reviewer Review Type Date Requested Status
Gareth Woolridge Approve
Canonical IS Reviewers Pending
Review via email: mp+390545@code.launchpad.net

Commit message

Prevent duplicate entries in extra_configs

Description of the change

Prevent duplicate entries in extra_configs

To post a comment you must log in.
Revision history for this message
🤖 Canonical IS Merge Bot (canonical-is-mergebot) wrote :

This merge proposal is being monitored by mergebot. Change the status to Approved to merge.

Revision history for this message
Gareth Woolridge (moon127) wrote :

Agreed we should be checking for duplicate config options in the extra_config data.

review: Approve
Revision history for this message
🤖 Canonical IS Merge Bot (canonical-is-mergebot) wrote :

Change successfully merged at revision c40952d1bfcdfa00e71f5f5c3d928911e4945f00

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/src/charm.py b/src/charm.py
2index 20a530a..96b72c2 100755
3--- a/src/charm.py
4+++ b/src/charm.py
5@@ -71,10 +71,14 @@ class UnifiPollerCharm(CharmBase):
6 """Check extra_config configuration_settings."""
7 config = self.model.config
8
9- errors = []
10+ errors, config_keys = [], []
11 if config['extra_configs']:
12 for c in yaml.safe_load(config['extra_configs']):
13 k, value = c.split('=', 1)
14+ if k in config_keys:
15+ errors.append('{} is duplicated'.format(k))
16+ else:
17+ config_keys.append(k)
18 if not re.match(r'^UP_', k.upper()):
19 errors.append(k)
20 if re.match(r'.*_URL', k.upper()):
21diff --git a/tests/unit/test_charm.py b/tests/unit/test_charm.py
22index 42b6066..50cfd9e 100644
23--- a/tests/unit/test_charm.py
24+++ b/tests/unit/test_charm.py
25@@ -92,6 +92,10 @@ CONFIG_INVALID_EXTRA_CONFIG_NO_NETLOC = {
26 'extra_configs': "[up_unifi_controller_1_url=http://valid-url, up_unifi_controller_2_url=https:no-netloc]",
27 }
28
29+CONFIG_INVALID_EXTRA_CONFIG_DUPLICATES = {
30+ 'extra_configs': "[up_dup=1, up_dup=2]",
31+}
32+
33
34 class TestCharm(unittest.TestCase):
35 def setUp(self):
36@@ -122,6 +126,12 @@ class TestCharm(unittest.TestCase):
37 expected = 'invalid extra_config setting(s): up_unifi_controller_2_url'
38 self.assertEqual(self.harness.charm._check_for_config_problems(), expected)
39
40+ def test_check_for_invalid_extra_configs_duplicates(self):
41+ """Check for correctly reports duplicate entries in extra_configs options."""
42+ self.harness.update_config(CONFIG_INVALID_EXTRA_CONFIG_DUPLICATES)
43+ expected = ['up_dup is duplicated']
44+ self.assertEqual(self.harness.charm._bad_extra_config_charm_settings(), expected)
45+
46 def test_check_for_missing_image_invalid_extra_config(self):
47 """Check for correctly reports invalid extra_configs options."""
48 self.harness.update_config(CONFIG_INVALID_EXTRA_CONFIG_NO_IMAGE)

Subscribers

People subscribed via source and target branches