1
0
mirror of https://github.com/containers/bootc.git synced 2026-02-05 15:45:53 +01:00

Consistently accept components as non-option args

We were inconsistent.
This commit is contained in:
Colin Walters
2020-06-24 22:18:32 +00:00
parent a4c46bacb7
commit cfb673ab32
2 changed files with 19 additions and 22 deletions

View File

@@ -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<Vec<String>>,
components: Vec<String>,
// Output JSON
#[structopt(long)]
@@ -277,7 +276,7 @@ fn update_state(sysroot_dir: &openat::Dir, state: &SavedState) -> Result<()> {
Ok(())
}
fn adopt() -> Result<String> {
fn adopt(opts: &AdoptOptions) -> Result<String> {
let mut r = String::new();
let sysroot_path = "/";
let _lockf = acquire_write_lock(sysroot_path)?;
@@ -286,7 +285,13 @@ fn adopt() -> Result<String> {
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<String> {
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<HashSet<ComponentType>, _> = 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");

View File

@@ -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