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

nmcli: fix error when setting previously unset mac address (#5291)

* fix #5290

* add changelog fragment

* remove unnecessary braces

* Update changelogs/fragments/5291-fix-nmcli-error-when-setting-unset-mac-address.yaml

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

Co-authored-by: Felix Fontein <felix@fontein.de>
This commit is contained in:
Giorgio Gallo 2022-09-28 22:49:07 +02:00 committed by GitHub
parent 25e3031c2f
commit ec9e10d6d1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 3 deletions

View file

@ -0,0 +1,2 @@
bugfixes:
- "nmcli - fix error when setting previously unset MAC address, ``gsm.apn`` or ``vpn.data``: current values were being normalized without checking if they might be ``None`` (https://github.com/ansible-collections/community.general/pull/5291)."

View file

@ -2099,15 +2099,18 @@ class Nmcli(object):
# MAC addresses are case insensitive, nmcli always reports them in uppercase # MAC addresses are case insensitive, nmcli always reports them in uppercase
value = value.upper() value = value.upper()
# ensure current_value is also converted to uppercase in case nmcli changes behaviour # ensure current_value is also converted to uppercase in case nmcli changes behaviour
current_value = current_value.upper() if current_value:
current_value = current_value.upper()
if key == 'gsm.apn': if key == 'gsm.apn':
# Depending on version nmcli adds double-qoutes to gsm.apn # Depending on version nmcli adds double-qoutes to gsm.apn
# Need to strip them in order to compare both # Need to strip them in order to compare both
current_value = current_value.strip('"') if current_value:
current_value = current_value.strip('"')
if key == self.mtu_setting and self.mtu is None: if key == self.mtu_setting and self.mtu is None:
self.mtu = 0 self.mtu = 0
if key == 'vpn.data': if key == 'vpn.data':
current_value = sorted(re.sub(r'\s*=\s*', '=', part.strip(), count=1) for part in current_value.split(',')) if current_value:
current_value = sorted(re.sub(r'\s*=\s*', '=', part.strip(), count=1) for part in current_value.split(','))
value = sorted(part.strip() for part in value.split(',')) value = sorted(part.strip() for part in value.split(','))
else: else:
# parameter does not exist # parameter does not exist