From cfb673ab327d1d62f842edca1588f932cd747dfd Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Wed, 24 Jun 2020 22:18:32 +0000 Subject: [PATCH] Consistently accept components as non-option args We were inconsistent. --- src/bootupd.rs | 25 +++++++++++-------------- tests/kola/test-bootupd | 16 ++++++++-------- 2 files changed, 19 insertions(+), 22 deletions(-) diff --git a/src/bootupd.rs b/src/bootupd.rs index 20025a89..54eb246f 100644 --- a/src/bootupd.rs +++ b/src/bootupd.rs @@ -10,7 +10,7 @@ use gio::NONE_CANCELLABLE; use nix::sys::socket as nixsocket; use openat_ext::OpenatDirExt; use serde_derive::{Deserialize, Serialize}; -use std::collections::{BTreeMap, BTreeSet, HashSet}; +use std::collections::{BTreeMap, BTreeSet}; use std::fmt::Write as WriteFmt; use std::io::prelude::*; use std::os::unix::io::RawFd; @@ -58,8 +58,7 @@ struct UpdateOptions { #[derive(Debug, Serialize, Deserialize, StructOpt)] #[structopt(rename_all = "kebab-case")] struct StatusOptions { - #[structopt(long = "component")] - components: Option>, + components: Vec, // Output JSON #[structopt(long)] @@ -277,7 +276,7 @@ fn update_state(sysroot_dir: &openat::Dir, state: &SavedState) -> Result<()> { Ok(()) } -fn adopt() -> Result { +fn adopt(opts: &AdoptOptions) -> Result { let mut r = String::new(); let sysroot_path = "/"; let _lockf = acquire_write_lock(sysroot_path)?; @@ -286,7 +285,13 @@ fn adopt() -> Result { let mut saved_state = saved_state.unwrap_or_else(|| SavedState { components: BTreeMap::new(), }); + let specified_components = parse_componentlist(&opts.components)?; for (ctype, component) in status.components.iter() { + if let Some(specified_components) = specified_components.as_ref() { + if !specified_components.contains(ctype) { + continue; + } + } let installed = match &component.installed { ComponentState::NotInstalled => continue, ComponentState::NotImplemented => continue, @@ -561,15 +566,7 @@ fn status(opts: &StatusOptions) -> Result { Ok("This architecture is not supported.".to_string()) } else { let mut r = String::new(); - let specified_components = if let Some(components) = &opts.components { - let r: std::result::Result, _> = components - .iter() - .map(|c| serde_plain::from_str(c)) - .collect(); - Some(r?) - } else { - None - }; + let specified_components = parse_componentlist(&opts.components)?; for (ctype, component) in status.components.iter() { if let Some(specified_components) = specified_components.as_ref() { if !specified_components.contains(ctype) { @@ -664,7 +661,7 @@ fn daemon_process_one(client: &mut AuthenticatedClient) -> Result<()> { let r = match opt { Opt::Adopt(ref opts) => { println!("Processing adopt"); - adopt() + adopt(opts) } Opt::Update(ref opts) => { println!("Processing update"); diff --git a/tests/kola/test-bootupd b/tests/kola/test-bootupd index fcadef6b..6788d334 100755 --- a/tests/kola/test-bootupd +++ b/tests/kola/test-bootupd @@ -40,7 +40,7 @@ assert_file_has_content_literal out.txt 'ActiveState=inactive' systemctl start bootupd.socket -bootupd status --component=EFI > out.txt +bootupd status EFI > out.txt assert_file_has_content_literal out.txt 'Component EFI' assert_file_has_content_literal out.txt ' Unmanaged: digest=' assert_not_file_has_content_literal out.txt 'Update: Available:' @@ -62,37 +62,37 @@ ok 'rerunning adopt is idempotent' cp --reflink=auto ${efidir}/${shim} shimx64.backup echo 'oops state drift' >> ${efidir}/shimx64.efi -bootupd status --component=EFI | tee out.txt +bootupd status EFI | tee out.txt assert_file_has_content_literal out.txt 'warning: drift detected' assert_file_has_content_literal out.txt 'Recorded: ' assert_file_has_content_literal out.txt 'Actual: sha512:' mv shimx64.backup ${efidir}/shimx64.efi -bootupd status --component=EFI | tee out.txt +bootupd status EFI | tee out.txt assert_not_file_has_content_literal out.txt 'warning: drift detected' ok 'drift detected' # TODO do better tests that rpm-ostree usroverlay -bootupd status --component=EFI | tee out.txt +bootupd status EFI | tee out.txt assert_not_file_has_content_literal out.txt 'Update: Available' cp --reflink=auto ${ostefi}/${shim} shimx64.efi.backup echo 'updated shimx64.efi' > ${ostefi}/${shim} -bootupd status --component=EFI | tee out.txt +bootupd status EFI | tee out.txt assert_file_has_content_literal out.txt 'Update: Available' cp --reflink=auto shimx64.efi.backup ${ostefi}/${shim} -bootupd status --component=EFI | tee out.txt +bootupd status EFI | tee out.txt assert_not_file_has_content_literal out.txt 'Update: Available' ok 'update available' -bootupd status --component=EFI | tee out.txt +bootupd status EFI | tee out.txt assert_not_file_has_content_literal out.txt 'Update: Available' cp --reflink=auto ${ostefi}/${shim} shimx64.efi.backup echo 'updated shimx64.efi' > ${ostefi}/${shim} bootupd update EFI | tee out.txt assert_file_has_content_literal out.txt 'EFI: Updated to digest=' assert_not_file_has_content_literal out.txt 'EFI: no updates available' -bootupd status --component=EFI | tee out.txt +bootupd status EFI | tee out.txt assert_not_file_has_content_literal out.txt 'warning: drift detected' assert_not_file_has_content_literal out.txt 'Update: Available' if ! test -f "${efidir}/grub.cfg"; then