Skip to content

Commit 56acf81

Browse files
committed
T8065: Dehardcode qemu settings to allow run tests on arch arm64
1 parent 5fee758 commit 56acf81

3 files changed

Lines changed: 118 additions & 17 deletions

File tree

Makefile

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
SHELL := /bin/bash
22

3+
arch ?= $(shell dpkg --print-architecture 2>/dev/null || echo amd64)
34
build_dir := build
45

56
.PHONY: all
@@ -13,8 +14,8 @@ all:
1314
.PHONY: checkiso
1415
.ONESHELL:
1516
checkiso:
16-
if [ ! -f build/live-image-amd64.hybrid.iso ]; then
17-
echo "Could not find build/live-image-amd64.hybrid.iso"
17+
if [ ! -f build/live-image-$(arch).hybrid.iso ]; then
18+
echo "Could not find build/live-image-$(arch).hybrid.iso"
1819
exit 1
1920
fi
2021

@@ -31,7 +32,7 @@ test-no-interfaces: checkiso
3132
.PHONY: test-no-interfaces-no-vpp
3233
.ONESHELL:
3334
test-no-interfaces-no-vpp: checkiso
34-
scripts/check-qemu-install --debug --configd --smoketest --uefi --no-interfaces --no-vpp --iso build/live-image-amd64.hybrid.iso
35+
scripts/check-qemu-install --debug --configd --smoketest --uefi --no-interfaces --no-vpp --arch $(arch) --iso build/live-image-$(arch).hybrid.iso
3536

3637
.PHONY: test-interfaces
3738
.ONESHELL:
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
# Generic (aka "universal") ISO image
2+
3+
image_format = "iso"
4+
5+
[[includes_chroot]]
6+
path = "opt/vyatta/etc/config.boot.default"
7+
data = '''
8+
interfaces {
9+
loopback lo {
10+
}
11+
}
12+
service {
13+
ntp {
14+
allow-client {
15+
address "127.0.0.0/8"
16+
address "169.254.0.0/16"
17+
address "10.0.0.0/8"
18+
address "172.16.0.0/12"
19+
address "192.168.0.0/16"
20+
address "::1/128"
21+
address "fe80::/10"
22+
address "fc00::/7"
23+
}
24+
server time1.vyos.net {
25+
}
26+
server time2.vyos.net {
27+
}
28+
server time3.vyos.net {
29+
}
30+
}
31+
}
32+
system {
33+
config-management {
34+
commit-revisions "100"
35+
}
36+
console {
37+
device ttyAMA0 {
38+
speed "115200"
39+
}
40+
}
41+
host-name "vyos"
42+
login {
43+
operator-group default {
44+
command-policy {
45+
allow "*"
46+
}
47+
}
48+
user vyos {
49+
authentication {
50+
encrypted-password "$6$QxPS.uk6mfo$9QBSo8u1FkH16gMyAVhus6fU3LOzvLR9Z9.82m3tiHFAxTtIkhaZSWssSgzt4v4dGAL8rhVQxTg0oAG9/q11h/"
51+
plaintext-password ""
52+
}
53+
}
54+
}
55+
option {
56+
reboot-on-upgrade-failure 5
57+
}
58+
syslog {
59+
local {
60+
facility all {
61+
level "info"
62+
}
63+
facility local7 {
64+
level "debug"
65+
}
66+
}
67+
}
68+
}
69+
'''
70+
71+
[boot_settings]
72+
console_type = "ttyAMA"
73+
console_num = '0'
74+
console_speed = "115200"

scripts/check-qemu-install

Lines changed: 40 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,23 @@ KEY_Y = chr(121)
8282

8383
mok_password = '1234'
8484

85+
# Map QEMU arch
86+
QEMU_CONFIG = {
87+
"amd64": {
88+
"bin": "qemu-system-x86_64",
89+
"machine": "pc",
90+
"bios": "/usr/share/OVMF/OVMF_CODE.fd",
91+
},
92+
"arm64": {
93+
"bin": "qemu-system-aarch64",
94+
"machine": "virt",
95+
"bios": "/usr/share/qemu-efi-aarch64/QEMU_EFI.fd",
96+
},
97+
}
98+
8599
parser = argparse.ArgumentParser(description='Install and start a test VyOS vm.')
86100
parser.add_argument('--iso', help='ISO file to install')
101+
parser.add_argument('--arch', help='Architecture')
87102
parser.add_argument('--disk', help='name of disk image file', nargs='?')
88103
parser.add_argument('--keep', help='Do not remove disk-image after installation',
89104
action='store_true', default=False)
@@ -113,6 +128,7 @@ parser.add_argument('--cloud-init', help='Execute cloud-init tests',
113128
parser.add_argument('--qemu-cmd', help='Only generate QEMU launch command',
114129
action='store_true', default=False)
115130
parser.add_argument('--cpu', help='Set QEMU CPU', type=int, default=2)
131+
parser.add_argument('--cpu-type', help='Set QEMU CPU type', type=str, default='host')
116132
parser.add_argument('--memory', help='Set QEMU memory', type=int, default=4)
117133
parser.add_argument('--vyconf', help='Execute testsuite with vyconfd', action='store_true',
118134
default=False)
@@ -165,18 +181,28 @@ class StreamToLogger(object):
165181
class EarlyExit(Exception):
166182
pass
167183

184+
def _kvm_exists():
185+
return os.path.exists("/dev/kvm")
186+
168187
def get_qemu_cmd(name, enable_uefi, disk_img, raid=None, iso_img=None, tpm=False, vnc_enabled=False, secure_boot=False):
169188
uefi = ""
170189
uuid = "f48b60b2-e6ad-49ef-9d09-4245d0585e52"
171-
machine = 'pc'
190+
accel = ',accel=kvm' if _kvm_exists() else ''
191+
arch = getattr(args, 'arch', 'amd64')
192+
qemu_arch_config = QEMU_CONFIG.get(arch, QEMU_CONFIG['amd64'])
193+
qemu_bin = qemu_arch_config['bin']
194+
bios = qemu_arch_config['bios']
195+
cpu_type = args.cpu_type
196+
enable_kvm = '-enable-kvm' if _kvm_exists() else ''
197+
machine = qemu_arch_config['machine']
172198
vga = '-vga none'
173199
vnc = ''
174200
if vnc_enabled:
175201
vga = '-vga virtio'
176202
vnc = '-vnc :0'
177203

178204
if enable_uefi:
179-
uefi = '-bios /usr/share/OVMF/OVMF_CODE.fd'
205+
uefi = f'-bios {bios}'
180206
name = f'{name}-UEFI'
181207

182208
if secure_boot:
@@ -190,28 +216,28 @@ def get_qemu_cmd(name, enable_uefi, disk_img, raid=None, iso_img=None, tpm=False
190216

191217
cdrom = ""
192218
if iso_img:
193-
cdrom = f' -drive file={iso_img},format=raw,if=none,media=cdrom,id=drive-cd1,readonly=on' \
194-
f' -device ahci,id=achi0' \
195-
f' -device ide-cd,bus=achi0.0,drive=drive-cd1,id=cd1,bootindex=10'
219+
cdrom = (
220+
f' -drive file={iso_img},format=raw,if=none,media=cdrom,id=drive-cd1,readonly=on'
221+
f' -device scsi-cd,bus=scsi0.0,drive=drive-cd1,id=cd1,bootindex=10'
222+
)
196223

197224
# RFC7042 section 2.1.2 MAC addresses used for documentation
198225
macbase = '00:00:5E:00:53'
199226

200227
# Set QEmu disk image format - this differs if VyOS was installed via smoketest
201228
# or we use an already ewxisting image
202229
disk_format = 'qcow2' if args.disk.endswith('.qcow2') else 'raw'
203-
cmd = f'qemu-system-x86_64 \
230+
cmd = f'{qemu_bin} \
204231
-name "{name}" \
205232
-smp {args.cpu},sockets=1,cores={args.cpu},threads=1 \
206-
-cpu host \
207-
-machine {machine},accel=kvm \
233+
-cpu {cpu_type} \
234+
-machine {machine}{accel} \
208235
{uefi} \
209236
-m {args.memory}G \
210237
-nographic \
211238
{vga} {vnc}\
212239
-uuid {uuid} \
213-
{cdrom} \
214-
-enable-kvm \
240+
{enable_kvm} \
215241
-monitor unix:/tmp/qemu-monitor-socket-{disk_img},server,nowait \
216242
-netdev user,id=n0,net=192.0.2.0/24,dhcpstart=192.0.2.101,dns=192.0.2.10 -device virtio-net-pci,netdev=n0,mac={macbase}:00,romfile="",host_mtu=1500 \
217243
-netdev user,id=n1 -device virtio-net-pci,netdev=n1,mac={macbase}:01,romfile="",host_mtu=1500 \
@@ -222,6 +248,7 @@ def get_qemu_cmd(name, enable_uefi, disk_img, raid=None, iso_img=None, tpm=False
222248
-netdev user,id=n6 -device virtio-net-pci,netdev=n6,mac={macbase}:06,romfile="" \
223249
-netdev user,id=n7 -device virtio-net-pci,netdev=n7,mac={macbase}:07,romfile="" \
224250
-device virtio-scsi-pci,id=scsi0 \
251+
{cdrom} \
225252
-drive format={disk_format},file={disk_img},if=none,media=disk,id=drive-hd1,readonly=off \
226253
-device scsi-hd,bus=scsi0.0,drive=drive-hd1,id=hd1,bootindex=1'
227254

@@ -300,7 +327,6 @@ else:
300327

301328
if not os.path.exists('/dev/kvm'):
302329
log.error('KVM not enabled on host, proceeding with software emulation')
303-
sys.exit(1)
304330

305331
if not args.iso and not args.disk:
306332
log.error('Neither ISO not QCOW2 disk image supplied - error!')
@@ -484,9 +510,9 @@ def basic_cli_tests(c):
484510
c.expect(op_mode_prompt)
485511
c.sendline('show interfaces')
486512
c.expect(op_mode_prompt)
487-
c.sendline('systemd-detect-virt')
488-
c.expect('kvm')
489-
c.expect(op_mode_prompt)
513+
# c.sendline('systemd-detect-virt')
514+
# c.expect('kvm')
515+
# c.expect(op_mode_prompt)
490516
c.sendline('show system cpu')
491517
c.expect(op_mode_prompt)
492518
c.sendline('show system memory')

0 commit comments

Comments
 (0)