-
Notifications
You must be signed in to change notification settings - Fork 53
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: Dynamically create netdev arguments to correctly include commas #2581
fix: Dynamically create netdev arguments to correctly include commas #2581
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is fine, but another way to do it is:
-netdev user,id=eth0${QEMU_FORWARDED_PORTS:+,}${QEMU_FORWARDED_PORTS},hostfwd=tcp::"${SSH_PORT}"-:22,hostname="${VM_NAME}"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, thanks for the quick fix. :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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}"
fi And 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" ;;
esac Im 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 😄 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 <[email protected]>
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
-netdev
argumentFix the previous change, where an excessive comma was added to the
-netdev
argument 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)/boot
and/usr
size, packages, list files for any missing binaries, kernel modules, config files, kernel modules, etc.