ppggff / vagrant-qemu

Use Vagrant to manage machines using QEMU. Test with Apple Silicon / M1 and CentOS aarch64 image
MIT License
408 stars 32 forks source link

Error when starting the instance: All arguments must be String #23

Closed RedlineTriad closed 1 year ago

RedlineTriad commented 1 year ago

Background

I want to use Ansible to provision my server. To test Ansible I use Molecule. For a more realistic testing environment with init system I want to use Vagrant as the Provisioner instead of Docker. I run my tests in GitHub Actions, which doesn't support nested virtualization. This means I want to run Vagrant with QEMU in emulation mode instead of a KVM backend.

My setup:

OS: Arch Linux mostly Vagrantfile:

Vagrant.configure("2") do |config|
  config.vm.box = "debian/buster64"
  config.vm.synced_folder ".", "/vagrant", disabled: true
  config.vm.provider "qemu" do |qe|
    qe.qemu_dir = "/usr/bin/"
    qe.arch="x86_64"
  end
end

Actual Problem

When testing this plugin locally I get the following Error:

opt/vagrant/embedded/gems/2.3.0/gems/childprocess-4.1.0/lib/childprocess/abstract_process.rb:44:in `initialize': all arguments must be String: ["/usr/bin/qemu-system-x86_64", "-machine", "virt,accel=hvf,highmem=on", "-cpu", "host", "-smp", "2", "-m", "4G", "-device", "virtio-net-device,netdev=net0", "-netdev", "user,id=net0,hostfwd=tcp::50022-:22", "-drive", "if=virtio,format=qcow2,file=/mnt/data/repos/Public/private_server/software/.vagrant/machines/default/qemu/8eN7SGA0QcM/linked-box.img", "-chardev", "socket,id=mon0,path=/home/redline/.vagrant.d/tmp/vagrant-qemu/8eN7SGA0QcM/qemu_socket,server=on,wait=off", "-mon", "chardev=mon0,mode=readline", "-chardev", "socket,id=ser0,path=/home/redline/.vagrant.d/tmp/vagrant-qemu/8eN7SGA0QcM/qemu_socket_serial,server=on,wait=off", "-serial", "chardev:ser0", "-pidfile", "/mnt/data/repos/Public/private_server/software/.vagrant/machines/default/qemu/8eN7SGA0QcM/qemu.pid", "-parallel", "null", "-monitor", "none", "-display", "none", "-vga", "none", "-daemonize", {:detach=>false}] (ArgumentError)

The problem here appears to be this argument to the process {:detach=>false} which isn't a string. This seems to come from this line of code: https://github.com/ppggff/vagrant-qemu/blob/2d12cfc4b34e7523028a3720bede398be9369c83/lib/vagrant-qemu/driver.rb#L114

I don't really have experience with Ruby and Vagrant but if you want I could try to get a fix together.

If there is some kind of workaround that would be nice too, I tried to toggle the no_daemonize flag but that didn't fix it either.

RedlineTriad commented 1 year ago

Also, please save me, I am yak shaving so damn hard. All of this is to host Grocy so I can have an inventory of all my groceries. And I intend to create a bot that automatically orderes them when they get low.

Am starving until then, please send food or therapist, just no more yaks.

ppggff commented 1 year ago

Following Vagrantfile works on my mac (with plugin version 0.3.2). Please try it.

Vagrant.configure("2") do |config|
  config.vm.box = "debian/buster64"
  config.vm.synced_folder ".", "/vagrant", disabled: true
  config.vm.provider "qemu" do |qe|
    qe.qemu_dir = "/usr/bin/"
    qe.arch="x86_64"

    # need for x86_64
    qe.machine = "q35"
    qe.cpu = "max"
    qe.net_device = "virtio-net-pci"

    # it seems this box need a VGA device (the debug serial port doesn't work... I don't know why)
    qe.extra_qemu_args = %w(-vga std)
  end
end

I never got the "All arguments must be String" error, did you alter the source code?

Also I think there should be a better way to change the default QEMU args, and a better debug method, I will work on it later.

RedlineTriad commented 1 year ago

No I didn't alter the source code, I installed the plugin with vagrant plugin install vagrant-qemu and am running it with vagrant up --provider qemu.

I am still getting the same error even with your Vagrantfile. Versions: Vagrant: 2.3.0 vagrant-qemu: 0.3.2

I feel like it should be reproducible since the list of argument just has a non string value in it: ..., "-daemonize", "-vga", "std", {:detach=>false}]

ppggff commented 1 year ago

Sorry, I found this is a compatibility issue about ruby 3.x, I try to fix it in version 0.3.3, please try it.

There may still have other compatibility issue in it, feel free to add them here. Thanks a lot.

RedlineTriad commented 1 year ago

Thank you a lot, this seems to have fixed the issue. It's funny working on my private server and just finding tons of bugs along the way, but somehow there is always a person that can help and fix it.

Terraform cloud had email verification issues. Molecule testing action had a docker image that broke but was fixed after a day. QEMU vagrant plugin is broken for new Ruby versions.

I just want to thank you for helping, and I hope we can just always make things a bit easier for the next person who wants to do a cool thing.