From 5b640551fdff979275b49965801ad438938fb067 Mon Sep 17 00:00:00 2001 From: Christian Poessinger Date: Wed, 30 Sep 2020 20:45:10 +0200 Subject: wireguard: T2939: bugfix when removing individual peers When individual peers that have been removed got determined they have been added to the config dict as list instead of string - which broke the system plumbing commands as they can not handle a Python list. --- src/conf_mode/interfaces-wireguard.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'src/conf_mode/interfaces-wireguard.py') diff --git a/src/conf_mode/interfaces-wireguard.py b/src/conf_mode/interfaces-wireguard.py index d5800264f..9bda35d0a 100755 --- a/src/conf_mode/interfaces-wireguard.py +++ b/src/conf_mode/interfaces-wireguard.py @@ -57,13 +57,13 @@ def get_config(config=None): # Determine which Wireguard peer has been removed. # Peers can only be removed with their public key! + dict = {} tmp = node_changed(conf, ['peer']) - if tmp: - dict = {} - for peer in tmp: - peer_config = leaf_node_changed(conf, ['peer', peer, 'pubkey']) - dict = dict_merge({'peer_remove' : {peer : {'pubkey' : peer_config}}}, dict) - wireguard.update(dict) + for peer in (tmp or []): + pubkey = leaf_node_changed(conf, ['peer', peer, 'pubkey']) + if pubkey: + dict = dict_merge({'peer_remove' : {peer : {'pubkey' : pubkey[0]}}}, dict) + wireguard.update(dict) return wireguard @@ -101,12 +101,12 @@ def verify(wireguard): f'for peer "{tmp}" if either one of them is set!') def apply(wireguard): + tmp = WireGuardIf(wireguard['ifname']) if 'deleted' in wireguard: - WireGuardIf(wireguard['ifname']).remove() + tmp.remove() return None - w = WireGuardIf(wireguard['ifname']) - w.update(wireguard) + tmp.update(wireguard) return None if __name__ == '__main__': -- cgit v1.2.3