diff options
| author | tv <tv@krebsco.de> | 2026-11-30 17:56:39 +0000 |
|---|---|---|
| committer | tv <tv@krebsco.de> | 2026-11-30 19:51:09 +0000 |
| commit | 62f857e35f94e98b3205502e410f0d727fa5ecc5 (patch) | |
| tree | 9f1197abecef97948480d710cfa4b01ad0dacf47 /src/plan.rs | |
| parent | 94c73688f08dd4a6bb25c75e62cdaf7849f6c0a1 (diff) | |
enstate: --stage, a submission for the next generation
Plans against --schema, stores the snapshot under it, and puts no views
in place and runs no reactions: the running generation goes on as it
is, keeping what it has no slot for, and the switch (--migrate) brings
the new views. The way to fill a required slot a generation adds before
switching to it, and to bring a host's first state: with the new
system's enstate, schema and configuration. Tests, and a subtest of the
VM test that does so.
Diffstat (limited to 'src/plan.rs')
| -rw-r--r-- | src/plan.rs | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/src/plan.rs b/src/plan.rs index 8627dd8..9a56505 100644 --- a/src/plan.rs +++ b/src/plan.rs @@ -44,6 +44,10 @@ pub struct Plan { /// The new snapshot's id, once applied. #[serde(skip_serializing_if = "Option::is_none")] pub snapshot: Option<String>, + /// Whether it was staged (`--stage`): its views and reactions come with the + /// switch to the generation it was planned for. + #[serde(skip_serializing_if = "std::ops::Not::not")] + pub staged: bool, /// Reactions that failed, once applied. #[serde(skip_serializing_if = "Vec::is_empty")] pub failed: Vec<String>, @@ -119,6 +123,7 @@ pub fn plan(schema: &Schema, store: &Store, submission: &Submission) -> Result<P reactions: Reactions::default(), changes: false, snapshot: None, + staged: false, failed: Vec::new(), }; let Some(channel_spec) = schema.channel(channel) else { @@ -503,6 +508,28 @@ impl Planned { plan.failed = react(&plan.reactions, systemctl, Reacting::Apply); Ok(plan) } + + /// Stages the plan, if it was accepted: only the new snapshot, for the generation + /// whose schema it was planned against, before switching to it. No views are put + /// in place and no reactions run: those of the running generation stay as they + /// are, and the switch (`--migrate`) brings the new generation's. The running + /// generation sees the snapshot as any accepted under another schema: what it has + /// no slot for is kept. + pub fn stage(self, store: &Store, schema_bytes: &[u8], lock: Lock) -> Result<Plan> { + let mut plan = self.plan; + plan.staged = true; + if plan.accepted && self.content_changes { + plan.snapshot = Some(store.commit( + &plan.channel, + &self.content, + &self.kept, + plan.current.as_deref(), + schema_bytes, + )?); + } + drop(lock); + Ok(plan) + } } /// How reactions are run. |
