Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions kt/commands/content_release/impl.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import logging
import os
import re
import time

from git import GitCommandError, Repo

Expand All @@ -10,7 +9,6 @@
from kt.ktlib.local import LocalCommand
from kt.ktlib.mock import Mock
from kt.ktlib.ssh import SshCommand
from kt.ktlib.util import Constants
from kt.ktlib.vm import Vm

# Source download configuration for kernels that don't work with getsrc.sh
Expand Down Expand Up @@ -309,7 +307,7 @@ def test(cls, kernel_workspace: str):

# Wait for dependencies to be installed if VM was just created
logging.info("Waiting for VM dependencies to be installed...")
Comment on lines 308 to 309
time.sleep(Constants.VM_DEPS_INSTALL_WAIT_SECONDS)
SshCommand.run(domain=vm_instance.domain, command=["sudo cloud-init status --wait || true"])

# Install the built RPMs
build_files_dir = kernel_workspace_obj.folder / "build_files"
Expand Down
15 changes: 13 additions & 2 deletions kt/commands/vm/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,20 @@
help="Lists existings vms",
)
@click.option("--test", is_flag=True, help="Build the kernel and run kselftests")
@click.option("--vcpus", type=int, default=12, help="Number of virtual CPUs (default: 12)")
@click.option("--memory", type=int, default=32768, help="Memory in MiB (default: 32768)")
Comment on lines +60 to +61
Comment on lines +60 to +61
@click.argument("kernel_workspace", required=False, shell_complete=ShellCompletion.show_kernel_workspaces)
def vm(kernel_workspace, console, destroy, override, list_all, test):
def vm(kernel_workspace, console, destroy, override, list_all, test, vcpus, memory):
if not list_all and not kernel_workspace:
raise click.UsageError("kernel_workspace is required unless --list-all is specified")

main(name=kernel_workspace, console=console, destroy=destroy, override=override, list_all=list_all, test=test)
main(
name=kernel_workspace,
console=console,
destroy=destroy,
override=override,
list_all=list_all,
test=test,
vcpus=vcpus,
memory=memory,
)
21 changes: 14 additions & 7 deletions kt/commands/vm/impl.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
import logging
import time

from kt.ktlib.config import Config
from kt.ktlib.util import Constants
from kt.ktlib.ssh import SshCommand
from kt.ktlib.virt import VmCommand
from kt.ktlib.vm import Vm


def main(name: str, console: bool, destroy: bool, override: bool, list_all: bool, test: bool = False):
def main(
name: str,
console: bool,
destroy: bool,
override: bool,
list_all: bool,
test: bool = False,
vcpus: int = 12,
memory: int = 32768,
):
if list_all:
VmCommand.list_all()
return
Expand All @@ -21,13 +29,12 @@ def main(name: str, console: bool, destroy: bool, override: bool, list_all: bool
vm.destroy()
return

vm_instance = Vm.setup_and_spinup(kernel_workspace_name=name, override=override)
vm_instance = Vm.setup_and_spinup(kernel_workspace_name=name, override=override, vcpus=vcpus, memory=memory)
config = Config.load()

if test:
# Wait for the dependencies to be installed
logging.info("Waiting for the deps to be installed")
time.sleep(Constants.VM_DEPS_INSTALL_WAIT_SECONDS)
logging.info("Waiting for cloud-init to finish...")
SshCommand.run(domain=vm_instance.domain, command=["sudo cloud-init status --wait || true"])
vm_instance.test(config=config)

if console:
Expand Down
1 change: 0 additions & 1 deletion kt/ktlib/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,5 @@ class Constants:

CLOUD_INIT = "cloud_init.yaml"

VM_DEPS_INSTALL_WAIT_SECONDS = 300
VM_STARTUP_WAIT_SECONDS = 60
VM_REBOOT_WAIT_SECONDS = 120
6 changes: 4 additions & 2 deletions kt/ktlib/virt.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ def install(
vm_major_version: str,
cloud_init_path: Path,
common_dir: Path,
vcpus: int = 12,
memory: int = 32768,
):
command = [
"--name",
Expand All @@ -51,9 +53,9 @@ def install(
"--virt-type",
"kvm",
"--vcpus",
"12,vcpu.cpuset=0-11,vcpu.placement=static",
str(vcpus),
"--memory",
str(32768),
str(memory),
"--vnc",
"--cloud-init",
f"user-data={cloud_init_path}",
Expand Down
18 changes: 11 additions & 7 deletions kt/ktlib/vm.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,15 @@ def load_from_workspace(cls, kernel_workspace_name: str):
return cls.load(config=config, kernel_workspace=kernel_workspace)

@classmethod
def setup_and_spinup(cls, kernel_workspace_name: str, override: bool = False):
def setup_and_spinup(cls, kernel_workspace_name: str, override: bool = False, vcpus: int = 12, memory: int = 32768):
"""
Setup and spin up a VM from a kernel workspace name.

Args:
kernel_workspace_name: The name of the kernel workspace
override: If True, destroy and recreate the VM
vcpus: Number of virtual CPUs
memory: Memory in MiB

Returns:
VmInstance: The running VM instance
Expand All @@ -114,7 +116,7 @@ def setup_and_spinup(cls, kernel_workspace_name: str, override: bool = False):
vm.destroy()

vm.setup(config=config)
vm_instance = vm.spin_up(config=config)
vm_instance = vm.spin_up(config=config, vcpus=vcpus, memory=memory)

return vm_instance

Expand Down Expand Up @@ -168,7 +170,7 @@ def _setup_cloud_init(self, config: Config):
f.write("#cloud-config\n")
yaml.dump(data, f)

def _create_image(self, config: Config):
def _create_image(self, config: Config, vcpus: int = 12, memory: int = 32768):
# Make sure the dir exists
self.qcow2_path.parent.mkdir(parents=True, exist_ok=True)

Expand All @@ -179,16 +181,18 @@ def _create_image(self, config: Config):
# Resize the disk to 30GB
self._resize_disk()

self._virt_install(config=config)
self._virt_install(config=config, vcpus=vcpus, memory=memory)
time.sleep(Constants.VM_STARTUP_WAIT_SECONDS)

def _virt_install(self, config: Config):
def _virt_install(self, config: Config, vcpus: int = 12, memory: int = 32768):
return VmCommand.install(
name=self.name,
qcow2_path=self.qcow2_path,
vm_major_version=self.vm_major_version,
cloud_init_path=self.cloud_init_path,
common_dir=config.base_path,
vcpus=vcpus,
memory=memory,
)

def _resize_disk(self):
Expand All @@ -202,11 +206,11 @@ def _resize_disk(self):
def setup(self, config: Config):
self._download_source_image()

def spin_up(self, config: Config) -> VmInstance:
def spin_up(self, config: Config, vcpus: int = 12, memory: int = 32768) -> VmInstance:
if not VirtHelper.exists(vm_name=self.name):
logging.info(f"VM {self.name} does not exist, creating from scratch...")

self._create_image(config=config)
self._create_image(config=config, vcpus=vcpus, memory=memory)
return VmInstance(name=self.name, kernel_workspace=self.kernel_workspace)
Comment on lines +209 to 214

logging.info(f"Vm {self.name} already exists")
Expand Down
Loading