Skip to content

Commit

Permalink
Add without-netconfig argument
Browse files Browse the repository at this point in the history
  • Loading branch information
jcronenberg committed Aug 12, 2024
1 parent 395b064 commit d6f6517
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 9 deletions.
1 change: 1 addition & 0 deletions rust/migrate-wicked/src/infiniband.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ mod tests {
continue_migration: false,
dry_run: false,
activate_connections: true,
without_netconfig: true,
netconfig_path: "".to_string(),
});
}
Expand Down
7 changes: 7 additions & 0 deletions rust/migrate-wicked/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ struct GlobalOpts {
#[arg(long, global = true, default_value_t = LevelFilter::Warn, value_parser = clap::builder::PossibleValuesParser::new(["TRACE", "DEBUG", "INFO", "WARN", "ERROR"]).map(|s| s.parse::<LevelFilter>().unwrap()),)]
pub log_level: LevelFilter,

#[arg(long, global = true, env = "MIGRATE_WICKED_WITHOUT_NETCONFIG")]
pub without_netconfig: bool,

#[arg(long, global = true, default_value_t = String::from("/etc/sysconfig/network/config"), env = "MIGRATE_WICKED_NETCONFIG_PATH")]
pub netconfig_path: String,
}
Expand Down Expand Up @@ -88,6 +91,7 @@ async fn run_command(cli: Cli) -> anyhow::Result<()> {
continue_migration: true,
dry_run: false,
activate_connections: true,
without_netconfig: cli.global_opts.without_netconfig,
netconfig_path: cli.global_opts.netconfig_path,
})
.expect("MIGRATION_SETTINGS was set too early");
Expand Down Expand Up @@ -125,6 +129,7 @@ async fn run_command(cli: Cli) -> anyhow::Result<()> {
continue_migration,
dry_run,
activate_connections,
without_netconfig: cli.global_opts.without_netconfig,
netconfig_path: cli.global_opts.netconfig_path,
})
.expect("MIGRATION_SETTINGS was set too early");
Expand Down Expand Up @@ -161,6 +166,7 @@ struct MigrationSettings {
continue_migration: bool,
dry_run: bool,
activate_connections: bool,
without_netconfig: bool,
netconfig_path: String,
}

Expand All @@ -170,6 +176,7 @@ impl Default for MigrationSettings {
continue_migration: false,
dry_run: false,
activate_connections: true,
without_netconfig: false,
netconfig_path: "".to_string(),
}
}
Expand Down
20 changes: 11 additions & 9 deletions rust/migrate-wicked/src/reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,15 +84,17 @@ pub fn read(paths: Vec<String>) -> Result<InterfacesResult, anyhow::Error> {
warning: None,
};

match read_netconfig(settings.netconfig_path.clone()) {
Ok(netconfig) => result.netconfig = netconfig,
Err(e) => {
if !settings.continue_migration {
return Err(e);
};
log::warn!("Failed to read netconfig: {}", e);
}
};
if !settings.without_netconfig {
match read_netconfig(settings.netconfig_path.clone()) {
Ok(netconfig) => result.netconfig = netconfig,
Err(e) => {
if !settings.continue_migration {
return Err(e);
};
log::warn!("Failed to read netconfig: {}", e);
}
};
}

for path in paths {
let path: PathBuf = path.into();
Expand Down
1 change: 1 addition & 0 deletions rust/migrate-wicked/src/wireless.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ mod tests {
continue_migration: false,
dry_run: false,
activate_connections: true,
without_netconfig: true,
netconfig_path: "".to_string(),
});
}
Expand Down
3 changes: 3 additions & 0 deletions rust/migrate-wicked/tests/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ for test_dir in ${TEST_DIRS}; do
if [ -d $test_dir/netconfig ]; then
migrate_args+=" --netconfig-path $test_dir/netconfig/config"
show_args+=" --netconfig-path $test_dir/netconfig/config"
else
migrate_args+=" --without-netconfig"
show_args+=" --without-netconfig"
fi

$MIGRATE_WICKED_BIN show $show_args $test_dir/wicked_xml
Expand Down

0 comments on commit d6f6517

Please sign in to comment.