From 3a591aa3d71dea26c354ab9834b1bf8d3ec59936 Mon Sep 17 00:00:00 2001 From: Wen Liang Date: Mon, 25 Jul 2022 10:30:04 -0400 Subject: [PATCH] network_state: improve state comparison for achieving idempotency `libnmstate.show()` would include the info like bridge timer etc which should not be considered when comparing between the previous state and current state. Instead, using the the `libnmstate.show_running_config()` which would filter out these kind of data. Signed-off-by: Wen Liang --- library/network_state.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/library/network_state.py b/library/network_state.py index aac8289..3f88f79 100644 --- a/library/network_state.py +++ b/library/network_state.py @@ -39,12 +39,12 @@ class NetworkState: self.params = module.params self.result = dict(changed=False) self.module_name = module_name - self.previous_state = libnmstate.show() + self.previous_state = self.get_state_config() def run(self): desired_state = self.params["desired_state"] libnmstate.apply(desired_state) - current_state = libnmstate.show() + current_state = self.get_state_config() if current_state != self.previous_state: self.result["changed"] = True @@ -52,6 +52,15 @@ class NetworkState: self.module.exit_json(**self.result) + def get_state_config(self): + if hasattr(libnmstate, "show_running_config") and callable( + getattr(libnmstate, "show_running_config") + ): + state_config = libnmstate.show_running_config() + else: + state_config = libnmstate.show() + return state_config + def run_module(): module_args = dict(