Skip to content
Draft
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
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
files: "(console_conf|subiquity|subiquitycore|doc)"
files: "(console_conf|subiquity|subiquitycore|vmtest|doc)"
repos:
- repo: https://github.com/psf/black
rev: 25.1.0
hooks:
- id: black
files: "(console_conf|subiquity|subiquitycore)"
files: "(console_conf|subiquity|subiquitycore|vmtest)"
- repo: https://github.com/pycqa/isort
rev: 6.0.1
hooks:
- id: isort
name: isort
files: "(console_conf|subiquity|subiquitycore)"
files: "(console_conf|subiquity|subiquitycore|vmtest)"
- repo: local
hooks:
- id: doc-spelling
Expand Down
30 changes: 30 additions & 0 deletions vmtests/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@

# vmtests

vmtests for subiquity work by way of virt-install and autoinstall. SSH is
setup with a passwordless authentication key so that, both at install time and
first boot, the system under test can be automated and analyzed.

new vmtests look something like this. See the VMM and VM classes in
`vmtests/tests/conftest.py` for more details and API.

```
def test_bios_direct(vmm):
test_config = """
autoinstall:
storage:
layout:
name: direct
"""

sut = vmm.install(
firmware=Firmware.BIOS,
disk_sizes_GiB=[10],
test_config=test_config,
)

[vda] = sut.lsblk()["blockdevices"]
[vda1, vda2] = vda["children"]
assert vda1["size"] == MiB
assert vda2["size"] == 10 * GiB - 3 * MiB
```
33 changes: 33 additions & 0 deletions vmtests/base-cloud-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#cloud-config

# the users section here sets up the live environment with what we need to be
# able to ssh in. At test runtime, a ssh key is added.
users:
- default
- name: ubuntu
plain_text_passwd: ubuntu
sudo: ALL=(ALL) NOPASSWD:ALL
groups: users, admin
shell: /bin/bash
lock_passwd: false

bootcmd:
- apt install -y openssh-server

autoinstall:
version: 1

# create a default user. Tests may override if desired.
identity:
realname: ''
hostname: ubuntu
username: ubuntu
password: '$6$wdAcoXrU039hKYPd$508Qvbe7ObUnxoj15DRCkzC3qO7edjH0VV7BPNRDYK4QR8ofJaEEF2heacn0QgD.f8pO8SNp83XNdWG6tocBM1'

# this sets up the target system with the ability to ssh in, for first boot
# testing. At test runtime, a ssh key is added.
ssh:
install-server: true
allow-pw: false

shutdown: poweroff
19 changes: 19 additions & 0 deletions vmtests/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import contextlib
from enum import Enum, auto

import pytest

MiB = 1 << 20
GiB = 1 << 30


class Firmware:
UEFI = "UEFI"
BIOS = "BIOS"


@contextlib.contextmanager
def assert_install_error():
with pytest.raises(pytest.fail.Exception) as ex:
yield
ex.match("install failed and reached ERROR state")
Loading
Loading