-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest_nested_virtualization.py
More file actions
93 lines (72 loc) · 2.73 KB
/
test_nested_virtualization.py
File metadata and controls
93 lines (72 loc) · 2.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
"""
Nested Virtualization Acceptance Tests
======================================
Customers can start virtual servers inside VMs (nested virtualiziation).
"""
from constants import CUSTOM_IMAGE_ALPINE_URL
from util import oneliner
def test_virtualization_support(server):
""" Nested virtualization is supported. """
# List of virt-host-validate checks that do NOT need to "PASS"
virt_validate_pass_exceptions = {
"Checking for device assignment IOMMU support",
"Checking for secure guest support",
"Checking for cgroup 'freezer' controller support",
}
# Install the required package
server.run('sudo apt update')
server.run('sudo apt install -y libvirt-clients')
virt_validate_status = server.run('sudo virt-host-validate').stdout
# Validate all checks PASS except for the ones defined above
for line in virt_validate_status.splitlines():
parts = line.split(':')
description = parts[1].strip()
status = parts[2].strip().split()[0]
if description not in virt_validate_pass_exceptions:
assert status == "PASS"
def test_run_nested_vm(server):
""" Nested virtualization is supported. """
vm_os = 'alpine' # Needs to match one virt os-variant
vm_iso_url = f"{CUSTOM_IMAGE_ALPINE_URL}.qcow2"
# Install the required package
server.run('sudo apt update')
server.run(oneliner(f"""
sudo apt install -y
libvirt-clients
qemu-kvm
libvirt-daemon-system
bridge-utils
virt-manager
"""))
# Make sure qemu tests pass and rc == 0
assert server.output_of('sudo virt-host-validate --help')
server.run(f'wget {vm_iso_url} -O /var/tmp/{vm_os}.qcow2')
server.run('sudo virsh net-start default')
server.run('sudo virsh net-autostart default')
server.run(oneliner(f"""
sudo virt-install
--virt-type kvm
--name {vm_os}_vm
--ram 1024
--vcpus=1
--disk path=/var/tmp/{vm_os}.qcow2,format=qcow2,bus=virtio
--autoconsole none
--os-variant generic
--hvm
--import
--serial file,path=/var/log/{vm_os}_vm.log
"""))
# Return the part of the table that has the actual state for the VM
vm_status = server.output_of(oneliner("""
sudo virsh -c qemu:///system list
| sed -n 3p
"""))
assert vm_os in vm_status and 'running' in vm_status
# Wait until the VM is actually booted and we see the welcome message
# in the console log. Use a timeout of 40s so the VM has time to actually
# boot up.
server.wait_for_text_in_file(
f'/var/log/{vm_os}_vm.log',
'Welcome to Alpine Linux',
40
)