Skip to content

Commit 1e3e98c

Browse files
committed
T8065: Dehardcode qemu settings to allow run tests on arch arm64
1 parent 7a5f513 commit 1e3e98c

6 files changed

Lines changed: 188 additions & 16 deletions

File tree

Makefile

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

33
build_dir := build
44

5+
arch ?= $(shell dpkg --print-architecture 2>/dev/null || echo amd64)
6+
57
.PHONY: all
68
all:
79
@echo "Make what specifically?"
@@ -13,8 +15,8 @@ all:
1315
.PHONY: checkiso
1416
.ONESHELL:
1517
checkiso:
16-
if [ ! -f build/live-image-amd64.hybrid.iso ]; then
17-
echo "Could not find build/live-image-amd64.hybrid.iso"
18+
if [ ! -f build/live-image-$(arch).hybrid.iso ]; then
19+
echo "Could not find build/live-image-$(arch).hybrid.iso"
1820
exit 1
1921
fi
2022

@@ -31,7 +33,7 @@ test-no-interfaces: checkiso
3133
.PHONY: test-no-interfaces-no-vpp
3234
.ONESHELL:
3335
test-no-interfaces-no-vpp: checkiso
34-
scripts/check-qemu-install --debug --configd --smoketest --uefi --no-interfaces --no-vpp build/live-image-amd64.hybrid.iso
36+
scripts/check-qemu-install --debug --configd --smoketest --uefi --no-interfaces --no-vpp --arch $(arch) build/live-image-$(arch).hybrid.iso
3537

3638
.PHONY: test-interfaces
3739
.ONESHELL:
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
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+
syslog {
43+
local {
44+
facility all {
45+
level "info"
46+
}
47+
facility local7 {
48+
level "debug"
49+
}
50+
}
51+
}
52+
}
53+
'''
54+
55+
[boot_settings]
56+
console_type = "ttyAMA"
57+
console_num = '0'
58+
console_speed = "115200"

docker-vyos/Dockerfile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,10 @@ RUN bash /tmp/vyos_install_stage_02.sh
6464
# Tune system for VyOS
6565
COPY [ "docker-vyos/vyos_install_common.sh", "docker-vyos/vyos_install_stage_03.sh", "/tmp/" ]
6666
# Copy default config
67-
COPY tools/container/config.boot.default /opt/vyatta/etc/
67+
# Detect architecture and copy the corresponding config file
68+
RUN ARCH=$(dpkg --print-architecture 2>/dev/null || echo amd64) && \
69+
echo "Detected architecture: $ARCH" && \
70+
cp tools/container/config.boot.$ARCH /opt/vyatta/etc/config.boot.default
6871

6972
RUN bash /tmp/vyos_install_stage_03.sh
7073

scripts/check-qemu-install

Lines changed: 41 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,20 @@ now = datetime.now()
5454
tpm_folder = '/tmp/vyos_tpm_test'
5555
qemu_name = 'VyOS-QEMU'
5656

57+
# Map QEMU arch
58+
QEMU_CONFIG = {
59+
"amd64": {
60+
"bin": "qemu-system-x86_64",
61+
"machine": "pc",
62+
"bios": "/usr/share/OVMF/OVMF_CODE.fd",
63+
},
64+
"arm64": {
65+
"bin": "qemu-system-aarch64",
66+
"machine": "virt",
67+
"bios": "/usr/share/qemu-efi-aarch64/QEMU_EFI.fd",
68+
},
69+
}
70+
5771
# getch.py
5872
KEY_F2 = chr(27) + chr(91) + chr(49) + chr(50) + chr(126)
5973
KEY_F10 = chr(27) + chr(91) + chr(50) + chr(49) + chr(126)
@@ -103,6 +117,7 @@ parser.add_argument('--no-vpp', help='Execute testsuite without VPP tests',
103117
action='store_true', default=False)
104118
parser.add_argument('--huge-page-size', help='Huge page size (e.g., 2M, 1G)', type=str)
105119
parser.add_argument('--huge-page-count', help='Number of huge pages to allocate', type=int)
120+
parser.add_argument('--arch', help='Architecture')
106121

107122
args = parser.parse_args()
108123

@@ -145,18 +160,31 @@ OVMF_VARS_TMP = args.disk.replace('.img', '.efivars')
145160
if args.sbtest:
146161
shutil.copy('/usr/share/OVMF/OVMF_VARS_4M.ms.fd', OVMF_VARS_TMP)
147162

163+
164+
def _kvm_exists():
165+
return os.path.exists("/dev/kvm")
166+
167+
148168
def get_qemu_cmd(name, enable_uefi, disk_img, raid=None, iso_img=None, tpm=False, vnc_enabled=False, secure_boot=False):
149169
uefi = ""
150170
uuid = "f48b60b2-e6ad-49ef-9d09-4245d0585e52"
151-
machine = 'pc'
171+
arch = getattr(args, 'arch', 'amd64')
172+
qemu_arch_config = QEMU_CONFIG.get(arch, QEMU_CONFIG["amd64"])
173+
qemu_bin = qemu_arch_config['bin']
174+
bios = qemu_arch_config['bios']
175+
cpu = 'host'
176+
machine = qemu_arch_config['machine']
177+
accel = ',accel=kvm' if _kvm_exists() else ''
178+
enable_kvm = '-enable-kvm' if _kvm_exists() else ''
152179
vga = '-vga none'
153180
vnc = ''
181+
154182
if vnc_enabled:
155183
vga = '-vga virtio'
156184
vnc = '-vnc :0'
157185

158186
if enable_uefi:
159-
uefi = '-bios /usr/share/OVMF/OVMF_CODE.fd'
187+
uefi = f'-bios {bios}'
160188
name = f'{name}-UEFI'
161189

162190
if secure_boot:
@@ -170,26 +198,25 @@ def get_qemu_cmd(name, enable_uefi, disk_img, raid=None, iso_img=None, tpm=False
170198

171199
cdrom = ""
172200
if iso_img:
173-
cdrom = f' -drive file={iso_img},format=raw,if=none,media=cdrom,id=drive-cd1,readonly=on' \
174-
f' -device ahci,id=achi0' \
175-
f' -device ide-cd,bus=achi0.0,drive=drive-cd1,id=cd1,bootindex=10'
201+
cdrom = (
202+
f' -drive file={iso_img},format=raw,if=none,media=cdrom,id=drive-cd1,readonly=on'
203+
f' -device scsi-cd,bus=scsi0.0,drive=drive-cd1,id=cd1,bootindex=10'
204+
)
176205

177206
# RFC7042 section 2.1.2 MAC addresses used for documentation
178207
macbase = '00:00:5E:00:53'
179-
cmd = f'qemu-system-x86_64 \
208+
cmd = f'{qemu_bin} \
180209
-name "{name}" \
181210
-smp {args.cpu},sockets=1,cores={args.cpu},threads=1 \
182-
-cpu host \
183-
-machine {machine},accel=kvm \
211+
-cpu {cpu} \
212+
-machine {machine}{accel} \
184213
{uefi} \
185214
-m {args.memory}G \
186215
-vga none \
187216
-nographic \
188217
{vga} {vnc}\
189218
-uuid {uuid} \
190-
-cpu host \
191-
{cdrom} \
192-
-enable-kvm \
219+
{enable_kvm} \
193220
-monitor unix:/tmp/qemu-monitor-socket-{disk_img},server,nowait \
194221
-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 \
195222
-netdev user,id=n1 -device virtio-net-pci,netdev=n1,mac={macbase}:01,romfile="",host_mtu=1500 \
@@ -200,6 +227,7 @@ def get_qemu_cmd(name, enable_uefi, disk_img, raid=None, iso_img=None, tpm=False
200227
-netdev user,id=n6 -device virtio-net-pci,netdev=n6,mac={macbase}:06,romfile="" \
201228
-netdev user,id=n7 -device virtio-net-pci,netdev=n7,mac={macbase}:07,romfile="" \
202229
-device virtio-scsi-pci,id=scsi0 \
230+
{cdrom} \
203231
-drive format=raw,file={disk_img},if=none,media=disk,id=drive-hd1,readonly=off \
204232
-device scsi-hd,bus=scsi0.0,drive=drive-hd1,id=hd1,bootindex=1'
205233

@@ -282,7 +310,8 @@ if not os.path.isfile(args.iso):
282310

283311
if not os.path.exists('/dev/kvm'):
284312
log.error('KVM not enabled on host, proceeding with software emulation')
285-
sys.exit(1)
313+
# Some arm platforms do not have kvm, for example Mac arm devices
314+
# sys.exit(1)
286315

287316
# Creating diskimage!!
288317
diskname_raid = None
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
system {
2+
host-name vyos
3+
login {
4+
user vyos {
5+
authentication {
6+
encrypted-password "*"
7+
plaintext-password ""
8+
}
9+
level admin
10+
}
11+
}
12+
syslog {
13+
local {
14+
facility all {
15+
level info
16+
}
17+
facility protocols {
18+
level debug
19+
}
20+
}
21+
}
22+
ntp {
23+
server "time1.vyos.net"
24+
server "time2.vyos.net"
25+
server "time3.vyos.net"
26+
}
27+
console {
28+
device ttyS0 {
29+
speed 115200
30+
}
31+
}
32+
config-management {
33+
commit-revisions 100
34+
}
35+
}
36+
37+
interfaces {
38+
loopback lo {
39+
}
40+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
system {
2+
host-name vyos
3+
login {
4+
user vyos {
5+
authentication {
6+
encrypted-password "*"
7+
plaintext-password ""
8+
}
9+
level admin
10+
}
11+
}
12+
syslog {
13+
local {
14+
facility all {
15+
level info
16+
}
17+
facility protocols {
18+
level debug
19+
}
20+
}
21+
}
22+
ntp {
23+
server "time1.vyos.net"
24+
server "time2.vyos.net"
25+
server "time3.vyos.net"
26+
}
27+
console {
28+
device ttyAMA0 {
29+
speed 115200
30+
}
31+
}
32+
config-management {
33+
commit-revisions 100
34+
}
35+
}
36+
37+
interfaces {
38+
loopback lo {
39+
}
40+
}

0 commit comments

Comments
 (0)