diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-27 18:24:20 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-27 18:24:20 +0000 |
commit | 483eb2f56657e8e7f419ab1a4fab8dce9ade8609 (patch) | |
tree | e5d88d25d870d5dedacb6bbdbe2a966086a0a5cf /src/spdk/scripts/vagrant/Vagrantfile | |
parent | Initial commit. (diff) | |
download | ceph-upstream.tar.xz ceph-upstream.zip |
Adding upstream version 14.2.21.upstream/14.2.21upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | src/spdk/scripts/vagrant/Vagrantfile | 158 | ||||
-rw-r--r-- | src/spdk/scripts/vagrant/Vagrantfile_vhost_vm | 111 |
2 files changed, 269 insertions, 0 deletions
diff --git a/src/spdk/scripts/vagrant/Vagrantfile b/src/spdk/scripts/vagrant/Vagrantfile new file mode 100644 index 00000000..40e012b2 --- /dev/null +++ b/src/spdk/scripts/vagrant/Vagrantfile @@ -0,0 +1,158 @@ +# -*- mode: ruby -*- +# vi: set ft=ruby : + +Vagrant.configure(2) do |config| + + # Pick the right distro and bootstrap, default is fedora26 + distro = ( ENV['SPDK_VAGRANT_DISTRO'] || "fedora26") + case distro + when "centos7" + config.vm.box = "puppetlabs/centos-7.2-64-nocm" + config.ssh.insert_key = false + # Puppetlabs does not provide libvirt Box so we will use official one + config.vm.provider :libvirt do |libvirt| + config.vm.box = "centos/7" + end if Vagrant.has_plugin?('vagrant-libvirt') + when "ubuntu16" + # See: https://app.vagrantup.com/puppetlabs/boxes/ubuntu-16.04-64-nocm + config.vm.box = "puppetlabs/ubuntu-16.04-64-nocm" + config.vm.box_version = "1.0.0" + when "ubuntu18" + # See: https://app.vagrantup.com/bento/boxes/ubuntu-18.04 + config.vm.box = "bento/ubuntu-18.04" + config.vm.box_version = "201803.24.0" + when "fedora26" + #See: https://app.vagrantup.com/generic/boxes/fedora2 + config.vm.box = "generic/fedora26" + when "fedora27" + #See: https://app.vagrantup.com/generic/boxes/fedora27 + config.vm.box = "generic/fedora27" + when "fedora28" + #See: https://app.vagrantup.com/generic/boxes/fedora28 + config.vm.box = "generic/fedora28" + when "freebsd11" + #See: https://app.vagrantup.com/generic/boxes/freebsd11 + config.vm.box = "generic/freebsd11" + if File.file?(File.expand_path("~/vagrant_pkg.conf")) + config.vm.provision "file", source: "~/vagrant_pkg.conf", destination: "pkg.conf" + config.vm.provision "shell", inline: "sudo mv pkg.conf /usr/local/etc/pkg.conf" + config.vm.provision "shell", inline: "sudo chown root:wheel /usr/local/etc/pkg.conf" + config.vm.provision "shell", inline: "sudo chmod 644 /usr/local/etc/pkg.conf" + end + else + "Invalid argument #{distro}" + abort("Invalid argument!") + end + config.vm.box_check_update = false + + # Copy in the .gitconfig if it exists + if File.file?(File.expand_path("~/.gitconfig")) + config.vm.provision "file", source: "~/.gitconfig", destination: ".gitconfig" + end + + # Copy the tsocks configuration file for use when installing some spdk test pool dependencies + if File.file?("/etc/tsocks.conf") + config.vm.provision "file", source: "/etc/tsocks.conf", destination: "tsocks.conf" + config.vm.provision "shell", inline: "sudo mv tsocks.conf /etc/tsocks.conf" + config.vm.provision "shell", inline: "sudo chown root:wheel /etc/tsocks.conf" + config.vm.provision "shell", inline: "sudo chmod 644 /etc/tsocks.conf" + end + + # vagrant-cachier caches apt/yum etc to speed subsequent + # vagrant up + # to enable, run + # vagrant plugin install vagrant-cachier + # + if Vagrant.has_plugin?("vagrant-cachier") + config.cache.scope = :box + end + + config.vm.network "private_network", type: "dhcp" + + # use http proxy if avaiable + if ENV['http_proxy'] && Vagrant.has_plugin?("vagrant-proxyconf") + config.proxy.http = ENV['http_proxy'] + config.proxy.https = ENV['https_proxy'] + config.proxy.no_proxy = "localhost,127.0.0.1" + end + + vmcpu=(ENV['SPDK_VAGRANT_VMCPU'] || 2) + vmram=(ENV['SPDK_VAGRANT_VMRAM'] || 4096) + spdk_dir=(ENV['SPDK_DIR'] || "none") + vhost_host_dir=(ENV['VHOST_HOST_DIR'] || "none") + vhost_vm_dir=(ENV['VHOST_VM_DIR'] || "none") + + config.ssh.forward_agent = true + config.ssh.forward_x11 = true + + config.vm.provider "virtualbox" do |vb| + vb.customize ["modifyvm", :id, "--ioapic", "on"] + vb.memory = "#{vmram}" + vb.cpus = "#{vmcpu}" + + nvme_disk = 'nvme.vdi' + unless File.exist? (nvme_disk) + vb.customize ["createhd", "--filename", nvme_disk, "--variant", "Fixed", "--size", "1024"] + vb.customize ["storagectl", :id, "--name", "nvme", "--add", "pcie", "--controller", "NVMe", "--portcount", "1", "--bootable", "off"] + vb.customize ["storageattach", :id, "--storagectl", "nvme", "--type", "hdd", "--medium", nvme_disk, "--port", "0"] + end + + #support for the SSE4.x instruction is required in some versions of VB. + vb.customize ["setextradata", :id, "VBoxInternal/CPUM/SSE4.1", "1"] + vb.customize ["setextradata", :id, "VBoxInternal/CPUM/SSE4.2", "1"] + end + + # This setup was Tested on Fedora 27 + # libvirt configuration need modern Qemu(tested on 2.10) & vagrant-libvirt in version 0.0.39+ + # There are few limitation for SElinux - The file added outside libvirt must have proper SE ACL policy or setenforce 0 + config.vm.provider "libvirt" do |libvirt, override| + libvirt.random_hostname = "1" + libvirt.disk_bus = "virtio" + + # we put nvme_disk inside default pool to eliminate libvirt/SELinux Permissions Problems + # and to be able to run vagrant from user $HOME directory + nvme_disk = '/var/lib/libvirt/images/nvme_disk.img' + unless File.exist? (nvme_disk) + puts "If run with libvirt provider please execute create_nvme_img.sh" + end + + libvirt.qemuargs :value => "-drive" + libvirt.qemuargs :value => "file=#{nvme_disk},if=none,id=D22" + libvirt.qemuargs :value => "-device" + libvirt.qemuargs :value => "nvme,drive=D22,serial=1234" + libvirt.driver = "kvm" + libvirt.graphics_type = "spice" + libvirt.memory = "#{vmram}" + libvirt.cpus = "#{vmcpu}" + libvirt.video_type = "qxl" + + # Optional field if we want use other storage pools than default + # libvirt.storage_pool_name = "vm" + end + + # rsync the spdk directory if provision hasn't happened yet + if ENV['COPY_SPDK_DIR'] == "1" && spdk_dir != "none" + config.vm.synced_folder "#{spdk_dir}", "/home/vagrant/spdk_repo/spdk", type: "rsync", rsync__auto: false + end + + # provision the vm with all of the necessary spdk dependencies for running the autorun.sh tests + if ENV['DEPLOY_TEST_VM'] == "1" && spdk_dir != "none" + config.vm.provision "shell" do |setup| + setup.path = "#{spdk_dir}/test/common/config/vm_setup.sh" + setup.privileged = false + setup.args = ["-u", "-i"] + end + end + + if vhost_host_dir != "none" + config.vm.synced_folder "#{vhost_host_dir}", "#{vhost_vm_dir}", type: "rsync", rsync__auto: false + config.vm.provision "shell", inline: "sudo mkdir -p /root/.ssh" + config.vm.provision "shell", inline: "sudo cp #{vhost_vm_dir}/spdk_vhost_id_rsa* /root/.ssh" + config.vm.provision "shell", inline: "sudo chmod 600 /root/.ssh/spdk_vhost_id_rsa" + end + + # Copy in the user's tools if they exists + if File.directory?(File.expand_path("~/vagrant_tools")) + config.vm.synced_folder "~/vagrant_tools", "/home/vagrant/tools", type: "rsync", rsync__auto: false + end +end diff --git a/src/spdk/scripts/vagrant/Vagrantfile_vhost_vm b/src/spdk/scripts/vagrant/Vagrantfile_vhost_vm new file mode 100644 index 00000000..2fd35540 --- /dev/null +++ b/src/spdk/scripts/vagrant/Vagrantfile_vhost_vm @@ -0,0 +1,111 @@ +# -*- mode: ruby -*- +# vi: set ft=ruby : + +Vagrant.configure(2) do |config| + + # Pick the right distro and bootstrap, default is ubuntu1604 + distro = ( ENV['SPDK_VAGRANT_DISTRO'] || "ubuntu16") + case distro + when "ubuntu16" + # See: https://app.vagrantup.com/puppetlabs/boxes/ubuntu-16.04-64-nocm + config.vm.box = "puppetlabs/ubuntu-16.04-64-nocm" + config.vm.box_version = "1.0.0" + when "ubuntu18" + # See: https://app.vagrantup.com/bento/boxes/ubuntu-18.04 + config.vm.box = "bento/ubuntu-18.04" + config.vm.box_version = "201808.24.0" + else + "Invalid argument #{distro}" + abort("Invalid argument!") + end + config.vm.box_check_update = false + + # vagrant-cachier caches apt/yum etc to speed subsequent + # vagrant up + # to enable, run + # vagrant plugin install vagrant-cachier + # + if Vagrant.has_plugin?("vagrant-cachier") + config.cache.scope = :box + end + + # use http proxy if avaiable + if ENV['http_proxy'] && Vagrant.has_plugin?("vagrant-proxyconf") + config.proxy.http = ENV['http_proxy'] + config.proxy.https = ENV['https_proxy'] + config.proxy.no_proxy = "localhost,127.0.0.1" + end + + vmcpu=(ENV['SPDK_VAGRANT_VMCPU'] || 2) + vmram=(ENV['SPDK_VAGRANT_VMRAM'] || 4096) + ssh_key_dir=(ENV['SPDK_VAGRANT_SSH_KEY']) + spdk_dir=(ENV['SPDK_DIR'] || "none") + install_deps=(ENV['INSTALL_DEPS'] || "false") + + config.ssh.forward_agent = true + config.ssh.forward_x11 = true + + # Change root passwd and allow root SSH + config.vm.provision "shell", inline: 'echo -e "root\nroot" | sudo passwd root' + config.vm.provision "shell", inline: 'sudo sh -c "echo \"PermitRootLogin yes\" >> /etc/ssh/sshd_config"' + + # Use previously generated SSH keys for setting up a key pair + $ssh_key_gen_script = <<-SCRIPT + sudo mkdir -p /root/.ssh + cat /vagrant/ssh_keys/spdk_vhost_id_rsa.pub > /root/.ssh/authorized_keys + sudo chmod 644 /root/.ssh/authorized_keys + SCRIPT + config.vm.provision "shell", inline: $ssh_key_gen_script + + # Install needed deps + $apt_script = <<-SCRIPT + sudo apt -y update + sudo DEBIAN_FRONTEND=noninteractive apt -y -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" upgrade + sudo apt -y install -y fio sg3-utils bc + SCRIPT + config.vm.provision "shell", inline: $apt_script + + # Modify GRUB options + # console=ttyS0 earlyprintk=ttyS0 - reroute output to serial dev, so that QEMU can write output to file + # scsi_mod.use_blk_mq=1 - for multiqueue use + # net.ifnames=0 biosdevname=0 - do not rename NICs on boot. That way we ensure that addded NIC is always eth0. + # Reason for these options is that NIC can have different udev name during provisioning with Vagrant + # and then some other name while running SPDK tests which use Qemu without any hypervisor like vbox or libvirt + # so no corresponding configuration for this NIC name will be present in /etc. + config.vm.provision "shell", inline: 'sudo sed -ir s#GRUB_CMDLINE_LINUX=\"\"#GRUB_CMDLINE_LINUX=\"console=ttyS0\ earlyprintk=ttyS0\ scsi_mod.use_blk_mq=1\ net.ifnames=0\ biosdevname=0\"#g /etc/default/grub' + config.vm.provision "shell", inline: 'sudo update-grub' + + # TODO: Next 2 lines break any future ssh communication via "vagrant ssh" + # I'd be good to check NIC names in ifconfig and then sed them in /etc/network/interfaces to eht0, eht1, and so on + config.vm.provision "shell", inline: 'sudo sh -c "echo \"auto eth0\" >> /etc/network/interfaces"' + config.vm.provision "shell", inline: 'sudo sh -c "echo \"iface eth0 inet dhcp\" >> /etc/network/interfaces"' + + if distro.include? "ubuntu18" + # This is to avoid annoying "Start job is running for wait for network to be configured" 2 minute timeout + # in case of not-so-perfect NIC and virtual network configuration for the VM + config.vm.provision "shell", inline: 'systemctl disable systemd-networkd-wait-online.service' + config.vm.provision "shell", inline: 'systemctl mask systemd-networkd-wait-online.service' + end + + config.vm.provider "virtualbox" do |vb| + vb.customize ["modifyvm", :id, "--ioapic", "on"] + vb.memory = "#{vmram}" + vb.cpus = "#{vmcpu}" + + #support for the SSE4.x instruction is required in some versions of VB. + vb.customize ["setextradata", :id, "VBoxInternal/CPUM/SSE4.1", "1"] + vb.customize ["setextradata", :id, "VBoxInternal/CPUM/SSE4.2", "1"] + end + + if spdk_dir != "none" + config.vm.synced_folder "#{spdk_dir}", "/home/vagrant/spdk_repo/spdk", type: "rsync", rsync__auto: false + if install_deps.include? "true" + config.vm.provision "shell", inline: 'sudo /home/vagrant/spdk_repo/spdk/scripts/pkgdep.sh' + end + end + + # Copy in the user's tools if they exists + if File.directory?(File.expand_path("~/vagrant_tools")) + config.vm.synced_folder "~/vagrant_tools", "/home/vagrant/tools", type: "rsync", rsync__auto: false + end +end |