fix(update): keep fetched distfiles when binary prebuild is skipped
emerge --buildpkgonly refuses while dependencies still need merging, which is normal for an out-of-date system. Record that as Ready with the fetched distfiles and the Portage reason instead of a hard Failure, and include the redacted stderr tail in the state note. The VM harness check timeout is now configurable.
This commit is contained in:
parent
035826e0f9
commit
a20e064680
2 changed files with 114 additions and 18 deletions
|
|
@ -13,6 +13,7 @@ use crate::error::{ExecError, Result};
|
||||||
use crate::exec::Exec;
|
use crate::exec::Exec;
|
||||||
use crate::portage;
|
use crate::portage;
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
pub struct PrepareOutcome {
|
pub struct PrepareOutcome {
|
||||||
pub started: bool,
|
pub started: bool,
|
||||||
pub note: String,
|
pub note: String,
|
||||||
|
|
@ -100,33 +101,55 @@ pub fn prepare(exec: &Exec, root: &Path, cores: u32, force: bool) -> Result<Prep
|
||||||
};
|
};
|
||||||
save_state(exec, root, &state)?;
|
save_state(exec, root, &state)?;
|
||||||
|
|
||||||
let result = (|| -> Result<()> {
|
// Phase 1: distfiles. A failure here is a real failure.
|
||||||
portage::chroot(exec, root, "emerge", &fetch_args())?;
|
if let Err(e) = portage::chroot(exec, root, "emerge", &fetch_args()) {
|
||||||
|
state.status = PrepareStatus::Failed;
|
||||||
|
state.note = describe_failure(&e);
|
||||||
|
let _ = save_state(exec, root, &state);
|
||||||
|
return Err(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Phase 2: reusable binary packages. `--buildpkgonly` refuses while
|
||||||
|
// dependencies still need merging, which is the common case for a system
|
||||||
|
// that is behind on updates. The distfiles are already fetched, so record
|
||||||
|
// that honestly as Ready with the reason rather than a hard failure that
|
||||||
|
// would hide the successful fetch. Activation stays explicit.
|
||||||
state.note = "building binary packages".into();
|
state.note = "building binary packages".into();
|
||||||
let _ = save_state(exec, root, &state);
|
let _ = save_state(exec, root, &state);
|
||||||
portage::chroot(exec, root, "emerge", &build_args())?;
|
match portage::chroot(exec, root, "emerge", &build_args()) {
|
||||||
Ok(())
|
|
||||||
})();
|
|
||||||
|
|
||||||
match result {
|
|
||||||
Ok(()) => {
|
Ok(()) => {
|
||||||
state.status = PrepareStatus::Ready;
|
state.status = PrepareStatus::Ready;
|
||||||
state.note = "updates prepared (not activated)".into();
|
state.note = "updates prepared (not activated)".into();
|
||||||
state.last_prepared_unix = now_unix();
|
|
||||||
save_state(exec, root, &state)?;
|
|
||||||
exec.logger
|
exec.logger
|
||||||
.info("background update preparation complete (not activated)");
|
.info("background update preparation complete (not activated)");
|
||||||
|
}
|
||||||
|
Err(e) => {
|
||||||
|
state.status = PrepareStatus::Ready;
|
||||||
|
state.note = format!(
|
||||||
|
"distfiles fetched; binary prebuild skipped: {}",
|
||||||
|
describe_failure(&e)
|
||||||
|
);
|
||||||
|
exec.logger.warn(format!("binary prebuild skipped: {e}"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
state.last_prepared_unix = now_unix();
|
||||||
|
save_state(exec, root, &state)?;
|
||||||
Ok(PrepareOutcome {
|
Ok(PrepareOutcome {
|
||||||
started: true,
|
started: true,
|
||||||
note: state.note.clone(),
|
note: state.note.clone(),
|
||||||
})
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Include the (already redacted) stderr tail of a failed command so the state
|
||||||
|
/// explains *why* preparation failed instead of only the exit status.
|
||||||
|
fn describe_failure(error: &ExecError) -> String {
|
||||||
|
match error {
|
||||||
|
ExecError::Command { stderr, .. } if !stderr.trim().is_empty() => {
|
||||||
|
let lines: Vec<&str> = stderr.lines().collect();
|
||||||
|
let tail = lines[lines.len().saturating_sub(5)..].join("\n");
|
||||||
|
format!("{error}: {tail}")
|
||||||
}
|
}
|
||||||
Err(e) => {
|
_ => format!("{error}"),
|
||||||
state.status = PrepareStatus::Failed;
|
|
||||||
state.note = format!("{e}");
|
|
||||||
let _ = save_state(exec, root, &state);
|
|
||||||
Err(e)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -172,6 +195,78 @@ mod tests {
|
||||||
assert_eq!(state.status, PrepareStatus::Ready);
|
assert_eq!(state.status, PrepareStatus::Ready);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn failed_prepare_records_stderr_detail() {
|
||||||
|
let runner = RecordingRunner::new();
|
||||||
|
runner.fail("chroot", "!!! emerge failed: unsatisfied dependency");
|
||||||
|
let exec = make_exec(runner);
|
||||||
|
let root = Path::new(&exec.root);
|
||||||
|
let err = prepare(&exec, root, 8, true).unwrap_err();
|
||||||
|
assert!(matches!(err, ExecError::Command { .. }));
|
||||||
|
let state = load_state(root);
|
||||||
|
assert_eq!(state.status, PrepareStatus::Failed);
|
||||||
|
assert!(
|
||||||
|
state.note.contains("unsatisfied dependency"),
|
||||||
|
"note was {}",
|
||||||
|
state.note
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn binary_prebuild_skipped_after_a_successful_fetch_is_ready() {
|
||||||
|
use crate::command::{CommandOutput, ProcessRunner};
|
||||||
|
use std::sync::atomic::{AtomicUsize, Ordering};
|
||||||
|
use std::time::Duration;
|
||||||
|
|
||||||
|
// First emerge (fetch) succeeds; second (buildpkgonly) fails with the
|
||||||
|
// real Portage "dependencies must be merged" condition.
|
||||||
|
struct FetchOkBuildFail {
|
||||||
|
calls: AtomicUsize,
|
||||||
|
}
|
||||||
|
impl ProcessRunner for FetchOkBuildFail {
|
||||||
|
fn execute(&self, _spec: &crate::command::CommandSpec) -> Result<CommandOutput> {
|
||||||
|
let n = self.calls.fetch_add(1, Ordering::SeqCst);
|
||||||
|
if n == 0 {
|
||||||
|
Ok(CommandOutput {
|
||||||
|
status: 0,
|
||||||
|
success: true,
|
||||||
|
stdout: Vec::new(),
|
||||||
|
stderr: Vec::new(),
|
||||||
|
duration: Duration::from_millis(1),
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
Ok(CommandOutput {
|
||||||
|
status: 1,
|
||||||
|
success: false,
|
||||||
|
stdout: Vec::new(),
|
||||||
|
stderr: b"!!! --buildpkgonly requires all dependencies to be merged."
|
||||||
|
.to_vec(),
|
||||||
|
duration: Duration::from_millis(1),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let path = tempfile::tempdir().unwrap().keep();
|
||||||
|
let logger = Logger::open(path.join("l.log"), Redactor::new(), false);
|
||||||
|
let exec = Exec::new(
|
||||||
|
Box::new(FetchOkBuildFail {
|
||||||
|
calls: AtomicUsize::new(0),
|
||||||
|
}),
|
||||||
|
logger,
|
||||||
|
false,
|
||||||
|
path.join("root"),
|
||||||
|
path,
|
||||||
|
);
|
||||||
|
let root = Path::new(&exec.root);
|
||||||
|
let outcome = prepare(&exec, root, 8, true).unwrap();
|
||||||
|
assert!(outcome.started);
|
||||||
|
assert!(outcome.note.contains("binary prebuild skipped"));
|
||||||
|
let state = load_state(root);
|
||||||
|
assert_eq!(state.status, PrepareStatus::Ready);
|
||||||
|
assert!(state.note.contains("dependencies to be merged"));
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn state_roundtrip() {
|
fn state_roundtrip() {
|
||||||
let runner = RecordingRunner::new();
|
let runner = RecordingRunner::new();
|
||||||
|
|
|
||||||
|
|
@ -119,7 +119,8 @@ def do_boot():
|
||||||
r"phoebus login:"], timeout=60) == 0:
|
r"phoebus login:"], timeout=60) == 0:
|
||||||
break
|
break
|
||||||
child.sendline(checks)
|
child.sendline(checks)
|
||||||
child.expect("===CHECKS-END===", timeout=180)
|
checks_timeout = int(os.environ.get("CHECKS_TIMEOUT", "180"))
|
||||||
|
child.expect("===CHECKS-END===", timeout=checks_timeout)
|
||||||
print("checks complete", flush=True)
|
print("checks complete", flush=True)
|
||||||
finally:
|
finally:
|
||||||
child.close(force=True)
|
child.close(force=True)
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue