Skip to content

Commit f98e028

Browse files
committed
Add memory option to test framework VM config
1 parent f84d977 commit f98e028

File tree

3 files changed

+40
-4
lines changed

3 files changed

+40
-4
lines changed

test/test-manager/src/config/vm.rs

+5
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,11 @@ pub struct VmConfig {
6565
#[serde(default)]
6666
#[arg(long)]
6767
pub vcpus: Option<usize>,
68+
69+
/// Amount of memory, in MBs
70+
#[serde(default)]
71+
#[arg(long)]
72+
pub memory: Option<usize>,
6873
}
6974

7075
impl VmConfig {

test/test-manager/src/vm/qemu.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ const OBTAIN_IP_TIMEOUT: Duration = Duration::from_secs(180);
2828
/// Default number of VCPU cores (passed to -smp)
2929
const DEFAULT_NUM_VCPUS: usize = 2;
3030

31+
/// Default amount of memory, in MBs (passed to -m)
32+
const DEFAULT_AMOUNT_MEMORY: usize = 2048;
33+
3134
#[derive(thiserror::Error, Debug)]
3235
pub enum Error {
3336
#[error("Failed to set up network")]
@@ -87,13 +90,18 @@ pub async fn run(config: &Config, vm_config: &VmConfig) -> Result<QemuInstance>
8790

8891
let mut qemu_cmd = Command::new("qemu-system-x86_64");
8992
let vcpus = vm_config.vcpus.unwrap_or(DEFAULT_NUM_VCPUS);
93+
let memory = vm_config.memory.unwrap_or(DEFAULT_AMOUNT_MEMORY);
94+
95+
log::debug!("CPU count: {vcpus}");
96+
log::debug!("Memory: {memory}M");
97+
9098
qemu_cmd.args([
9199
"-cpu",
92100
"host",
93101
"-accel",
94102
"kvm",
95103
"-m",
96-
"4096",
104+
&memory.to_string(),
97105
"-smp",
98106
&vcpus.to_string(),
99107
"-drive",

test/test-manager/src/vm/tart.rs

+26-3
Original file line numberDiff line numberDiff line change
@@ -49,16 +49,17 @@ pub async fn run(config: &Config, vm_config: &VmConfig) -> Result<TartInstance>
4949
MachineCopy::clone_vm(&vm_config.image_path).await?
5050
};
5151

52+
if let Err(err) = machine_copy.configure(vm_config).await {
53+
log::error!("Failed to configure tart vm: {err}");
54+
}
55+
5256
// Start VM
5357
let mut tart_cmd = Command::new("tart");
5458
tart_cmd.args(["run", &machine_copy.name, "--serial"]);
5559

5660
if !vm_config.disks.is_empty() {
5761
log::warn!("Mounting disks is not yet supported")
5862
}
59-
if let Some(cpu) = vm_config.vcpus {
60-
tart_cmd.args(["--cpu", &cpu.to_string()]);
61-
}
6263

6364
match config.runtime_opts.display {
6465
config::Display::None => {
@@ -170,6 +171,28 @@ impl MachineCopy {
170171
})
171172
}
172173

174+
pub async fn configure(&self, vm_config: &VmConfig) -> Result<()> {
175+
let mut args = vec![];
176+
if let Some(cpu) = vm_config.vcpus {
177+
args.extend(["--cpu".to_owned(), cpu.to_string()]);
178+
log::info!("vCPUs: {cpu}");
179+
}
180+
if let Some(mem) = vm_config.memory {
181+
args.extend(["--memory".to_owned(), mem.to_string()]);
182+
log::info!("Memory: {mem} MB");
183+
}
184+
if !args.is_empty() {
185+
let mut tart_cmd = Command::new("tart");
186+
tart_cmd.args(["set", &self.name]);
187+
tart_cmd.args(args);
188+
tart_cmd
189+
.status()
190+
.await
191+
.context("failed to update tart config")?;
192+
}
193+
Ok(())
194+
}
195+
173196
pub async fn cleanup(mut self) {
174197
let _ = tokio::task::spawn_blocking(move || self.try_destroy()).await;
175198
}

0 commit comments

Comments
 (0)