feat(config-revisions): declare a device's own configuration history #117

Merged
christianmanivong merged 1 commits from feat/config-revisions into main 2026-11-13 21:39:38 +00:00
Owner

Contract part of NetOrk/netork#2511, declared here first (STANDARDS.md §3) before napalm-opnsense implements it (NAPALM/napalm-opnsense#48).

ConfigRevisionsMixin: a device's own configuration history.

  • get_config_revisions() and get_config_revision(revision_id) are declared only, so callable(getattr(driver, "get_config_revisions", None)) tells whether a driver has a history.
  • ConfigRevisionDict: id, time (UTC ISO 8601), description, user, size.
  • revert_config_revision(revision_id) is a template over the driver step _revert_to_config_revision. It refuses an id that is not in the history (UnknownConfigRevision, a ValueError), reads the revision before the revert can rotate it out, and afterwards checks that the newest revision holds its configuration (ConfigRevertFailed, a RuntimeError). The check is there because OPNsense answers "reverted" even when it fell back to the previous file. Returns the revision now in place.
  • config_revision_content(text) is the hook where a driver leaves out what its device stamps into every save (OPNsense's <revision> block). The default keeps the whole text. An application can compare through it too.

Tested: unit tests against an in-memory device.

Contract part of NetOrk/netork#2511, declared here first (STANDARDS.md §3) before napalm-opnsense implements it (NAPALM/napalm-opnsense#48). `ConfigRevisionsMixin`: a device's own configuration history. - `get_config_revisions()` and `get_config_revision(revision_id)` are declared only, so `callable(getattr(driver, "get_config_revisions", None))` tells whether a driver has a history. - `ConfigRevisionDict`: `id`, `time` (UTC ISO 8601), `description`, `user`, `size`. - `revert_config_revision(revision_id)` is a template over the driver step `_revert_to_config_revision`. It refuses an id that is not in the history (`UnknownConfigRevision`, a `ValueError`), reads the revision before the revert can rotate it out, and afterwards checks that the newest revision holds its configuration (`ConfigRevertFailed`, a `RuntimeError`). The check is there because OPNsense answers "reverted" even when it fell back to the previous file. Returns the revision now in place. - `config_revision_content(text)` is the hook where a driver leaves out what its device stamps into every save (OPNsense's `<revision>` block). The default keeps the whole text. An application can compare through it too. Tested: unit tests against an in-memory device.
christianmanivong added 1 commit 2026-11-13 21:28:39 +00:00
feat(config-revisions): declare a device's own configuration history
driver / lint (pull_request) Successful in 13s
driver / standard (pull_request) Successful in 16s
driver / types (pull_request) Successful in 1m3s
driver / test (3.13) (pull_request) Successful in 1m12s
driver / test (3.12) (pull_request) Successful in 1m18s
driver / lowest (pull_request) Successful in 47s
driver / build (pull_request) Successful in 34s
driver / security (pull_request) Successful in 3m34s
CI / driver (pull_request) Successful in 5m2s
driver / publish (pull_request) Skipped
43e0210ff6
Some devices keep a copy of their configuration for every save and can
go back to one. An application restores a configuration there by
reverting to the revision that holds it; on OPNsense that is the only
way, since its API takes no uploaded config.xml (NetOrk/netork#2511).

ConfigRevisionsMixin declares get_config_revisions() (newest first, as
ConfigRevisionDict) and get_config_revision(revision_id).
revert_config_revision(revision_id) is a template over the driver's
_revert_to_config_revision step: it refuses an id that is not in the
history (UnknownConfigRevision), reads the revision before the revert
can rotate it out, and afterwards checks that the newest revision holds
its configuration (ConfigRevertFailed otherwise), since a device may
report a revert it did not make. config_revision_content(text) is the
hook where a driver leaves out what its device stamps into every save,
so revisions with the same configuration compare equal.

Refs NetOrk/netork#2511
christianmanivong merged commit e43926f1d5 into main 2026-11-13 21:39:38 +00:00
christianmanivong deleted branch feat/config-revisions 2026-11-13 21:39:38 +00:00
Sign in to join this conversation.