summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYuriy Andamasov <yuriy@vyos.io>2026-06-30 14:18:50 +0300
committerGitHub <noreply@github.com>2026-06-30 21:18:50 +1000
commit0e10d136ef280ca147b6f1e332072f6ba14c8844 (patch)
treec1f99833376e15b4b47e01d28d20f12ba4a4c123
parent6d7a2184e970624f74f333931f7f70a1f900f7b5 (diff)
downloadvyos.vyos-0e10d136ef280ca147b6f1e332072f6ba14c8844.tar.gz
vyos.vyos-0e10d136ef280ca147b6f1e332072f6ba14c8844.zip
T8522: fix parse_icmp_attr() split delimiter and UnboundLocalError (#464)
* Add easy-wins improvement spec for vyos.vyos collection Covers five phases: formatting compliance, runtime.yml redirect fix, deprecated feature cleanup, missing unit tests, and template deduplication. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * Add implementation plan for easy-wins improvements 15 tasks across 5 phases: formatting compliance, runtime.yml bugfix, deprecated code cleanup, missing unit tests, template deduplication. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * Update spec and plan with architect review corrections Key changes: - Defer Phase 5 (template deduplication) to v7.0.0: route_maps are not identical, BGP dedup blocked by Python module-level scoping, OSPF has fundamentally different command paradigms - Add .git-blame-ignore-revs step to Phase 1 - Add missing test cases: overridden/rendered for resource modules, aggregate/purge/with_address for vyos_vlan - Fix incorrect claim that version.py LooseVersion is unused - Add sequential merge requirement to preamble Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * chore: add .worktrees/ and .claude/ to .gitignore * T8522: fix parse_icmp_attr() split delimiter and UnboundLocalError - Use val.split("/") instead of val.split(".") when parsing type/code pairs - In the numeric-only branch, use int(val) instead of the undefined type_no variable - Cast both type and code to int for consistent typing Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * T8522: remove unrelated planning docs and gitignore changes These files were included from local main branch commits unrelated to this bugfix. This commit removes them to keep the PR scoped. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * T8522: add parsed test for legacy type/code ICMP format Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com> Co-authored-by: omnom62 <75066712+omnom62@users.noreply.github.com>
-rw-r--r--changelogs/fragments/fix-icmp-parse-attr.yml5
-rw-r--r--plugins/module_utils/network/vyos/facts/firewall_rules/firewall_rules.py8
-rw-r--r--tests/unit/modules/network/vyos/test_vyos_firewall_rules13.py14
3 files changed, 23 insertions, 4 deletions
diff --git a/changelogs/fragments/fix-icmp-parse-attr.yml b/changelogs/fragments/fix-icmp-parse-attr.yml
new file mode 100644
index 00000000..5cf0e199
--- /dev/null
+++ b/changelogs/fragments/fix-icmp-parse-attr.yml
@@ -0,0 +1,5 @@
+---
+bugfixes:
+ - firewall_rules - fix parse_icmp_attr() using wrong split delimiter ('.' instead of '/')
+ and referencing undefined variable type_no in the numeric-only branch, which caused
+ ValueError or UnboundLocalError when gathering firewall rules with ICMP type conditions.
diff --git a/plugins/module_utils/network/vyos/facts/firewall_rules/firewall_rules.py b/plugins/module_utils/network/vyos/facts/firewall_rules/firewall_rules.py
index 270b4a62..f8f02e7a 100644
--- a/plugins/module_utils/network/vyos/facts/firewall_rules/firewall_rules.py
+++ b/plugins/module_utils/network/vyos/facts/firewall_rules/firewall_rules.py
@@ -412,11 +412,11 @@ class Firewall_rulesFacts(object):
# <1.3 could be # (type), #/# (type/code) or 'type' (type_name)
# recent this is only for strings
if "/" in val: # type/code
- (type_no, code) = val.split(".")
- config["type"] = type_no
- config["code"] = code
+ (type_no, code) = val.split("/")
+ config["type"] = int(type_no)
+ config["code"] = int(code)
elif val.isnumeric():
- config["type"] = type_no
+ config["type"] = int(val)
else:
config["type_name"] = val
return config
diff --git a/tests/unit/modules/network/vyos/test_vyos_firewall_rules13.py b/tests/unit/modules/network/vyos/test_vyos_firewall_rules13.py
index 1af61752..edce123b 100644
--- a/tests/unit/modules/network/vyos/test_vyos_firewall_rules13.py
+++ b/tests/unit/modules/network/vyos/test_vyos_firewall_rules13.py
@@ -1576,3 +1576,17 @@ class TestVyosFirewallRulesModule13(TestVyosModule):
]
self.maxDiff = None
self.execute_module(changed=True, commands=commands)
+
+ def test_vyos_firewall_rules_parsed_icmp_type_code(self):
+ """parse_icmp_attr: legacy 'type/code' token parses into integer type and code."""
+ raw = (
+ "set firewall name TEST rule 1 action 'accept'\n"
+ "set firewall name TEST rule 1 protocol 'icmp'\n"
+ "set firewall name TEST rule 1 icmp type '3/4'\n"
+ )
+ set_module_args(dict(running_config=raw, state="parsed"))
+ result = self.execute_module(changed=False)
+ parsed = result["parsed"]
+ rule = parsed[0]["rule_sets"][0]["rules"][0]
+ self.assertEqual(rule["icmp"]["type"], 3)
+ self.assertEqual(rule["icmp"]["code"], 4)