Skip to content

Commit

Permalink
fixup! providers: setup network kernel arguments in initrd
Browse files Browse the repository at this point in the history
  • Loading branch information
lucab committed Apr 21, 2020
1 parent f78f03a commit c386684
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 7 deletions.
4 changes: 2 additions & 2 deletions dracut/30afterburn/afterburn-network-kargs.service
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ OnFailure=emergency.target
OnFailureJobMode=isolate

[Service]
Environment=AFTERBURN_OPT_DEFAULT_VALUE=--default-value=ip=dhcp,dhcp6
Environment=AFTERBURN_OPT_PROVIDER=--cmdline
ExecStart=/usr/bin/afterburn exp rd-network-kargs ${AFTERBURN_OPT_PROVIDER} ${AFTERBURN_OPT_DEFAULT_VALUE}
# AFTERBURN_NETWORK_KARGS_DEFAULT must be set externally by distributions.
ExecStart=/usr/bin/afterburn exp rd-network-kargs ${AFTERBURN_OPT_PROVIDER} --default-value $AFTERBURN_NETWORK_KARGS_DEFAULT
Type=oneshot
5 changes: 1 addition & 4 deletions src/cli/exp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,12 @@ pub struct CliRdNetworkKargs {
}

impl CliRdNetworkKargs {
/// Hard-coded fallback for default network arguments.
const DEFAULT_NETWORK_KARGS: &'static str = "ip=dhcp,dhcp6";

/// Parse sub-command into configuration.
pub(crate) fn parse(matches: &ArgMatches) -> Result<CliExp> {
let platform = super::parse_provider(matches)?;
let default_kargs = matches
.value_of("default-value")
.unwrap_or_else(|| Self::DEFAULT_NETWORK_KARGS)
.ok_or_else(|| "missing network kargs default value")?
.to_string();

let cfg = Self {
Expand Down
45 changes: 44 additions & 1 deletion src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,9 @@ fn cli_setup<'a, 'b>() -> App<'a, 'b> {
Arg::with_name("default-value")
.long("default-value")
.help("Default value for network kargs fallback")
.takes_value(true),
.required(true)
.takes_value(true)
.empty_values(false),
),
),
)
Expand Down Expand Up @@ -279,4 +281,45 @@ mod tests {
x => panic!("unexpected 'exp' sub-command: {:?}", x),
};
}

#[test]
fn test_missing_default_net_kargs() {
// Missing flag.
let t1: Vec<_> = ["afterburn", "exp", "rd-network-kargs", "--provider", "gcp"]
.iter()
.map(ToString::to_string)
.collect();

// Missing flag value.
let t2: Vec<_> = [
"afterburn",
"exp",
"rd-network-kargs",
"--provider",
"gcp",
"--default-value",
]
.iter()
.map(ToString::to_string)
.collect();

// Empty flag value.
let t3: Vec<_> = [
"afterburn",
"exp",
"rd-network-kargs",
"--provider",
"gcp",
"--default-value",
"",
]
.iter()
.map(ToString::to_string)
.collect();

for args in vec![t1, t2, t3] {
let input = format!("{:?}", args);
parse_args(args).expect_err(&input);
}
}
}

0 comments on commit c386684

Please sign in to comment.