use crate::test::*;
-const ORIGREF: &'static str = "orig-booted";
-const TESTREF: &'static str = "testcontent";
-const TDATAPATH: &'static str = "/var/tmp/ostree-test-transaction-data.json";
-const SRVREPO: &'static str = "/var/tmp/ostree-test-srv";
+const ORIGREF: &str = "orig-booted";
+const TESTREF: &str = "testcontent";
+const TDATAPATH: &str = "/var/tmp/ostree-test-transaction-data.json";
+const SRVREPO: &str = "/var/tmp/ostree-test-srv";
// Percentage of ELF files to change per update
const TREEGEN_PERCENTAGE: u32 = 15;
/// Total number of reboots
InterruptStrategy::Polite(t) => self
.polite
.entry(t.clone())
- .or_insert_with(|| BTreeMap::new()),
+ .or_insert_with(BTreeMap::new),
InterruptStrategy::Force(t) => self
.force
.entry(t.clone())
- .or_insert_with(|| BTreeMap::new()),
+ .or_insert_with(BTreeMap::new),
}
}
}
impl InterruptStrategy {
pub(crate) fn is_noop(&self) -> bool {
- match self {
- InterruptStrategy::Polite(PoliteInterruptStrategy::None) => true,
- _ => false,
- }
+ matches!(self, InterruptStrategy::Polite(PoliteInterruptStrategy::None))
}
}
assert!(!firstdeploy.booted);
validate_pending_commit(pending_commit, &commitstates)?;
UpdateResult::Staged
+ } else if pending_commit == commitstates.booted {
+ UpdateResult::NotCompleted
+ } else if pending_commit == commitstates.target {
+ UpdateResult::Completed
} else {
- if pending_commit == commitstates.booted {
- UpdateResult::NotCompleted
- } else if pending_commit == commitstates.target {
- UpdateResult::Completed
- } else {
- anyhow::bail!(
- "Unexpected pending commit: {} ({:?})",
- pending_commit,
- commitstates.describe(pending_commit)
- );
- }
+ anyhow::bail!(
+ "Unexpected pending commit: {} ({:?})",
+ pending_commit,
+ commitstates.describe(pending_commit)
+ );
};
Ok(res)
}
live_strategy = Some(strategy);
}
InterruptStrategy::Force(ForceInterruptStrategy::Reboot) => {
- mark.reboot_strategy = Some(strategy.clone());
+ mark.reboot_strategy = Some(strategy);
prepare_reboot(serde_json::to_string(&mark)?)?;
// This is a forced reboot - no syncing of the filesystem.
bash!("reboot -ff")?;
anyhow::bail!("Failed to wait for uninterrupted upgrade");
}
InterruptStrategy::Polite(PoliteInterruptStrategy::Reboot) => {
- mark.reboot_strategy = Some(strategy.clone());
- Err(reboot(serde_json::to_string(&mark)?))?;
+ mark.reboot_strategy = Some(strategy);
+ return Err(reboot(serde_json::to_string(&mark)?).into());
// We either rebooted, or failed to reboot
}
InterruptStrategy::Polite(PoliteInterruptStrategy::Stop) => {
// We need this static across reboots
let srvrepo = Path::new(SRVREPO);
let firstrun = !srvrepo.exists();
- if let Some(_) = mark.as_ref() {
+ if mark.as_ref().is_some() {
if firstrun {
anyhow::bail!("Missing {:?}", srvrepo);
}
let end = time::Instant::now();
let cycle_time = end.duration_since(start);
let tdata = TransactionalTestInfo {
- cycle_time: cycle_time,
+ cycle_time,
};
let mut f = std::io::BufWriter::new(std::fs::File::create(&TDATAPATH)?);
serde_json::to_writer(&mut f, &tdata)?;
mod treegen;
// Written by Ignition
-const DESTRUCTIVE_TEST_STAMP: &'static str = "/etc/ostree-destructive-test-ok";
+const DESTRUCTIVE_TEST_STAMP: &str = "/etc/ostree-destructive-test-ok";
#[derive(Debug, StructOpt)]
#[structopt(rename_all = "kebab-case")]
+#[allow(clippy::enum_variant_names)]
/// Main options struct
enum Opt {
/// List the destructive tests
for t in test::DESTRUCTIVE_TESTS.iter() {
println!("{}", t.name);
}
- return Ok(());
+ Ok(())
}
Opt::NonDestructive(subopt) => {
// FIXME add method to parse subargs
- let iter = match subopt {
- NonDestructiveOpts::Args(subargs) => subargs,
- };
+ let NonDestructiveOpts::Args(iter) = subopt;
let libtestargs = libtest_mimic::Arguments::from_iter(iter);
let tests: Vec<_> = test::NONDESTRUCTIVE_TESTS
.iter()
if o.status.success() {
bail!("Command {:?} unexpectedly succeeded", c);
}
- if !twoway::find_bytes(&o.stderr, pat.as_bytes()).is_some() {
+ if twoway::find_bytes(&o.stderr, pat.as_bytes()).is_none() {
dbg!(String::from_utf8_lossy(&o.stdout));
dbg!(String::from_utf8_lossy(&o.stderr));
bail!("Command {:?} stderr did not match: {}", c, pat);
if !o.status.success() {
bail!("Command {:?} failed", c);
}
- if !twoway::find_bytes(&o.stdout, pat.as_bytes()).is_some() {
+ if twoway::find_bytes(&o.stdout, pat.as_bytes()).is_none() {
dbg!(String::from_utf8_lossy(&o.stdout));
bail!("Command {:?} stdout did not match: {}", c, pat);
}
pub(crate) random_delay: Option<time::Duration>,
}
-pub(crate) const TEST_HTTP_BASIC_AUTH: &'static str = "foouser:barpw";
+pub(crate) const TEST_HTTP_BASIC_AUTH: &str = "foouser:barpw";
fn validate_authz(value: &[u8]) -> Result<bool> {
let buf = std::str::from_utf8(&value)?;
if let Some(o) = buf.find("Basic ") {
- let (_, buf) = buf.split_at(o + "Basic ".len());
+ let (_, buf) = buf.split_at(o + "Basic ".len());
let buf = base64::decode(buf).context("decoding")?;
let buf = std::str::from_utf8(&buf)?;
Ok(buf == TEST_HTTP_BASIC_AUTH)
let make_service = make_service_fn(move |_| {
let sv = sv.clone();
- let opts = opts.clone();
future::ok::<_, hyper::Error>(service_fn(move |req| handle_request(req, sv.clone(), opts)))
});
let server: hyper::Server<_, _, _> = hyper::Server::bind(&addr).serve(make_service);
let path = path.as_ref();
let mut rt = Runtime::new()?;
rt.block_on(async move {
- let addr = http_server(path, opts.clone()).await?;
+ let addr = http_server(path, *opts).await?;
tokio::task::spawn_blocking(move || f(&addr)).await?
})?;
Ok(())