From 58b55b6ef6643608703334fd840e93cdb2369736 Mon Sep 17 00:00:00 2001 From: Jarrod Johnson Date: Wed, 16 Feb 2022 11:58:22 -0500 Subject: [PATCH] Error on trying to double-add nodes or groups Prevent user from repeatedly adding the same group to a node or same node to a group. --- confluent_server/confluent/config/configmanager.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/confluent_server/confluent/config/configmanager.py b/confluent_server/confluent/config/configmanager.py index 8ee3b216..0ec7f615 100644 --- a/confluent_server/confluent/config/configmanager.py +++ b/confluent_server/confluent/config/configmanager.py @@ -1824,6 +1824,9 @@ class ConfigManager(object): if attribmap[group][attr].get('prepend', False): newnodes = noderange.NodeRange(attribmap[group][attr][ 'prepend'], config=self).nodes + for newnode in newnodes: + if newnode in currnodes: + raise ValueError('{0} is already in group {1}'.format(newnode, group)) attribmap[group][attr] = list( newnodes) + currnodes elif attribmap[group][attr].get('remove', False): @@ -2245,6 +2248,9 @@ class ConfigManager(object): if attribmap[node]['groups'].get('prepend', False): newgroups = attribmap[node]['groups'][ 'prepend'].split(',') + for newgroup in newgroups: + if newgroup in currgroups: + raise ValueError('Node {0} is already in group {1}'.format(node, newgroup)) attribmap[node]['groups'] = newgroups + currgroups elif attribmap[node]['groups'].get('remove', False): delgroups = attribmap[node]['groups'][