Skip to content

Conversation

victormlg
Copy link
Contributor

@victormlg victormlg commented Sep 9, 2025

It was a bit hard to know exactly what approach to take so if you have any better ideas I am interested

This doesn't exactly work yet, because

  • when creating VMs in a loop with a default name (like dev-1, dev-2, dev-3...) , the vms are created but only the first one created is accessible from the directory where lies the Vagrantfile (I'm using virtualbox)
  • when creating VMs with a custom name given by an env variable (ike in the pr) the vm is just not accessible, as if it wasn't created, but is actually present in virtualbox.

I am not sure how we should provision the created vms. We could:

  • just leave them unprovisioned
  • like I do in the code: let the user input his own provision script
  • start the VM unprovisioned, then inspect it using nt-discovery.sh and find all the information we need (like what package manager it uses, etc...) then provision it with a modular script using the collected data.

Copy link
Contributor

@craigcomstock craigcomstock left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks like a great start! I have added some notes on things we have solved in jenkins-vms regarding various bits.

node.vm.provider "virtualbox" do |vb|
vb.memory = VM_MEMORY
vb.cpus = VM_CPUS
vb.customize [ "guestproperty", "set", :id, "/VirtualBox/GuestAdd/VBoxService/--timesync-set-threshold", 1000 ]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

regarding time and dns you might need to include this snippet from jenkins-vms that handles darwin/macos

https://gitlab.com/Northern.tech/CFEngine/jenkins-vms/-/blob/master/scripts/common.rb?ref_type=heads#L104

# previously working Vagrantfiles:
# https://fedoraproject.org/wiki/Changes/Vagrant_2.2_with_QEMU_Session#Upgrade.2Fcompatibility_impact
v.qemu_use_session = false
override.vm.synced_folder "./", "/vagrant", type: :rsync
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

synced folders are also tricky for older distributions like debian-9:

here are some workarounds for centos-7 and old debians:

https://gitlab.com/Northern.tech/CFEngine/jenkins-vms/-/blob/master/scripts/common.rb?ref_type=heads#L151

@victormlg victormlg force-pushed the spawn-vagrant branch 3 times, most recently from 429b367 to 8ff3c80 Compare September 23, 2025 15:37
@victormlg victormlg marked this pull request as ready for review September 30, 2025 15:40
@victormlg victormlg requested a review from larsewi September 30, 2025 15:44
Copy link
Contributor

@larsewi larsewi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great 🚀 Some smaller comments

While reviewing your PR, I never understood what the config argument to ssh and scp is for, or why it's necessary. Could you explain?

return [
VagrantVM(
"{}-{}".format(name, i + 1),
"{}.{}".format(start_ip, end_ip + i),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you run cf-remote spawn two times, the IPs will conflict?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For now, yes. I didn't come up with any better solution

@victormlg
Copy link
Contributor Author

Looks great 🚀 Some smaller comments

While reviewing your PR, I never understood what the config argument to ssh and scp is for, or why it's necessary. Could you explain?

When you spawn a vagrant VM, vagrant generates a ssh config file with a private key and everything set up correctly. You can inspect it by running vagrant ssh-config. When you ssh into a vagrant machine by running vagrant ssh <name>, vagrant is simply doing ssh -F .
Connecting with vanilla ssh was a bit cumbersome because it resulted in a lot of errors and man-in-the-middle attacks warnings and such, so I thought it would be easier to connect by using the ssh config file generated by vagrant

The variable "config" is simply the path to the vagrant-ssh-config file inside the VM's directory. If it is not None, then the connection will connect using it.

Ticket: ENT-5725
Signed-off-by: Victor Moene <victor.moene@northern.tech>
Copy link
Contributor

@larsewi larsewi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like there are some failing test :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants