Skip to content

Commit

Permalink
nmcli: two fixes needed to make wifi.wake-on-wlan settings work prope…
Browse files Browse the repository at this point in the history
…rly (#5431)

* nmcli: Convert current value of wifi.wake-on-wlan before comparing

The new value of wifi.wake-on-wlan is specified as an integer, but in
the nmcli output it's specified as a hex string followed by a textual
description of it. Therefore, to determine properly whether it's being
changed we need to pull the hex string out of the current value,
convert it into an integer, and finally convert the integer back to a
string so that we can compare it to the new specified value. Without
this change, whenever wifi.wake-on-wlan is specified in the module
arguments the module will think the value is being changed even when
it isn't.

* nmcli: Handle wifi options correctly when connection type not specified

When an nmcli task does not specify the connection type and the module
ask nmcli for it, the module needs to convert nmcli's
`802-11-wireless` to `wifi`, the term for this connection type used by
the module.

* nmcli: Correctly detect values changed to the integer 0

If the user specifies a value of 0 (without quotes) in a task, we
should interpret that as an actual value, not empty, when comparing
the new value to the old one. Otherwise we incorrectly conclude that
there was no change.

* Changelog fragment for #5431
  • Loading branch information
jikamens authored Feb 24, 2023
1 parent c168f9c commit 490899f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
4 changes: 4 additions & 0 deletions changelogs/fragments/5431-nmcli-wifi.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
bugfixes:
- nmcli - fix failure to handle WIFI settings when connection type not specified (https://github.com/ansible-collections/community.general/pull/5431).
- nmcli - fix improper detection of changes to ``wifi.wake-on-wlan`` (https://github.com/ansible-collections/community.general/pull/5431).
- nmcli - fix change handling of values specified as an integer 0 (https://github.com/ansible-collections/community.general/pull/5431).
11 changes: 10 additions & 1 deletion plugins/modules/nmcli.py
Original file line number Diff line number Diff line change
Expand Up @@ -2107,11 +2107,18 @@ def _compare_conn_params(self, conn_info, options):
diff_after = dict()

for key, value in options.items():
if not value:
# We can't just do `if not value` because then if there's a value
# of 0 specified as an integer it'll be interpreted as empty when
# it actually isn't.
if value != 0 and not value:
continue

if key in conn_info:
current_value = conn_info[key]
if key == '802-11-wireless.wake-on-wlan' and current_value is not None:
match = re.match('0x([0-9A-Fa-f]+)', current_value)
if match:
current_value = str(int(match.group(1), 16))
if key in ('ipv4.routes', 'ipv6.routes') and current_value is not None:
current_value = self.get_route_params(current_value)
if key == self.mac_setting:
Expand Down Expand Up @@ -2167,6 +2174,8 @@ def is_connection_changed(self):
if not self.type:
current_con_type = self.show_connection().get('connection.type')
if current_con_type:
if current_con_type == '802-11-wireless':
current_con_type = 'wifi'
self.type = current_con_type

options.update(self.connection_options(detect_change=True))
Expand Down

0 comments on commit 490899f

Please sign in to comment.