fix: Dynamically create netdev arguments to correctly include commas#2581
Conversation
tormath1
left a comment
There was a problem hiding this comment.
Looks good, thanks for the quick fix. :)
There was a problem hiding this comment.
This can be moved to bugfixes section.
I deleted this part: # Construct the -netdev user argument dynamically
NETDEV_USER_ARGS="id=eth0,hostfwd=tcp::${SSH_PORT}-:22,hostname=${VM_NAME}"
if [ -n "${QEMU_FORWARDED_PORTS}" ]; then
NETDEV_USER_ARGS="${NETDEV_USER_ARGS},${QEMU_FORWARDED_PORTS}"
fiAnd replace the case "${VM_BOARD}" in
amd64-usr)
qemu-system-x86_64 \
-name "$VM_NAME" \
-m ${VM_MEMORY} \
-netdev user,id=eth0${QEMU_FORWARDED_PORTS+,}${QEMU_FORWARDED_PORTS},hostfwd=tcp::"${SSH_PORT}"-:22,hostname="${VM_NAME}" \
-device virtio-net-pci,netdev=eth0 \
-object rng-random,filename=/dev/urandom,id=rng0 -device virtio-rng-pci,rng=rng0 \
"$@"
;;
arm64-usr)
qemu-system-aarch64 \
-name "$VM_NAME" \
-m ${VM_MEMORY} \
-netdev user,id=eth0${QEMU_FORWARDED_PORTS+,}${QEMU_FORWARDED_PORTS},hostfwd=tcp::"${SSH_PORT}"-:22,hostname="${VM_NAME}" \
-device virtio-net-device,netdev=eth0 \
-object rng-random,filename=/dev/urandom,id=rng0 -device virtio-rng-pci,rng=rng0 \
"$@"
;;
*) die "Unsupported arch" ;;
esacIm not sure if Im doing something wrong here but Im getting double commas here: ./flatcar_production_qemu.sh -- -display curses
qemu-system-x86_64: -netdev user,id=eth0,,hostfwd=tcp::2222-:22,hostname=flatcar_production_qemu-4215-0-0-nightly-20250114-2100: Parameter 'id' expects an identifier
Identifiers consist of letters, digits, '-', '.', '_', starting with a letter. |
|
That's my fault. I edited my comment after a few moments to add a |
|
Build action triggered: https://github.com/flatcar/scripts/actions/runs/12827137845 |
Oh, got it, thanks! Now its working perfectly 😄 |
|
Thanks for the tip Chewi! I updated the PR with his changes, and ran the same commands as in the PR test description and everything seems to be working 😄 |
tormath1
left a comment
There was a problem hiding this comment.
LGTM. Feel free to rebase / squash your commits. Too bad we missed that at the review, maybe we should add a test case for those helpers.
This has to be backported on the alpha maintenance branch too.
docs: Add entrance to the changelog about the fix Update changelog/changes/2025-01-15-qemu-startup-script-comma-fix.md Co-authored-by: Mathieu Tortuyaux <mathieu.tortuyaux@gmail.com>
d649592 to
0f0fa2f
Compare
Done, sorry I forgot to use your tip for squashing will try that next time😜 Also yeah, my fault I missed that during testing somehow. How would you guys go about creating a test for something like that? |
|
I'm not sure where it would fit in our test infrastructure. I think it would be important to actually run QEMU so that you know whether the invocation is valid. Perhaps it could be started headless in the background and then terminated after a few seconds. You could then check whether the exit status was successful. |
|
You wouldn't even need a real disk image because it doesn't matter whether it actually boots or not. You might need real firmware for it to start though. |
|
Cherry-picked to:
|
Fix excessive comma in
-netdevargumentFix the previous change, where an excessive comma was added to the
-netdevargument when no port forwards were passed:By dynamically creating the argument to correctly include commas.
How to use
Testing done
Correctly starts up the machine and forwards the SSH port to 2222:
Correctly starts up the machine and forwards the SSH port and all of the mentioned ports in the argument:
changelog/directory (user-facing change, bug fix, security fix, update)/bootand/usrsize, packages, list files for any missing binaries, kernel modules, config files, kernel modules, etc.