1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

nmcli: Compare MAC addresses case insensitively (#2416) (#2425)

* nmcli: Compare MAC addresses case insensitively

* Update changelogs/fragments/2416-nmcli_compare_mac_addresses_case_insensitively.yml

Co-authored-by: Felix Fontein <felix@fontein.de>

* Update plugins/modules/net_tools/nmcli.py

Co-authored-by: Felix Fontein <felix@fontein.de>

* Add mac to TESTCASE_BRIDGE so test_bridge_connection_unchanged covers case sensitive mac address comparison

* Update plugins/modules/net_tools/nmcli.py

Co-authored-by: Felix Fontein <felix@fontein.de>

* Convert current_value to uppercase as well in case nmcli changes behaviour

Co-authored-by: Felix Fontein <felix@fontein.de>
(cherry picked from commit 7359b1fbe5)

Co-authored-by: spike77453 <spike77453@users.noreply.github.com>
This commit is contained in:
patchback[bot] 2021-05-03 08:17:32 +02:00 committed by GitHub
parent 5691e3aff3
commit 0da9d956a0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 1 deletions

View file

@ -0,0 +1,2 @@
bugfixes:
- nmcli - compare MAC addresses case insensitively to fix idempotency issue (https://github.com/ansible-collections/community.general/issues/2409).

View file

@ -1042,7 +1042,6 @@ class Nmcli(object):
'con-name': 'connection.id', 'con-name': 'connection.id',
'autoconnect': 'connection.autoconnect', 'autoconnect': 'connection.autoconnect',
'ifname': 'connection.interface-name', 'ifname': 'connection.interface-name',
'mac': self.mac_setting,
'master': 'connection.master', 'master': 'connection.master',
'slave-type': 'connection.slave-type', 'slave-type': 'connection.slave-type',
'zone': 'connection.zone', 'zone': 'connection.zone',
@ -1066,6 +1065,11 @@ class Nmcli(object):
current_value = [re.sub(r'^{\s*ip\s*=\s*([^, ]+),\s*nh\s*=\s*([^} ]+),\s*mt\s*=\s*([^} ]+)\s*}', r'\1 \2 \3', current_value = [re.sub(r'^{\s*ip\s*=\s*([^, ]+),\s*nh\s*=\s*([^} ]+),\s*mt\s*=\s*([^} ]+)\s*}', r'\1 \2 \3',
route) for route in current_value] route) for route in current_value]
current_value = [re.sub(r'^{\s*ip\s*=\s*([^, ]+),\s*nh\s*=\s*([^} ]+)\s*}', r'\1 \2', route) for route in current_value] current_value = [re.sub(r'^{\s*ip\s*=\s*([^, ]+),\s*nh\s*=\s*([^} ]+)\s*}', r'\1 \2', route) for route in current_value]
if key == self.mac_setting:
# MAC addresses are case insensitive, nmcli always reports them in uppercase
value = value.upper()
# ensure current_value is also converted to uppercase in case nmcli changes behaviour
current_value = current_value.upper()
elif key in param_alias: elif key in param_alias:
real_key = param_alias[key] real_key = param_alias[key]
if real_key in conn_info: if real_key in conn_info:

View file

@ -184,6 +184,7 @@ TESTCASE_BRIDGE = [
'ifname': 'br0_non_existant', 'ifname': 'br0_non_existant',
'ip4': '10.10.10.10/24', 'ip4': '10.10.10.10/24',
'gw4': '10.10.10.1', 'gw4': '10.10.10.1',
'mac': '52:54:00:ab:cd:ef',
'maxage': 100, 'maxage': 100,
'stp': True, 'stp': True,
'state': 'present', 'state': 'present',
@ -200,6 +201,7 @@ ipv4.addresses: 10.10.10.10/24
ipv4.gateway: 10.10.10.1 ipv4.gateway: 10.10.10.1
ipv4.never-default: no ipv4.never-default: no
ipv6.method: auto ipv6.method: auto
bridge.mac-address: 52:54:00:AB:CD:EF
bridge.stp: yes bridge.stp: yes
bridge.max-age: 100 bridge.max-age: 100
bridge.ageing-time: 300 bridge.ageing-time: 300