diff options
| author | Sebastian Holmin <sebastian.holmin@mullvad.net> | 2024-07-22 15:45:27 +0200 |
|---|---|---|
| committer | Markus Pettersson <markus.pettersson@mullvad.net> | 2024-08-09 09:43:58 +0200 |
| commit | eb6cdfa95cf55b62a5908e5fcdffdb2fa136559b (patch) | |
| tree | 16d34a7eab97a8f97d519897354560a3b1523357 /test | |
| parent | 7cff069918f4c412f11f45e098fdf2e22c3ea71b (diff) | |
| download | mullvadvpn-eb6cdfa95cf55b62a5908e5fcdffdb2fa136559b.tar.xz mullvadvpn-eb6cdfa95cf55b62a5908e5fcdffdb2fa136559b.zip | |
Change VM config from positional arg to flag
Diffstat (limited to 'test')
| -rwxr-xr-x | test/ci-runtests.sh | 2 | ||||
| -rw-r--r-- | test/test-manager/src/main.rs | 61 | ||||
| -rw-r--r-- | test/test-manager/src/summary.rs | 6 |
3 files changed, 32 insertions, 37 deletions
diff --git a/test/ci-runtests.sh b/test/ci-runtests.sh index e6b7ba7b18..0346044e7b 100755 --- a/test/ci-runtests.sh +++ b/test/ci-runtests.sh @@ -201,7 +201,7 @@ function run_tests_for_os { --app-package-to-upgrade-from "${prev_filename}" \ --package-folder "$PACKAGES_DIR" \ --test-report "$SCRIPT_DIR/.ci-logs/${os}_report" \ - "$os" 2>&1 | sed "s/${ACCOUNT_TOKEN}/\{ACCOUNT_TOKEN\}/g" + --vm "$os" 2>&1 | sed "s/${ACCOUNT_TOKEN}/\{ACCOUNT_TOKEN\}/g" } echo "**********************************" diff --git a/test/test-manager/src/main.rs b/test/test-manager/src/main.rs index 79d239f4d0..a679745e83 100644 --- a/test/test-manager/src/main.rs +++ b/test/test-manager/src/main.rs @@ -28,27 +28,27 @@ struct Args { enum Commands { /// Create or edit a VM config Set { - /// Name of the config - name: String, + /// Name of the VM config + vm: String, /// VM config #[clap(flatten)] config: config::VmConfig, }, - /// Remove specified configuration + /// Remove specified VM config Remove { - /// Name of the config - name: String, + /// Name of the VM config, run `test-manager list` to see available configs + vm: String, }, - /// List available configurations + /// List available VM configurations List, /// Spawn a runner instance without running any tests RunVm { - /// Name of the runner config - name: String, + /// Name of the VM config, run `test-manager list` to see available configs + vm: String, /// Run VNC server on a specified port #[arg(long)] @@ -64,8 +64,9 @@ enum Commands { /// Spawn a runner instance and run tests RunTests { - /// Name of the runner config - name: String, + /// Name of the VM config, run `test-manager list` to see available configs + #[arg(long)] + vm: String, /// Show display of guest #[arg(long, group = "display_args")] @@ -110,8 +111,8 @@ enum Commands { #[arg(long, short)] verbose: bool, - /// Output test results in a structured format. - #[arg(long)] + /// Path to output test results in a structured format + #[arg(long, value_name = "PATH")] test_report: Option<PathBuf>, }, @@ -127,7 +128,7 @@ enum Commands { /// to have `provisioner` set to `ssh`, `ssh_user` & `ssh_password` set and /// the `ssh_user` should be able to execute commands with sudo/ as root. Update { - /// Name of the runner config + /// Name of the VM config name: String, }, } @@ -156,34 +157,34 @@ async fn main() -> Result<()> { .context("Failed to load config")?; match args.cmd { Commands::Set { - name, + vm, config: vm_config, - } => vm::set_config(&mut config, &name, vm_config) + } => vm::set_config(&mut config, &vm, vm_config) .await .context("Failed to edit or create VM config"), - Commands::Remove { name } => { - if config.get_vm(&name).is_none() { + Commands::Remove { vm } => { + if config.get_vm(&vm).is_none() { println!("No such configuration"); return Ok(()); } config .edit(|config| { - config.vms.remove_entry(&name); + config.vms.remove_entry(&vm); }) .await .context("Failed to remove config entry")?; - println!("Removed configuration \"{name}\""); + println!("Removed configuration \"{vm}\""); Ok(()) } Commands::List => { println!("Available configurations:"); - for name in config.vms.keys() { - println!("{}", name); + for (vm, config) in config.vms.iter() { + println!("{vm}: {config:#?}"); } Ok(()) } Commands::RunVm { - name, + vm, vnc, keep_changes, } => { @@ -195,9 +196,7 @@ async fn main() -> Result<()> { config::Display::Local }; - let mut instance = vm::run(&config, &name) - .await - .context("Failed to start VM")?; + let mut instance = vm::run(&config, &vm).await.context("Failed to start VM")?; instance.wait().await; @@ -215,7 +214,7 @@ async fn main() -> Result<()> { Ok(()) } Commands::RunTests { - name, + vm, display, vnc, account, @@ -240,12 +239,12 @@ async fn main() -> Result<()> { .unwrap_or(DEFAULT_MULLVAD_HOST.to_owned()); log::debug!("Mullvad host: {mullvad_host}"); - let vm_config = vm::get_vm_config(&config, &name).context("Cannot get VM config")?; + let vm_config = vm::get_vm_config(&config, &vm).context("Cannot get VM config")?; let summary_logger = match test_report { Some(path) => Some( summary::SummaryLogger::new( - &name, + &vm, test_rpc::meta::Os::from(vm_config.os_type), &path, ) @@ -263,10 +262,8 @@ async fn main() -> Result<()> { ) .context("Could not find the specified app packages")?; - let mut instance = vm::run(&config, &name) - .await - .context("Failed to start VM")?; - let artifacts_dir = vm::provision(&config, &name, &*instance, &manifest) + let mut instance = vm::run(&config, &vm).await.context("Failed to start VM")?; + let artifacts_dir = vm::provision(&config, &vm, &*instance, &manifest) .await .context("Failed to run provisioning for VM")?; diff --git a/test/test-manager/src/summary.rs b/test/test-manager/src/summary.rs index 30b71948cf..9706e351a1 100644 --- a/test/test-manager/src/summary.rs +++ b/test/test-manager/src/summary.rs @@ -68,7 +68,7 @@ pub struct SummaryLogger { impl SummaryLogger { /// Create a new logger and log to `path`. If `path` does not exist, it will be created. If it /// already exists, it is truncated and overwritten. - pub async fn new(name: &str, os: Os, path: &Path) -> Result<SummaryLogger, Error> { + pub async fn new(vm: &str, os: Os, path: &Path) -> Result<SummaryLogger, Error> { let mut file = fs::OpenOptions::new() .create(true) .write(true) @@ -77,9 +77,7 @@ impl SummaryLogger { .await .map_err(|err| Error::Open(err, path.to_path_buf()))?; - file.write_all(name.as_bytes()) - .await - .map_err(Error::Write)?; + file.write_all(vm.as_bytes()).await.map_err(Error::Write)?; file.write_u8(b'\n').await.map_err(Error::Write)?; file.write_all(&serde_json::to_vec(&os).map_err(Error::Serialize)?) .await |
