summaryrefslogtreecommitdiffhomepage
path: root/test/test-manager/src/main.rs
diff options
context:
space:
mode:
authorSebastian Holmin <sebastian.holmin@mullvad.net>2025-01-22 13:33:03 +0100
committerSebastian Holmin <sebastian.holmin@mullvad.net>2025-01-22 13:33:03 +0100
commitbbfc9c858bd58cf8a8768e7229b40ee44aa898bd (patch)
tree66ffb72550e367f13fe4b68881937627d79a390f /test/test-manager/src/main.rs
parent598727746cd679b6d1aa327f6a5ac0506693bda8 (diff)
parentb198ecd495f75117c482eea2f9d8cd738ad14441 (diff)
downloadmullvadvpn-bbfc9c858bd58cf8a8768e7229b40ee44aa898bd.tar.xz
mullvadvpn-bbfc9c858bd58cf8a8768e7229b40ee44aa898bd.zip
Merge branch 'be-able-to-whitelist-relays-in-an-end-to-end-test-run-des-1052'
Diffstat (limited to 'test/test-manager/src/main.rs')
-rw-r--r--test/test-manager/src/main.rs141
1 files changed, 93 insertions, 48 deletions
diff --git a/test/test-manager/src/main.rs b/test/test-manager/src/main.rs
index 95274e9a7a..694af65dc3 100644
--- a/test/test-manager/src/main.rs
+++ b/test/test-manager/src/main.rs
@@ -13,8 +13,9 @@ mod vm;
use std::net::IpAddr;
use std::{net::SocketAddr, path::PathBuf};
-use anyhow::{Context, Result};
+use anyhow::{Context, Ok, Result};
use clap::{builder::PossibleValuesParser, Parser};
+use config::ConfigFile;
use package::TargetInfo;
use tests::{config::TEST_CONFIG, get_filtered_tests};
use vm::provision;
@@ -31,28 +32,13 @@ struct Args {
#[derive(clap::Subcommand, Debug)]
enum Commands {
- /// Create or edit a VM config
- Set {
- /// Name of the VM config
- vm: String,
-
- /// VM config
- #[clap(flatten)]
- config: config::VmConfig,
- },
-
- /// Remove specified VM config
- Remove {
- /// Name of the VM config, run `test-manager list` to see available configs
- vm: String,
- },
-
- /// List available VM configurations
- List,
+ /// Manage configuration for tests and VMs
+ #[clap(subcommand)]
+ Config(ConfigArg),
/// Spawn a runner instance without running any tests
RunVm {
- /// Name of the VM config, run `test-manager list` to see available configs
+ /// Name of the VM config, run `test-manager config vm list` to see configured VMs
vm: String,
/// Run VNC server on a specified port
@@ -69,7 +55,7 @@ enum Commands {
/// Spawn a runner instance and run tests
RunTests {
- /// Name of the VM config, run `test-manager list` to see available configs
+ /// Name of the VM config, run `test-manager config vm list` to see configured VMs
#[arg(long)]
vm: String,
@@ -161,6 +147,39 @@ enum Commands {
},
}
+#[derive(clap::Subcommand, Debug)]
+enum ConfigArg {
+ /// Print the current config
+ Get,
+ /// Print the path to the current config file
+ Which,
+ /// Manage VM-specific setting
+ #[clap(subcommand)]
+ Vm(VmConfig),
+}
+
+#[derive(clap::Subcommand, Debug)]
+enum VmConfig {
+ /// Create or edit a VM config
+ Set {
+ /// Name of the VM config
+ vm: String,
+
+ /// VM config
+ #[clap(flatten)]
+ config: config::VmConfig,
+ },
+
+ /// Remove specified VM config
+ Remove {
+ /// Name of the VM config, run `test-manager config vm list` to see configured VMs
+ vm: String,
+ },
+
+ /// List available VM configurations
+ List,
+}
+
#[cfg(target_os = "linux")]
impl Args {
fn get_vnc_port(&self) -> Option<u16> {
@@ -184,33 +203,50 @@ async fn main() -> Result<()> {
.await
.context("Failed to load config")?;
match args.cmd {
- Commands::Set {
- vm,
- config: vm_config,
- } => vm::set_config(&mut config, &vm, vm_config)
- .await
- .context("Failed to edit or create VM config"),
- Commands::Remove { vm } => {
- if config.get_vm(&vm).is_none() {
- println!("No such configuration");
- return Ok(());
+ Commands::Config(config_subcommand) => match config_subcommand {
+ ConfigArg::Get => {
+ println!("{:#?}", *config);
+ Ok(())
}
- config
- .edit(|config| {
- config.vms.remove_entry(&vm);
- })
- .await
- .context("Failed to remove config entry")?;
- println!("Removed configuration \"{vm}\"");
- Ok(())
- }
- Commands::List => {
- println!("Available configurations:");
- for (vm, config) in config.vms.iter() {
- println!("{vm}: {config:#?}");
+ ConfigArg::Which => {
+ println!(
+ "{}",
+ ConfigFile::get_config_path()
+ .expect("Get config path")
+ .display()
+ );
+ Ok(())
}
- Ok(())
- }
+ ConfigArg::Vm(vm_config) => match vm_config {
+ VmConfig::Set {
+ vm,
+ config: vm_config,
+ } => vm::set_config(&mut config, &vm, vm_config)
+ .await
+ .context("Failed to edit or create VM config"),
+ VmConfig::Remove { vm } => {
+ if config.get_vm(&vm).is_none() {
+ println!("No such configuration");
+ return Ok(());
+ }
+ config
+ .edit(|config| {
+ config.vms.remove_entry(&vm);
+ })
+ .await
+ .context("Failed to remove config entry")?;
+ println!("Removed configuration \"{vm}\"");
+ Ok(())
+ }
+ VmConfig::List => {
+ println!("Configured VMs:");
+ for vm in config.vms.keys() {
+ println!("{vm}");
+ }
+ Ok(())
+ }
+ },
+ },
Commands::RunVm {
vm,
vnc,
@@ -266,7 +302,12 @@ async fn main() -> Result<()> {
};
if let Some(mullvad_host) = mullvad_host {
- log::trace!("Setting Mullvad host using --mullvad-host flag");
+ match config.mullvad_host {
+ Some(old_host) => {
+ log::info!("Overriding Mullvad host from {old_host} to {mullvad_host}",)
+ }
+ None => log::info!("Setting Mullvad host to {mullvad_host}",),
+ };
config.mullvad_host = Some(mullvad_host);
}
let mullvad_host = config.get_host();
@@ -327,7 +368,11 @@ async fn main() -> Result<()> {
test_rpc::meta::Os::from(vm_config.os_type),
openvpn_certificate,
));
- let tests = get_filtered_tests(&test_filters)?;
+
+ let mut tests = get_filtered_tests(&test_filters)?;
+ for test in tests.iter_mut() {
+ test.location = config.test_locations.lookup(test.name).cloned();
+ }
// For convenience, spawn a SOCKS5 server that is reachable for tests that need it
let socks = socks_server::spawn(SocketAddr::new(