From cfc4c93253d57de953c4cae7acc5f2b2890614ac Mon Sep 17 00:00:00 2001 From: omnom62 <75066712+omnom62@users.noreply.github.com> Date: Thu, 13 Feb 2025 09:01:45 +1000 Subject: T7002 fw global integration fix (#379) * T7002 fw_global integration tests fix init * adding 1.3 structure * v1.3- integration tests for fw_global * fixed integration tests for 1.3 and fw_global * D.R.Y. for firewall_global integration tests * changelog * config-trap is fixed for 1.4 * fw_global log mod fixed * firewall_gobal 1.4 integration and unit tests fixes * firewall_gobal unit tests fix * T7002 firewall_global integration tests fixed * clean-up work things * some updates from PR review * populate_commands for fw_global * D.R.Y fw_global integration tests * linter fw_global * linter * fragments for T7002 updated * linter --- .../vyos/config/firewall_global/firewall_global.py | 32 +++++++++++++++------- .../vyos/facts/firewall_global/firewall_global.py | 6 ++-- 2 files changed, 25 insertions(+), 13 deletions(-) (limited to 'plugins/module_utils') diff --git a/plugins/module_utils/network/vyos/config/firewall_global/firewall_global.py b/plugins/module_utils/network/vyos/config/firewall_global/firewall_global.py index 7e978ff9..34dc0ed6 100644 --- a/plugins/module_utils/network/vyos/config/firewall_global/firewall_global.py +++ b/plugins/module_utils/network/vyos/config/firewall_global/firewall_global.py @@ -476,14 +476,23 @@ class Firewall_global(ConfigBase): for key, val in iteritems(w): if val and key != "connection_type": if opr and key in l_set and not (h and self._is_w_same(w, h, key)): - commands.append( - self._form_attr_cmd( - key=attr + " " + w["connection_type"], - attr=key, - val=self._bool_to_str(val), - opr=opr, - ), - ) + if key == "log" and LooseVersion(get_os_version(self._module)) >= LooseVersion("1.4"): + commands.append( + self._form_attr_cmd( + key=attr + " " + w["connection_type"], + attr=key, + opr=opr, + ), + ) + else: + commands.append( + self._form_attr_cmd( + key=attr + " " + w["connection_type"], + attr=key, + val=self._bool_to_str(val), + opr=opr, + ), + ) elif not opr and key in l_set: if not h: commands.append( @@ -645,14 +654,17 @@ class Firewall_global(ConfigBase): cmd = "delete firewall " else: cmd = "set firewall " - if key != "group" and LooseVersion(get_os_version(self._module)) >= LooseVersion("1.4"): + if attr and key != "group" and LooseVersion(get_os_version(self._module)) >= LooseVersion("1.4"): cmd += "global-options " if key: cmd += key.replace("_", "-") + " " if attr: cmd += attr.replace("_", "-") if val and opr: - cmd += " '" + str(val) + "'" + if key == "state_policy" and LooseVersion(get_os_version(self._module)) >= LooseVersion("1.4"): + cmd += "" + else: + cmd += " '" + str(val) + "'" return cmd.strip() def _bool_to_str(self, val): diff --git a/plugins/module_utils/network/vyos/facts/firewall_global/firewall_global.py b/plugins/module_utils/network/vyos/facts/firewall_global/firewall_global.py index 97386e99..a46f8563 100644 --- a/plugins/module_utils/network/vyos/facts/firewall_global/firewall_global.py +++ b/plugins/module_utils/network/vyos/facts/firewall_global/firewall_global.py @@ -111,7 +111,7 @@ class Firewall_globalFacts(object): rr_lst = [] v6_attr = findall( - r"^set firewall (?:global-options )(?:ipv6-src-route|ipv6-receive-redirects) (\S+)", + r"^set firewall (?:global-options )?(?:ipv6-src-route|ipv6-receive-redirects) (\S+)", conf, M, ) @@ -121,7 +121,7 @@ class Firewall_globalFacts(object): rr_lst.append(obj) v4_attr = findall( - r"^set firewall (?:global-options )(?:ip-src-route|receive-redirects|send-redirects) (\S+)", + r"^set firewall (?:global-options )?(?:ip-src-route|receive-redirects|send-redirects) (\S+)", conf, M, ) @@ -174,7 +174,7 @@ class Firewall_globalFacts(object): :return: generated rule list configuration. """ sp_lst = [] - policies = findall(r"^set firewall (?:global-options )state-policy (\S+)", conf, M) + policies = findall(r"^set firewall (?:global-options )?state-policy (\S+)", conf, M) policies = list(set(policies)) # remove redundancies if policies: rules_lst = [] -- cgit v1.2.3