feat: add automatic policy rule cleanup when disabling or switching to audit mode with provider-level rule deletion
Add cluster_provider_targets helper to build target list from all cluster workloads, implement cleanup_policy_provider_rules to delete policy rules across all clusters with per-cluster result tracking, add delete_policy_rules method to ProxmoxProvider that removes rules matching policy ID marker with error collection, extend policy_id_marker and rule_comment_matches_marker helpers for
This commit is contained in:
@@ -107,3 +107,23 @@ async def test_apply_rules_replaces_only_marked_nexafabric_rules(monkeypatch: py
|
||||
"comment": "NexaFabric policy=policy-1 version=2 rule=1 target=web",
|
||||
}
|
||||
]
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_delete_policy_rules_removes_marked_rules(monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
FakeAsyncClient.deleted_urls = []
|
||||
FakeAsyncClient.posted_payloads = []
|
||||
FakeAsyncClient.put_urls = []
|
||||
FakeAsyncClient.put_payloads = []
|
||||
monkeypatch.setattr(proxmox.httpx, "AsyncClient", FakeAsyncClient)
|
||||
|
||||
result = await ProxmoxProvider().delete_policy_rules(
|
||||
ProviderConnection(api_url="https://pve.example:8006", token="user@pve!token=secret", read_only=False),
|
||||
[{"node": "pve1", "kind": "qemu", "vmid": "100"}],
|
||||
"policy-1",
|
||||
)
|
||||
|
||||
assert result["applied"] is True
|
||||
assert result["rules_deleted"] == 1
|
||||
assert FakeAsyncClient.deleted_urls == ["https://pve.example:8006/api2/json/nodes/pve1/qemu/100/firewall/rules/1"]
|
||||
assert FakeAsyncClient.posted_payloads == []
|
||||
|
||||
Reference in New Issue
Block a user