> **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking.
-**Goal:** Five sequential quality improvements to the vyos.vyos Ansible collection — formatting, bugfix, dead code removal, test coverage, template deduplication.
+**Goal:** Four sequential quality improvements to the vyos.vyos Ansible collection — formatting, bugfix, dead code removal, test coverage. (Template deduplication was evaluated and deferred to v7.0.0 — see spec for rationale.)
-**Architecture:** Each phase is an independent branch and PR. Phases are ordered by risk: mechanical formatting first, then a one-line bugfix, then dead code cleanup, then new tests, then the riskiest refactor (template deduplication) last with full test coverage in place.
+**Architecture:** Each phase is an independent branch and PR. Phases are ordered by risk: mechanical formatting first, then a one-line bugfix, then dead code cleanup, then new tests. **Each phase must be merged to `main` before the next phase branches** — later phases depend on earlier ones for clean diffs and test coverage.
-Note: `plugins/module_utils/network/vyos/utils/version.py` was flagged by isort but the `LooseVersion` import is a deliberate re-export used by 19 other files. The `# pylint: disable=unused-import` comment is correct. Do NOT remove this import.
+Note: `plugins/module_utils/network/vyos/utils/version.py` imports `LooseVersion` with `# pylint: disable=unused-import`. This is a deliberate re-export — 19 files import `LooseVersion` through this module. Do NOT remove this import or change isort's handling of it.
+Black/isort may have introduced new flake8 violations (e.g., line-length edge cases in comments, unused variables exposed by reformatting). Fix any that appear before proceeding.
+
+- [ ] **Step 2: Run full lint suite**
```bash
black --check . && isort --check-only . && flake8 .
```
-Expected: All three pass with zero issues. If flake8 reports any issues, fix them before proceeding.
+Expected: All three pass with zero issues.
-- [ ] **Step 2: Run unit tests to confirm no regressions**
+- [ ] **Step 3: Run unit tests to confirm no regressions**
```bash
pytest tests/unit -vvv -n 2
```
Expected: All tests pass.
-- [ ] **Step 3: Create changelog fragment**
+- [ ] **Step 4: Get the formatting commit hash and create .git-blame-ignore-revs**
+
+A 193-file formatting commit pollutes `git blame`. Add the commit hash to `.git-blame-ignore-revs` so tools like `git blame --ignore-revs-file` skip it:
git commit -m "fix: correct snmp_server redirect in meta/runtime.yml"
```
---
## Phase 3: Deprecated Feature Cleanup
### Task 5: Remove pre-1.3 commented-out code from vyos_bgp_global
**Files:**
- Modify: `plugins/modules/vyos_bgp_global.py`
- [ ] **Step 1: Create branch**
```bash
git checkout -b chore/deprecated-cleanup main
```
- [ ] **Step 2: Identify all commented-out pre-1.3 blocks**
The following commented-out blocks in `plugins/modules/vyos_bgp_global.py` are pre-1.3 artifacts and must be removed. Each block starts with a `#` comment containing one of these markers:
- "Moved to address-family before 1.3"
- "Removed before 1.3"
- "Removed prior to 1.3"
Remove these complete commented-out blocks (the marker line AND all indented commented lines that follow as part of that parameter's YAML documentation block):
1. Lines ~86-89: `allowas_in` — "Moved to address-family before 1.3"
2. Lines ~90-93: `as_override` — "Moved to address-family before 1.3"
3. Lines ~94-107: `attribute_unchanged` — "Moved to address-family before 1.3" (includes suboptions)
4. Lines ~121-127: `orf` — "Removed before 1.3" (includes choices)
5. Lines ~149-161: `distribute_list` — "Moved to address-family before 1.3" (includes suboptions)
6. Lines ~166-190: `interface` comment block — "added in 1.3" (this is a commented-out description of a feature, not active code)
7. Lines ~191-202: `filter_list` — "Moved to address-family before 1.3" (includes suboptions)
8. Lines ~206-212: `maximum_prefix` and `nexthop_self` — "Moved to address-family before 1.3"
9. Lines ~231-242: `prefix_list` — "Moved to address-family before 1.3" (includes suboptions)
10. Lines ~246-248: `remove_private_as` — "Moved to address-family before 1.3"
11. Lines ~249-260: `route_map` — "Moved to address-family before 1.3" (includes suboptions)
12. Lines ~261-263: `route_reflector_client` — "Moved to address-family before 1.3"
13. Lines ~264-266: `route_server_client` — "Removed prior to 1.3"
14. Lines ~270-272: `soft_reconfiguration` — "Moved to address-family before 1.3"
15. Lines ~279-281: `unsuppress_map` — "Moved to address-family before 1.3"
16. Lines ~283-285: `weight` — "Moved to address-family before 1.3"
**Important:** Do NOT remove the `# <-- added in 1.3` inline comment on `solo` (line ~273) — that's an active parameter notation, not dead code.
- [ ] **Step 3: Remove all identified blocks**
Open `plugins/modules/vyos_bgp_global.py` and remove all 16 blocks listed above. After removal, the YAML docstring should flow cleanly from `capability:` → `extended_nexthop:` directly to `default_originate:`, and from `port:` directly to `remote_as:`, etc.
- [ ] **Step 4: Verify removal is complete**
```bash
grep -n "Removed before 1.3\|Removed prior to 1.3\|Moved to address-family before 1.3" plugins/modules/vyos_bgp_global.py
These features are deprecated but still needed for VyOS 1.3.8 support. Verify each has correct deprecation documentation (read-only, no changes unless text is wrong):
```bash
grep -n -A2 "Deprecated" plugins/modules/vyos_firewall_interfaces.py | head -10
grep -n -A2 "Deprecated\|Unavailable after 1.4" plugins/modules/vyos_bgp_global.py | head -10
grep -n -A2 "Deprecated\|Unavailable after 1.4" plugins/modules/vyos_vrf.py | head -10
Expected: All tests pass. If any fail, examine the fixture data and expected commands — the module's facts parser and config builder determine what commands get generated. Adjust fixture data or expected commands to match.
Note: `vyos_vlan` is a legacy module — it uses `get_config`/`load_config`/`run_commands` directly, not the resource module pattern. It uses `present`/`absent` states. The test pattern follows `test_vyos_banner.py`, not the resource module tests. This module also calls `run_commands` to do `show interfaces` for `map_config_to_obj`, so we need to mock that too.
Expected: All tests pass. The `show interfaces` mock output must match what `map_config_to_obj` parses — if tests fail, examine the parsing logic in `vyos_vlan.py:271-300` and adjust `SHOW_INTERFACES_OUTPUT` to produce the expected parsed objects.
-The `route_maps.py` and `route_maps_14.py` templates are completely identical (1405 lines each) except for the class name (`Route_mapsTemplate` vs `Route_mapsTemplate14`). The `_14` file can be replaced with a thin subclass.
-
-- [ ] **Step 1: Create branch**
-
-```bash
-git checkout -b refactor/template-deduplication main
-```
-
-- [ ] **Step 2: Read current route_maps_14.py to confirm it's identical**
-Expected: No differences (or only whitespace/comment differences). If there ARE functional differences, do not proceed with this step — investigate the differences first.
-
-- [ ] **Step 3: Replace route_maps_14.py with thin subclass**
-
-Replace the entire content of `plugins/module_utils/network/vyos/rm_templates/route_maps_14.py` with:
-
-```python
-# -*- coding: utf-8 -*-
-# Copyright 2023 Red Hat
-# GNU General Public License v3.0+
-# (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
-The difference between these files is that pre-1.4 includes `{as_number}` in command path strings (e.g., `"protocols bgp {as_number} parameters confederation"`) while 1.4+ omits it (`"protocols bgp parameters confederation"`).
-
-Strategy: Add a `_bgp_prefix()` method to the base template class. Pre-1.4 returns `"protocols bgp {as_number}"`, 1.4+ returns `"protocols bgp"`. Template functions call this method instead of hardcoding the prefix. The `_14` file becomes a subclass overriding only `_bgp_prefix()`.
-
-**This task requires careful analysis.** Before implementing:
-
-- [ ] **Step 1: Identify all differing lines between the two files**
-
-```bash
-diff plugins/module_utils/network/vyos/rm_templates/bgp_global.py plugins/module_utils/network/vyos/rm_templates/bgp_global_14.py | head -100
-```
+**Status:** Deferred to v7.0.0. See spec for full rationale.
-Examine the output. Every difference should be the `{as_number}` pattern in format strings. If there are other differences, document them and decide whether they can also be parameterized.
+**Summary of findings from architect review:**
-- [ ] **Step 2: Count the differing template functions**
+1. **route_maps are NOT identical** — ~12 semantic differences in VyOS CLI syntax (`as-path exclude` vs `as-path-exclude`, `extcommunity rt` vs `extcommunity-rt`, different `community`/`large-community` handling). A thin subclass alias would break VyOS 1.4 functionality.
+2. **BGP templates blocked by Python scoping** — template functions are module-level (not class methods). Python resolves module-level constants at the module where the function is *defined*, not where it is *called*. Importing functions from a base file and having them use the importing file's `_BGP_PREFIX` constant does not work. Real dedup would require converting ~14-28 functions to class methods or a factory pattern — high risk, marginal gain.
-- [ ] **Step 4: Convert template functions to use `_bgp_prefix()`**
+3. **ospf_interfaces have fundamentally different command paradigms** — interface-centric (pre-1.4) vs protocol-centric (1.4+). Not parameterizable.
-For each template function that contains a hardcoded `"protocols bgp {as_number}"` string, replace it with a call to `Bgp_globalTemplate._bgp_prefix()`. For example, change:
+4. **v7.0.0 eliminates the problem at its source** — dropping VyOS 1.3.x support means deleting the pre-1.4 templates entirely, with zero refactoring risk.
-**Important:** The `.format(**config_data)` call must still be applied to the entire string. Ensure the concatenation produces the same final string.
-
-**Alternative approach if template functions are module-level (not class methods):** Since template functions are standalone functions (not methods), they can't easily call instance methods. A simpler approach is to define a module-level constant:
-
-```python
-_BGP_PREFIX = "protocols bgp {as_number}"
-```
-
-Then in `bgp_global_14.py`:
-
-```python
-_BGP_PREFIX = "protocols bgp"
-```
-
-And update all template functions to use `_BGP_PREFIX` instead of the hardcoded string.
-
-- [ ] **Step 5: Replace bgp_global_14.py with thin override**
-
-Replace `plugins/module_utils/network/vyos/rm_templates/bgp_global_14.py` with a file that:
-1. Imports the base template
-2. Overrides `_BGP_PREFIX = "protocols bgp"`
-3. Copies the PARSERS list (PARSERS reference template functions, so if the functions use module-level `_BGP_PREFIX`, each module needs its own copy of the functions that reference the correct prefix)
-
-**Caution:** If the template functions are module-level and reference a module-level `_BGP_PREFIX`, you cannot simply inherit — each file needs its own function definitions that reference its own `_BGP_PREFIX`. In this case, deduplication may not reduce total lines significantly. Evaluate whether the reduction is worth the added indirection.
-
-If deduplication doesn't produce significant reduction (less than 30% line reduction), **skip this subtask** and document why in the commit message.
-Same pattern as Task 12. The difference is `{as_number}` in command path strings.
-
-- [ ] **Step 1: Identify all differences**
-
-```bash
-diff plugins/module_utils/network/vyos/rm_templates/bgp_address_family.py plugins/module_utils/network/vyos/rm_templates/bgp_address_family_14.py | head -100
-```
-
-- [ ] **Step 2: Apply the same deduplication strategy as Task 12**
-
-If Task 12 succeeded with the `_BGP_PREFIX` approach, apply the identical pattern here. If Task 12 concluded deduplication wasn't worth it, skip this task for the same reason.
-The OSPF templates have a structural difference: pre-1.4 uses interface-centric paths (`interfaces ethernet eth0 ip ospf`) while 1.4+ uses protocol-centric paths (`protocols ospf interface eth0`). This is fundamentally different from the BGP prefix pattern.
-
-- [ ] **Step 1: Measure shared vs divergent code**
-If >30% of lines differ, **do not deduplicate** — the two templates represent genuinely different configuration paradigms. Document the decision.
-
-- [ ] **Step 2: If shared >70%, extract base (unlikely)**
-
-Only proceed if analysis shows >70% shared code. Otherwise, commit a decision note:
-
-```bash
-git commit --allow-empty -m "docs: ospf_interfaces templates not deduplicated — structural differences too large (interface-centric vs protocol-centric paths)"
-Five sequential phases of improvements to the vyos.vyos collection, ordered by risk (lowest first). Each phase is an independent PR with its own changelog fragment.
+Four sequential phases of improvements to the vyos.vyos collection, ordered by risk (lowest first). Each phase is an independent PR with its own changelog fragment. **Each phase must be merged to `main` before the next phase branches** — later phases depend on earlier ones for clean diffs and test coverage.
-- Remove unused import in `plugins/module_utils/network/vyos/utils/version.py:13` — `LooseVersion` imported but never used in that file
+- Add `.git-blame-ignore-revs` file with the formatting commit hash to prevent polluting `git blame`
+- Fix any flake8 issues that surface after black/isort changes
+
+**Note:** `plugins/module_utils/network/vyos/utils/version.py:13` imports `LooseVersion` with `# pylint: disable=unused-import`. This is a deliberate re-export — 19 files import `LooseVersion` through this module. Do NOT remove it.
**Verification:** `black --check . && isort --check-only . && flake8 .` all pass with zero issues.
-**Changelog fragment:** `minor_changes` — "Collection-wide formatting compliance with black, isort, and flake8."
+**Changelog fragment:** `minor_changes` — "Collection-wide formatting compliance with black and isort."
---
## Phase 2 — Fix meta/runtime.yml Redirect
**Goal:** Fix broken module redirect for `snmp_server`.
**Bug:** `meta/runtime.yml:57-58` redirects `snmp_server` to `vyos.vyos.vyos_snmp_servers` (plural). The actual module is `vyos_snmp_server` (singular). No file `vyos_snmp_servers.py` exists. All other 27 redirects are correct.
**Fix:** Change line 58 from `redirect: vyos.vyos.vyos_snmp_servers` to `redirect: vyos.vyos.vyos_snmp_server`.
**Verification:** Confirm the module `plugins/modules/vyos_snmp_server.py` exists. Grep for any other references to `vyos_snmp_servers` (plural) that might need updating.
**Changelog fragment:** `bugfixes` — "Fix meta/runtime.yml redirect for snmp_server pointing to non-existent vyos_snmp_servers module."
---
## Phase 3 — Deprecated Feature Audit and Cleanup
**Goal:** Remove dead code for features deprecated before VyOS 1.3.8 and document remaining deprecations clearly. Do NOT remove features that are still valid for 1.3.8 — those are scheduled for v7.0.0.
`plugins/modules/vyos_bgp_global.py` contains multiple commented-out parameter blocks with notes like "Removed before 1.3", "Removed prior to 1.3", "Moved to address-family before 1.3". These are at lines 121, 149, 191, 206, 210, 231, 246, 249, 261, 264, 270, 279, 283. Remove all commented-out pre-1.3 artifacts.
For each: verify the deprecation notice text is accurate and consistent. No code removal — these still serve 1.3.8 users.
### 3c — Verify tombstoned modules
`meta/runtime.yml:36-42` tombstones `logging` and `vyos_logging` with `removal_version: 6.0.0`. Verify no code for these modules still exists. If stale code remains, remove it.
**Verification:** `grep -r "Removed before 1.3\|Removed prior to 1.3\|Moved to address-family before 1.3" plugins/` returns no results after cleanup.
-Config modules (e.g., `config/bgp_global/bgp_global.py`) import both template classes and switch via `_validate_template()` using `LooseVersion(get_os_version(module)) >= LooseVersion("1.4")`. Facts modules do the same in `populate_facts()`.
-
-### Deduplication strategy
-
-**For BGP templates (bgp_global, bgp_address_family):** The only difference is `{as_number}` in command path strings. Extract a base class with a `_cmd_prefix()` method that returns the protocol path prefix. Pre-1.4 subclass includes `{as_number}`, 1.4+ subclass omits it. All template functions and PARSERS list stay in the base.
-
-**For route_maps:** These are identical except the class name. Merge into a single file. The `_14` variant becomes a subclass alias or is eliminated entirely.
-
-**For ospf_interfaces:** The structural difference is larger (interface-centric vs protocol-centric command paths). These may not be good deduplication candidates. Assess shared template entries vs divergent ones. If >70% shared, extract a base; otherwise leave as-is.
-
-### Files to modify
-
-For each deduplicated template pair:
-- Create or modify the base template file with shared logic
-- Modify the `_14` file to inherit from the base, overriding only what differs
-- Update imports in corresponding `config/` and `facts/` modules if class names change
-- Update corresponding unit test imports if any
+**route_maps are NOT identical** — the initial analysis was wrong. They differ in VyOS CLI syntax for compound commands and community handling. A thin subclass alias would break VyOS 1.4 functionality.
-### Constraints
+**BGP templates use module-level functions** — template functions (e.g., `_tmplt_bgp_params_confederation`) are standalone module-level functions, not class methods. Python resolves a module-level `_BGP_PREFIX` constant at the module where the function is *defined*, not where it is *called*. You cannot import functions from the base file and have them use the importing file's constant. Real dedup would require converting all ~14-28 functions to class methods or using a factory pattern — high risk, marginal gain.
-- The dispatch mechanism in config and facts modules must continue to work identically
-- All existing unit tests must pass without modification (except import path changes)
-- Template class interfaces (PARSERS list, method signatures) must remain identical
+**ospf_interfaces have fundamentally different command paradigms** — interface-centric vs protocol-centric is not a parameterizable difference.
-**Verification:** Full test suite passes. Manual review of generated commands for both VyOS versions matches current behavior.
+### Recommendation
-**Changelog fragment:** `minor_changes` — "Refactor version-specific rm_templates to reduce duplication between pre-1.4 and 1.4+ variants."
+Defer to v7.0.0 when VyOS 1.3.x support is dropped. Deleting the pre-1.4 templates entirely eliminates the duplication at its source with zero refactoring risk.
---
## Ordering Rationale
1. **Formatting first** — creates a clean diff baseline for all subsequent work
2. **Runtime fix** — trivial, fixes a real bug
3. **Deprecation cleanup** — removes dead code before we add tests or refactor around it
-4. **Tests** — adds coverage before the highest-risk refactor
-5. **Deduplication** — highest risk, most lines changed, benefits from all prior cleanup
+4. **Tests** — adds coverage for previously untested modules