Skip to content

Commit d04b430

Browse files
Merge pull request #42 from fastrevmd-lab/fix/40-atomic-candidate-change-with-warnings
release: rustez 0.14.1 — atomic candidate-change for the warnings path
2 parents 82c7ae0 + 3382e96 commit d04b430

7 files changed

Lines changed: 65 additions & 29 deletions

File tree

‎CLAUDE.md‎

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,17 +39,17 @@ Auth: set `RUSTEZ_VSRX_KEY` for key-based or `RUSTEZ_VSRX_PASS` for password aut
3939
- **ConfigPayload::Set** — maps to `LoadAction::Set, LoadFormat::Text`.
4040
- **Namespace prefix** — `build_load_xml()` uses `nc:` prefix on XML elements to match rustnetconf 0.7.1's `<nc:rpc>` envelope. Required for Junos 24.4 compatibility.
4141
- **Cluster auto-open** — `ConfigManager::load()` auto-calls `open_configuration(Private)` on clustered devices. `unlock()` auto-closes it. State tracked on `Device.config_db_open`.
42-
- **Candidate-dirty tracking** — rustnetconf 0.14 only sends `<discard-changes/>` on close when *this* session dirtied the shared
42+
- **Candidate-dirty tracking** — rustnetconf only sends `<discard-changes/>` on close when *this* session dirtied the shared
4343
candidate. Typed ops (`load_configuration`, `rollback_configuration`, `edit_config`) mark it automatically; the raw `rpc()` /
44-
`rpc_with_warnings()` path does not. **Prefer `RpcExecutor::call_xml_candidate_change()`** (Python:
45-
`Device.rpc.raw_xml_candidate_change()`), which routes through `client.rpc_candidate_change()` and validates → preflights →
46-
marks → sends atomically. Surfaced to callers as `Device::touched_candidate()`.
44+
`rpc_with_warnings()` path does not. **Never hand-mark.** Use an atomic candidate-change call, which validates → preflights →
45+
marks → sends as one step: `client.rpc_candidate_change()` (via `RpcExecutor::call_xml_candidate_change()`, Python
46+
`Device.rpc.raw_xml_candidate_change()`), or `client.rpc_candidate_change_with_warnings()` when warnings are needed
47+
(`ConfigManager::load_with_warnings()`). Surfaced to callers as `Device::touched_candidate()`.
4748
- **A false dirty mark is worse than a missing one** — a missing mark leaves a dirty candidate that blocks the next lock; a false
48-
mark makes `close()` discard *another operator's* uncommitted work, which is the bug this tracking exists to prevent. So if you
49-
must hand-mark (only `load_with_warnings()` does, because there is no `rpc_candidate_change_with_warnings`), **validate the
50-
fragment with `rustnetconf::rpc::validate_xml_fragment()` first, and validate before opening the config database** — the raw
51-
`rpc*` calls reject a malformed fragment locally without sending, and `ConfigPayload::Xml` passes caller XML through unescaped.
52-
Mark after validation but before the send, so a timeout or partial apply still counts.
49+
mark makes `close()` discard *another operator's* uncommitted work, which is the bug this tracking exists to prevent. The raw
50+
`rpc*` calls reject a malformed fragment locally *without sending*, and `ConfigPayload::Xml` passes caller XML through
51+
unescaped, so hand-marking before one of them is a live way to reintroduce the bug. `mark_candidate_dirty()` exists but rustEZ
52+
no longer calls it anywhere — the atomic calls above own the mark, and nothing should mark outside them.
5353
- **Warnings** — `RpcExecutor::call_with_warnings()` / `call_xml_with_warnings()` return `(String, Vec<RpcErrorInfo>)`. `ConfigManager::load_with_warnings()` does the same for config loads.
5454

5555
## Architecture

‎rustez-cli/Cargo.toml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ publish = false
1111

1212
[dependencies]
1313
rustez = { path = "../rustez" }
14-
rustnetconf = "0.14.0"
14+
rustnetconf = "0.14.1"
1515
tokio = { version = "1", features = ["full"] }
1616
clap = { version = "4", features = ["derive"] }
1717
serde = { version = "1", features = ["derive"] }

‎rustez-py/Cargo.toml‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "rustez-py"
3-
version = "0.14.0"
3+
version = "0.14.1"
44
edition = "2021"
55
authors = ["fastrevmd-lab"]
66
description = "Python bindings for rustEZ — pip install rustez"
@@ -15,6 +15,6 @@ crate-type = ["cdylib"]
1515

1616
[dependencies]
1717
rustez = { path = "../rustez" }
18-
rustnetconf = "0.14.0"
18+
rustnetconf = "0.14.1"
1919
pyo3 = { version = "0.29", features = ["extension-module"] }
2020
tokio = { version = "1", features = ["full"] }

‎rustez-py/pyproject.toml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "maturin"
44

55
[project]
66
name = "rustez"
7-
version = "0.14.0"
7+
version = "0.14.1"
88
description = "Python bindings for rustEZ — Junos device automation built on Rust"
99
requires-python = ">=3.9"
1010
license = "MIT"

‎rustez/CHANGELOG.md‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,39 @@ All notable changes to the `rustez` crate are documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [0.14.1] — 2026-08-20
9+
10+
### Fixed
11+
12+
- **`load_with_warnings()` no longer hand-marks the candidate** (#40). 0.14.0
13+
had to validate the fragment itself and then call `mark_candidate_dirty()`
14+
before `rpc_with_warnings()`, because rustnetconf had no atomic
15+
candidate-change call that returns warnings. That workaround closed the
16+
malformed-XML hole but could not reach rustnetconf's private
17+
`keepalive_check()` / `ensure_established()` preflight, so a dead or
18+
unreachable session could still leave a **false** dirty mark — and a false
19+
mark is the dangerous direction: `close()` acting on it discards another
20+
operator's uncommitted work on the shared Junos candidate, which is precisely
21+
the bug 0.14.0 set out to fix.
22+
23+
rustnetconf 0.14.1 adds `rpc_candidate_change_with_warnings()`, which
24+
validates, preflights, marks, and only then sends — as one step. The
25+
hand-rolled sequence is gone, and `mark_candidate_dirty()` is now called
26+
nowhere in rustEZ: the atomic calls own the mark, so nothing can mark for an
27+
RPC that never reached the device.
28+
29+
### Changed
30+
31+
- Bumped `rustnetconf` to `0.14.1`. Additive patch upgrade — no behaviour
32+
changes and no API removals.
33+
34+
### Notes
35+
36+
- No public rustEZ API changed. `commit_with_comment()`'s inverse limitation is
37+
unchanged and still documented under 0.14.0 — it cannot *clear* the flag on
38+
the raw `rpc()` path, because there is still no typed commit-with-comment
39+
upstream.
40+
841
## [0.14.0] — 2026-08-19
942

1043
### Fixed
@@ -189,6 +222,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
189222
was `AcceptAll`. Since `rustnetconf 0.11` the default has been `RejectAll`
190223
(fail-closed); the docs now reflect this.
191224

225+
[0.14.1]: https://github.com/fastrevmd-lab/rustez/compare/v0.14.0...v0.14.1
192226
[0.14.0]: https://github.com/fastrevmd-lab/rustez/compare/v0.13.1...v0.14.0
193227
[0.13.1]: https://github.com/fastrevmd-lab/rustez/compare/v0.13.0...v0.13.1
194228
[0.13.0]: https://github.com/fastrevmd-lab/rustez/compare/v0.12.1...v0.13.0

‎rustez/Cargo.toml‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "rustez"
3-
version = "0.14.0"
3+
version = "0.14.1"
44
edition = "2021"
55
authors = ["fastrevmd-lab"]
66
description = "A Rust replacement for Juniper PyEZ — async-first Junos automation built on rustnetconf"
@@ -11,7 +11,7 @@ categories = ["network-programming"]
1111
rust-version = "1.79"
1212

1313
[dependencies]
14-
rustnetconf = "0.14.0"
14+
rustnetconf = "0.14.1"
1515
tokio = { version = "1", features = ["full"] }
1616
quick-xml = "0.41"
1717
thiserror = "2"

‎rustez/src/config.rs‎

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use std::time::Duration;
44

55
use quick_xml::escape::escape;
66
use rustnetconf::rpc::RpcErrorInfo;
7-
use rustnetconf::{Client, Datastore, LoadAction, LoadFormat, NetconfError, OpenConfigurationMode};
7+
use rustnetconf::{Client, Datastore, LoadAction, LoadFormat, OpenConfigurationMode};
88

99
/// XML namespace prefix used by rustnetconf for NETCONF RPCs.
1010
const NC: &str = "nc:";
@@ -125,26 +125,26 @@ impl<'a> ConfigManager<'a> {
125125
/// returns alongside a successful load. See [`load()`](Self::load) for
126126
/// the auto-open and error-cleanup behavior.
127127
///
128-
/// This method marks the candidate dirty so that `close_session()` knows
129-
/// a discard may be needed.
128+
/// Marks the candidate dirty so `close()` cleans up after this session.
129+
/// The mark is applied by rustnetconf's atomic candidate-change path, which
130+
/// validates and preflights before marking — a fragment that never reaches
131+
/// the device leaves no mark behind.
130132
pub async fn load_with_warnings(
131133
&mut self,
132134
payload: ConfigPayload,
133135
) -> Result<(String, Vec<RpcErrorInfo>), RustEzError> {
134-
// Build and validate the XML BEFORE opening or marking. rpc_with_warnings
135-
// internally calls validate_xml_fragment and returns early if malformed,
136-
// without sending anything. Validation must precede the mark because a
137-
// false mark causes close() to discard a third party's work. This does not
138-
// replicate upstream's keepalive/ensure_established preflight — only
139-
// rpc_candidate_change does that, and it has no warnings variant.
136+
// rpc_candidate_change_with_warnings (rustnetconf 0.14.1) validates the
137+
// fragment, runs the send preflight, marks the candidate, and only then
138+
// writes — atomically. It replaces a hand-rolled validate-then-mark that
139+
// could not reach the private keepalive/ensure_established checks, so a
140+
// dead session could still leave a false mark for close() to act on.
141+
// Do not reintroduce a separate mark_candidate_dirty() call here: the
142+
// whole point is that nothing marks outside this one atomic path.
140143
let xml = build_load_xml(&payload);
141-
rustnetconf::rpc::validate_xml_fragment(&xml).map_err(NetconfError::from)?;
142-
143144
let opened_here = self.auto_open_if_needed().await?;
144145

145-
self.client.mark_candidate_dirty();
146146
let timeout = self.timeout;
147-
let result = timed(timeout, self.client.rpc_with_warnings(&xml)).await;
147+
let result = timed(timeout, self.client.rpc_candidate_change_with_warnings(&xml)).await;
148148
if result.is_err() {
149149
self.close_auto_opened_on_error(opened_here).await;
150150
}
@@ -318,7 +318,9 @@ fn payload_to_load_args(payload: &ConfigPayload) -> (LoadAction, LoadFormat, Str
318318

319319
/// Build the `<load-configuration>` XML for a given payload.
320320
///
321-
/// Used by `load_with_warnings()` which needs raw RPC for warning extraction.
321+
/// Used by `load_with_warnings()`, which builds the fragment itself because the
322+
/// typed `load_configuration()` does not return warnings. The fragment goes to
323+
/// `rpc_candidate_change_with_warnings()`, which validates it before sending.
322324
/// Uses `nc:` namespace prefix to match rustnetconf's RPC envelope.
323325
/// `Text` and `Set` payloads are XML-escaped to prevent injection.
324326
/// `Xml` is passed through raw since it's explicitly raw XML by design.

0 commit comments

Comments
 (0)