Skip to main content

Fake

Struct Fake 

Source
pub struct Fake {
    pub world: Arc<Mutex<World>>,
    pub store: MemStore,
}
Expand description

The handle every backend trait is implemented on. Cheap to clone; all clones share one world and one journal store.

Fields§

§world: Arc<Mutex<World>>§store: MemStore

Implementations§

Source§

impl Fake

Source

pub fn footprint_view(&self, tools: &[UnitId]) -> FootprintView

§12d: the footprints as /run/planarian/footprint/ would hold them for the network tools tools, on the boot clock (seconds): the same planarian_backend_netwatch::FootprintView the Linux side reads.

Source

pub fn new(world: World, store: MemStore) -> Fake

Source

pub fn w(&self) -> MutexGuard<'_, World>

Source

pub(crate) fn hung( &self, verb: &str, unit: &UnitId, wait: Millis, ) -> Option<Outcome>

hold_hangs: a hold call (systemctl start/stop, nft) that takes that long. Past wait the client gives up (Unknown, the fake clock advanced by wait) and nothing lands; within it, the call takes its time and goes on.

Source

pub fn advance(&self, d: Millis)

Source

pub(crate) fn admit(&self, w: &mut World, op: &OpId, call: String) -> bool

Source

pub(crate) fn run( &self, op: &OpId, call: String, f: impl FnOnce(&mut World) -> Outcome, ) -> Outcome

One mutating backend call: fenced on a stale epoch before any effect (docs/assumptions.md), and subject to an injected outcome (World::inject, keyed by the call’s name before its parenthesis).

Trait Implementations§

Source§

impl Backends for Fake

Source§

type Units = Fake

Source§

type Gens = Fake

Cloned onto a worker thread for the slow part of planning a change.
Source§

type Inv = Fake

Source§

type Probes = Fake

Source§

type Sessions = Fake

Source§

type Runtime = Fake

Source§

type Procs = Fake

Source§

type Clock = Fake

Source§

fn units(&self) -> &Fake

Source§

fn generations(&self) -> &Fake

Source§

fn inventory(&self) -> &Fake

Source§

fn probes(&self) -> &Fake

Source§

fn sessions(&self) -> &Fake

Source§

fn runtime(&self) -> &Fake

Source§

fn processes(&self) -> &Fake

Source§

fn clock(&self) -> &Fake

Source§

impl Clock for Fake

Source§

fn now(&self) -> Timestamp

The world’s now is elapsed time (boot time); the wall clock is it plus wall_skew, which only set_wall_clock moves (§12h).

Source§

fn boot_now(&self) -> Timestamp

Milliseconds on CLOCK_BOOTTIME: for everything that does not survive a reboot (approval tokens, leases, cooldowns, windows; §12h). Moving the wall clock never moves it.
Source§

fn sleep(&self, d: Millis)

Source§

impl Clone for Fake

Source§

fn clone(&self) -> Fake

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Fake

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl GenerationBackend for Fake

Source§

fn current(&self) -> Result<GenerationId, Outcome>

Source§

fn boot_entries(&self) -> Result<Vec<GenerationId>, Outcome>

Source§

fn boot_default(&self) -> Result<GenerationId, Outcome>

Source§

fn last_booted(&self) -> Result<GenerationId, Outcome>

Source§

fn created_by(&self, g: GenerationId) -> Option<(u32, Timestamp)>

Who created generation g and when (its profile link’s owner and time): the provenance of a rebuild made outside Planarian (§15).
Source§

fn stage( &self, _owner: &PinnedSource, overrides: &OverrideSet, ) -> Result<StagedSource, Outcome>

Source§

fn source_hash(&self, _owner: &PinnedSource) -> Result<Hash, Outcome>

Recompute the NAR hash of the owner’s Nix-visible source now (stale check, §9 step 6).
Source§

fn untracked(&self, _owner: &PinnedSource) -> Vec<String>

The owner’s files Nix cannot see now (untracked in a git flake), to report with the stale check: one added during the build was not there at staging (§9 step 1).
Source§

fn evaluate(&self, src: &StagedSource) -> Result<EvaluatedGeneration, Outcome>

Source§

fn build(&self, eval: &EvaluatedGeneration) -> Result<Built, Outcome>

Store-only; roots its own output.
Source§

fn dry_activation(&self, path: &StorePath) -> Result<ActivationPlan, Outcome>

What switching from the running generation to an existing one would start, stop, restart and reload (its dry activation), for SwitchGeneration / Revert / Rollback (§11, R04). An activation that failed, timed out or was cut short is an error, never a smaller plan.
Source§

fn override_content(&self, h: &Hash) -> Result<OverrideSet, Outcome>

The override content remember_override kept under this hash.
Source§

fn verify_candidate( &self, path: &StorePath, nar: Option<&Hash>, ) -> Result<bool, Outcome>

The path is a whole system, its contents still hash to what the store recorded, and, when nar is given (the transaction built it), that is the NAR hash recorded at build (§9 step 3, C6).
Source§

fn pending_jobs(&self) -> Result<Vec<JobId>, Outcome>

Source§

fn jobs_tagged(&self, op: &OpId) -> Result<Option<Vec<JobId>>, Outcome>

None: the backend cannot say whether work tagged with op exists.
Source§

fn override_hash(&self) -> Result<Hash, Outcome>

The override file’s current content hash (promotion compares against it, §9 step 4).
Source§

fn activate_live(&self, g: GenerationId, op: &OpId) -> Outcome

switch-to-configuration test.
Source§

fn publish_boot(&self, g: GenerationId, op: &OpId) -> Outcome

Boot entry only; no re-activation.
Source§

fn publish_boot_once( &self, g: GenerationId, keep: GenerationId, op: &OpId, ) -> Outcome

The boot-only path (§12 step 7, §12f): g boots once, at the next boot; keep stays the default. All or nothing.
Source§

fn one_shot_pending(&self) -> Result<Option<GenerationId>, Outcome>

The generation a one-shot entry will boot next, if one is pending.
Source§

fn protect(&self, g: GenerationId, op: &OpId) -> Outcome

Source§

fn cancel(&self, job: &JobId, op: &OpId) -> Outcome

Source§

fn swap_override(&self, from: &Hash, to: &Hash, op: &OpId) -> Outcome

Atomically replace the live override file with the content whose hash is to, but only if its current hash is from. Idempotent: if it already hashes to to, succeed without writing.
Source§

fn path_of(&self, g: GenerationId) -> Result<StorePath, Outcome>

The system store path of a known generation.
Source§

fn evaluate_built( &self, path: &StorePath, ) -> Result<EvaluatedGeneration, Outcome>

Evaluate an already-built generation from its store path (its exported manifest), for SwitchGeneration / Revert / Rollback.
Source§

fn read_overrides(&self) -> Result<(OverrideSet, Hash), Outcome>

The live override set and its content hash.
Source§

fn remember_override(&self, set: &OverrideSet) -> Result<Hash, Outcome>

Keep override content addressable by hash, so swap_override can write it.
Source§

fn override_for(&self, g: GenerationId) -> Result<Option<Hash>, Outcome>

The override content recorded for a generation when it was committed.
Source§

fn record_override(&self, g: GenerationId, hash: &Hash) -> Result<(), Outcome>

Source§

fn release_root(&self, root: &str) -> bool

Remove a GC root symlink this backend created.
Source§

fn collect_garbage( &self, protect: &[GenerationId], emergency: bool, op: &OpId, ) -> Outcome

Collect generations under the §12b bounds (gc::plan), never touching protect (I3), then collect store garbage. Mutating.
Source§

fn gc_plan( &self, protect: &[GenerationId], emergency: bool, ) -> Result<GcPlan, Outcome>

What collect_garbage would delete now. Read-only.
Source§

fn space_report(&self) -> Option<SpaceReport>

The last collection’s result.
Source§

fn age_out_build_roots(&self) -> Vec<String>

Remove build roots no transaction can still use: older than the longest a candidate may wait (§12f), a crashed build’s included. At startup and before every collection (§9 step 5, C4). Returns them.
Source§

impl InventoryBackend for Fake

Source§

fn devices(&self) -> Result<Vec<DeviceInfo>, Outcome>

Source§

fn resources(&self) -> Result<Resources, Outcome>

Source§

fn bound_driver(&self, device: &UnitId) -> Result<Option<DriverRef>, Outcome>

Source§

fn bind(&self, device: &UnitId, driver: &DriverRef, op: &OpId) -> Outcome

Source§

fn unbind(&self, device: &UnitId, op: &OpId) -> Outcome

Source§

impl ProbeBackend for Fake

Source§

fn run_batch(&self, jobs: &[(UnitId, ProbeDef)]) -> Vec<ProbeResult>

Run probes concurrently, each in its sandbox, each killed at its timeout (§10). One result per job, in order. FreeSpace probes are answered here too; SystemdActive and SessionTarget are evaluated by state.
Source§

impl ProcessBackend for Fake

Source§

fn kill_group(&self, pid: u32) -> bool

SIGTERM, then SIGKILL, the process group via pidfd; true once confirmed gone.
Source§

fn alive(&self, pid: u32) -> bool

Source§

impl RuntimeOptionBackend for Fake

Source§

fn get(&self, path: &str) -> Option<Value>

Source§

fn set(&self, path: &str, value: &Value, op: &OpId) -> Outcome

Outcome::Failed("no live mechanism") when the option can only be changed through its write-back.
Source§

fn alternatives(&self, path: &str) -> Vec<Value>

Other values the option could take right now (for wifi.network: known networks in range, besides the current one).
Source§

impl SessionBackend for Fake

Source§

fn sessions(&self) -> Result<Vec<SessionInfo>, Outcome>

Source§

fn compositor_running(&self, s: &SessionInfo) -> Option<bool>

Whether a compositor runs in this session’s own cgroup (§9); None if the backend cannot see.
Source§

fn foreground(&self) -> Vec<String>

Sessions in which foreground work holds (§10: a GameMode client, a gamescope session, …): Condition::Foreground.
Source§

fn power(&self) -> Option<PowerSource>

Source§

impl UnitBackend for Fake

Source§

fn protecting(&self, tools: &[UnitId]) -> Result<BTreeSet<UnitId>, Outcome>

§12d: the scripted footprints (footprint_view), read as the Linux side reads the files.

Source§

fn observe(&self, id: &UnitId) -> Result<Observed, Outcome>

Source§

fn ended_by(&self, id: &UnitId) -> Option<Ending>

How the unit’s main process last ended; None if the backend cannot say.
Source§

fn auto_restarts(&self, id: &UnitId) -> Option<u32>

How many times systemd itself restarted the unit (NRestarts); None if the backend cannot say.
Source§

fn foreign_units(&self) -> Vec<String>

The boot report’s unit check (§10): active units whose definition does not come from the running generation (a file outside the store that is not a generator’s).
Source§

fn list(&self) -> Result<Vec<UnitId>, Outcome>

Source§

fn start_agent( &self, name: &str, _argv: &[String], _limits: &AgentLimits, ) -> Result<InstanceId, Outcome>

Start an agent (§11, §16): the transient unit planarian-agent-<name>, under a dynamic uid of its own. Returns the started unit’s instance (its InvocationID), read back once it has started (I24).
Source§

fn agent_running(&self, name: &str) -> bool

Whether an agent’s unit under this name is loaded and running (I24: agent run refuses a name in use).
Source§

fn hold(&self, unit: &UnitId, wait: Millis) -> Outcome

§12d Network security fails closed: hold the traffic a failed network-security unit protected (planarian-hold@<unit>). A failure posture response, not a transition: no Prepared, no lease (it only ever restricts traffic; docs/bypasses.md). Idempotent. Unlike the other mutations here it takes no OpId; the daemon journals HoldApplied before calling it. Read more
Source§

fn lift_hold(&self, unit: &UnitId, wait: Millis) -> Outcome

Lift a unit’s hold, once it is Running and its Readiness probes pass (journaled HoldLifted first). Idempotent. At most wait.
Source§

fn held(&self) -> Result<BTreeSet<UnitId>, Outcome>

The units whose traffic is held now, as the host says (§12d: the hold survives a restart of planariad). An error means “cannot say”, never “none”.
Source§

fn release_hold( &self, unit: &UnitId, until: Option<Timestamp>, wait: Millis, ) -> Outcome

planarian hold release (an attested Override, decided before this): mark the unit’s hold released until until (None: the next boot), then lift it, waiting at most wait. While the mark stands, a new failure does not hold.
Source§

fn end_release(&self, unit: &UnitId) -> Outcome

The release ended (expired, or the override lifted): remove the mark.
Source§

fn hold_table_present(&self, wait: Millis) -> Result<bool, Outcome>

Whether the hold’s nftables table is in place. Anything else that flushes the ruleset (nft flush ruleset) removes it and would fail open; the daemon checks this while a hold is active. An error means “cannot say” (also past wait).
Source§

fn reapply_hold(&self, unit: &UnitId, wait: Millis) -> Outcome

Build a unit’s hold again (the table was removed under it): restart its hold unit, since starting an active one does nothing. At most wait.
Source§

fn restart(&self, id: &UnitId, op: &OpId) -> Outcome

Source§

fn stop(&self, id: &UnitId, op: &OpId) -> Outcome

Auto Trait Implementations§

§

impl Freeze for Fake

§

impl RefUnwindSafe for Fake

§

impl Send for Fake

§

impl Sync for Fake

§

impl Unpin for Fake

§

impl UnsafeUnpin for Fake

§

impl UnwindSafe for Fake

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.