2017-04-28 17:18:24 +00:00
|
|
|
# -*- mode: ruby -*-
|
|
|
|
# vi: set ft=ruby :
|
|
|
|
|
2020-02-18 07:44:56 +00:00
|
|
|
require 'open3'
|
|
|
|
def checkboxtype(distro)
|
2020-02-13 07:07:21 +00:00
|
|
|
localboxes, stderr, status = Open3.capture3("vagrant box list")
|
|
|
|
if localboxes.include? "spdk/"+distro
|
|
|
|
return "spdk/"+distro
|
|
|
|
else
|
2020-04-01 07:50:06 +00:00
|
|
|
case distro
|
|
|
|
when "centos7"
|
|
|
|
return "centos/7"
|
|
|
|
when "centos8"
|
|
|
|
return "centos/8"
|
|
|
|
when "ubuntu1604"
|
|
|
|
return "peru/ubuntu-16.04-server-amd64"
|
|
|
|
when "ubuntu1804"
|
|
|
|
return "peru/ubuntu-18.04-server-amd64"
|
|
|
|
when "fedora30"
|
|
|
|
return "generic/fedora30"
|
|
|
|
when "fedora31"
|
|
|
|
return "generic/fedora31"
|
|
|
|
when "arch"
|
|
|
|
return "generic/arch"
|
|
|
|
when "freebsd11"
|
|
|
|
return "generic/freebsd11"
|
|
|
|
when "freebsd12"
|
|
|
|
return "generic/freebsd12"
|
2020-05-27 14:34:21 +00:00
|
|
|
when "clearlinux"
|
|
|
|
return "AntonioMeireles/ClearLinux"
|
2020-04-01 07:50:06 +00:00
|
|
|
else
|
|
|
|
"Invalid argument #{distro}"
|
|
|
|
abort("Invalid argument!")
|
|
|
|
end
|
2020-02-13 07:07:21 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-04-28 17:18:24 +00:00
|
|
|
Vagrant.configure(2) do |config|
|
|
|
|
|
2019-11-29 10:26:50 +00:00
|
|
|
# Pick the right distro and bootstrap, default is fedora30
|
|
|
|
distro = ( ENV['SPDK_VAGRANT_DISTRO'] || "fedora30")
|
2018-11-24 13:42:34 +00:00
|
|
|
provider = (ENV['SPDK_VAGRANT_PROVIDER'] || "virtualbox")
|
2020-03-30 10:15:36 +00:00
|
|
|
|
2020-06-18 11:13:44 +00:00
|
|
|
# Get all variables for creating vm
|
|
|
|
vmcpu=(ENV['SPDK_VAGRANT_VMCPU'] || 2)
|
|
|
|
vmram=(ENV['SPDK_VAGRANT_VMRAM'] || 4096)
|
|
|
|
spdk_dir=(ENV['SPDK_DIR'] || "none")
|
|
|
|
vmemulator=(ENV['SPDK_QEMU_EMULATOR'] || "")
|
|
|
|
emulated_nvme_types=(ENV['NVME_DISKS_TYPE'] || "nvme").split(',')
|
|
|
|
nvme_namespaces=(ENV['NVME_DISKS_NAMESPACES'] || "").split(',')
|
|
|
|
nvme_file=(ENV['NVME_FILE'] || "").split(',')
|
|
|
|
nvme_cmbs=(ENV['NVME_CMB'] || "").split(',')
|
|
|
|
vagrantfile_dir=(ENV['VAGRANTFILE_DIR'] || "none")
|
|
|
|
|
2020-03-30 10:15:36 +00:00
|
|
|
# generic/freebsd boxes do not work properly with vagrant-proxyconf and
|
|
|
|
# have issues installing rsync and sshfs for syncing files. NFS is
|
|
|
|
# pre-installed, so use it.
|
|
|
|
# generic/fedora boxes on the other hand have problems running NFS
|
|
|
|
# service so use sshfs+rsync combo instead.
|
|
|
|
plugins_sync_backend = {type: :sshfs}
|
|
|
|
files_sync_backend = {type: "rsync", rsync__auto: false}
|
|
|
|
if distro.include? "freebsd"
|
|
|
|
plugins_sync_backend = {type: :nfs, nfs_udp: false}
|
|
|
|
files_sync_backend = {type: :nfs, nfs_udp: false, mount_options: ['ro']}
|
|
|
|
end
|
2020-02-13 07:07:21 +00:00
|
|
|
config.vm.box = checkboxtype(distro)
|
2017-04-28 17:18:24 +00:00
|
|
|
config.vm.box_check_update = false
|
2020-03-05 14:25:15 +00:00
|
|
|
config.vm.synced_folder '.', '/vagrant', disabled: true
|
2017-04-28 17:18:24 +00:00
|
|
|
|
|
|
|
# Copy in the .gitconfig if it exists
|
|
|
|
if File.file?(File.expand_path("~/.gitconfig"))
|
|
|
|
config.vm.provision "file", source: "~/.gitconfig", destination: ".gitconfig"
|
|
|
|
end
|
|
|
|
|
2018-09-26 17:11:36 +00:00
|
|
|
# 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"
|
2020-06-18 13:03:08 +00:00
|
|
|
config.vm.provision "shell" do |setup|
|
|
|
|
setup.path = "#{spdk_dir}/scripts/vagrant/vagrantfiles/tsocks_setup.sh"
|
|
|
|
setup.privileged = true
|
|
|
|
end
|
2018-09-26 17:11:36 +00:00
|
|
|
end
|
|
|
|
|
2017-04-28 17:18:24 +00:00
|
|
|
# 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
|
2020-03-30 10:15:36 +00:00
|
|
|
config.cache.synced_folder_opts = plugins_sync_backend
|
2017-04-28 17:18:24 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
# use http proxy if avaiable
|
2019-12-12 12:28:09 +00:00
|
|
|
if ENV['http_proxy']
|
|
|
|
if 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
|
|
|
|
|
|
|
|
# Proxyconf does not seem to support FreeBSD boxes or at least it's
|
|
|
|
# docs do not mention that. Set up proxy configuration manually.
|
|
|
|
if distro.include?("freebsd")
|
2020-06-18 13:03:08 +00:00
|
|
|
config.vm.provision "shell" do |setup|
|
|
|
|
setup.path = "#{spdk_dir}/scripts/vagrant/vagrantfiles/freebsd_proxy.sh"
|
|
|
|
setup.privileged = true
|
|
|
|
setup.args = ["#{ENV['http_proxy']}"]
|
|
|
|
end
|
2019-12-12 12:28:09 +00:00
|
|
|
end
|
2017-04-28 17:18:24 +00:00
|
|
|
end
|
|
|
|
|
2020-03-30 10:15:36 +00:00
|
|
|
# freebsd boxes in order to have spdk sources synced from host properly
|
|
|
|
# will use NFS with "ro" option enabled to prevent changes on host filesystem.
|
|
|
|
# To make sources usable in the guest VM we need to unmount them and use
|
|
|
|
# local copy.
|
|
|
|
if distro.include?("freebsd")
|
2020-06-18 13:03:08 +00:00
|
|
|
config.vm.provision "shell" do |setup|
|
|
|
|
setup.path = "#{spdk_dir}/scripts/vagrant/vagrantfiles/freebsd_spdk_repo.sh"
|
|
|
|
setup.privileged = true
|
|
|
|
end
|
2020-03-30 10:15:36 +00:00
|
|
|
end
|
|
|
|
|
2017-04-28 17:18:24 +00:00
|
|
|
config.ssh.forward_agent = true
|
|
|
|
config.ssh.forward_x11 = true
|
2019-12-06 14:16:04 +00:00
|
|
|
if ENV['VAGRANT_PASSWORD_AUTH'] == "1"
|
|
|
|
config.ssh.username = "vagrant"
|
|
|
|
config.ssh.password = "vagrant"
|
|
|
|
end
|
2017-04-28 17:18:24 +00:00
|
|
|
|
|
|
|
config.vm.provider "virtualbox" do |vb|
|
2018-06-19 03:58:46 +00:00
|
|
|
vb.customize ["modifyvm", :id, "--ioapic", "on"]
|
|
|
|
vb.memory = "#{vmram}"
|
|
|
|
vb.cpus = "#{vmcpu}"
|
|
|
|
|
2018-11-06 18:05:10 +00:00
|
|
|
nvme_disk=(ENV['NVME_FILE'] || "nvme_disk.img")
|
2018-06-19 03:58:46 +00:00
|
|
|
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"]
|
2017-04-28 17:18:24 +00:00
|
|
|
end
|
2017-11-28 14:04:51 +00:00
|
|
|
|
|
|
|
# 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|
|
2018-08-10 14:11:02 +00:00
|
|
|
libvirt.random_hostname = "1"
|
|
|
|
libvirt.disk_bus = "virtio"
|
2019-12-12 12:28:09 +00:00
|
|
|
|
|
|
|
# generic/freebsd boxes need to be explicitly run with SCSI bus,
|
|
|
|
# otherwise boot process fails on mounting the disk
|
|
|
|
if (distro.include?("freebsd"))
|
|
|
|
libvirt.disk_bus = "scsi"
|
|
|
|
end
|
|
|
|
|
2019-08-21 12:50:29 +00:00
|
|
|
if not vmemulator.empty?
|
|
|
|
libvirt.emulator_path = "#{vmemulator}"
|
2020-03-12 13:21:16 +00:00
|
|
|
libvirt.machine_type = "pc"
|
2019-08-21 12:50:29 +00:00
|
|
|
end
|
2017-11-28 14:04:51 +00:00
|
|
|
|
2018-06-19 03:58:46 +00:00
|
|
|
# we put nvme_disk inside default pool to eliminate libvirt/SELinux Permissions Problems
|
|
|
|
# and to be able to run vagrant from user $HOME directory
|
2018-11-06 18:05:10 +00:00
|
|
|
|
2019-08-28 14:08:21 +00:00
|
|
|
# Loop to create all emulated disks set
|
|
|
|
emulated_nvme_types.each_with_index { |disk, index|
|
|
|
|
if ENV['NVME_FILE']
|
|
|
|
nvme_disk_id="#{disk}" + "-#{index}"
|
|
|
|
nvme_disk="#{nvme_file["#{index}".to_i]}"
|
|
|
|
else
|
|
|
|
nvme_disk="/var/lib/libvirt/images/nvme_disk.img"
|
|
|
|
end
|
|
|
|
|
|
|
|
unless File.exist? (nvme_disk)
|
|
|
|
puts "If run with libvirt provider please execute create_nvme_img.sh"
|
|
|
|
end
|
|
|
|
|
|
|
|
if disk == "nvme"
|
|
|
|
libvirt.qemuargs :value => "-drive"
|
|
|
|
libvirt.qemuargs :value => "format=raw,file=#{nvme_disk},if=none,id=#{nvme_disk_id}"
|
|
|
|
libvirt.qemuargs :value => "-device"
|
2020-06-18 11:10:41 +00:00
|
|
|
nvme_drive = "nvme,drive=#{nvme_disk_id},serial=1234#{index}"
|
2020-06-01 12:54:15 +00:00
|
|
|
if !nvme_namespaces["#{index}".to_i].nil? && nvme_namespaces["#{index}".to_i] != 1
|
|
|
|
nvme_drive << ",namespaces=#{nvme_namespaces["#{index}".to_i]}"
|
2019-08-28 14:08:21 +00:00
|
|
|
end
|
2020-06-01 12:54:15 +00:00
|
|
|
if !nvme_cmbs["#{index}".to_i].nil? && nvme_cmbs["#{index}".to_i] == "true"
|
|
|
|
# Fix the size of the buffer to 128M
|
|
|
|
nvme_drive << ",cmb_size_mb=128"
|
|
|
|
end
|
|
|
|
libvirt.qemuargs :value => nvme_drive
|
2019-08-28 14:08:21 +00:00
|
|
|
elsif disk == "ocssd"
|
|
|
|
libvirt.qemuargs :value => "-drive"
|
|
|
|
libvirt.qemuargs :value => "format=raw,file=#{nvme_disk},if=none,id=#{nvme_disk_id}"
|
|
|
|
libvirt.qemuargs :value => "-device"
|
|
|
|
# create ocssd drive with special parameters
|
|
|
|
# lba_index=4 it is LBA namespace format, 4 means that block size is 4K and have 64B metadata
|
|
|
|
# lnum_lun, lnum_pln, lpgs_per_blk, lsecs_per_pg, lblks_per_pln this are parameters describing the device geometry
|
|
|
|
# we need to multiply these parameters by ourselves to have backend file minimal size:
|
|
|
|
# in our case: 4K * 8 * 2 * 1536 * 2 * 45 = 8640 MB
|
2020-03-26 11:24:45 +00:00
|
|
|
libvirt.qemuargs :value => "nvme,drive=#{nvme_disk_id},serial=deadbeef,oacs=0,namespaces=1,lver=2,lba_index=4,mdts=10,lnum_lun=8,lnum_pln=2,lpgs_per_blk=1536,lsecs_per_pg=2,lblks_per_pln=45,metadata=#{nvme_disk}_ocssd_md,nsdatafile=#{nvme_disk}_ocssd_blknvme.ns,laer_thread_sleep=3000,stride=4"
|
2019-08-28 14:08:21 +00:00
|
|
|
end
|
|
|
|
}
|
2018-06-19 03:58:46 +00:00
|
|
|
|
|
|
|
libvirt.driver = "kvm"
|
2019-08-21 12:50:29 +00:00
|
|
|
libvirt.graphics_type = "vnc"
|
2018-06-19 03:58:46 +00:00
|
|
|
libvirt.memory = "#{vmram}"
|
|
|
|
libvirt.cpus = "#{vmcpu}"
|
2019-08-21 12:50:29 +00:00
|
|
|
libvirt.video_type = "cirrus"
|
2018-06-19 03:58:46 +00:00
|
|
|
|
2020-04-06 08:19:31 +00:00
|
|
|
if ENV['VAGRANT_HUGE_MEM'] == "1"
|
|
|
|
libvirt.memorybacking :hugepages
|
|
|
|
end
|
|
|
|
|
2018-06-19 03:58:46 +00:00
|
|
|
# Optional field if we want use other storage pools than default
|
|
|
|
# libvirt.storage_pool_name = "vm"
|
2018-08-14 13:36:43 +00:00
|
|
|
end
|
2018-06-19 03:58:46 +00:00
|
|
|
|
2018-08-14 13:36:43 +00:00
|
|
|
# rsync the spdk directory if provision hasn't happened yet
|
2019-12-12 12:28:09 +00:00
|
|
|
# Warning: rsync does not work with freebsd boxes, so this step is disabled
|
2020-03-30 10:15:36 +00:00
|
|
|
if ENV['COPY_SPDK_DIR'] == "1" && spdk_dir != "none"
|
|
|
|
config.vm.synced_folder "#{spdk_dir}", "/home/vagrant/spdk_repo/spdk", files_sync_backend
|
2018-08-14 13:36:43 +00:00
|
|
|
end
|
|
|
|
|
2020-02-27 14:43:13 +00:00
|
|
|
# rsync artifacts from build
|
|
|
|
if ENV['COPY_SPDK_ARTIFACTS'] == "1"
|
2020-03-30 10:15:36 +00:00
|
|
|
config.vm.synced_folder "#{vagrantfile_dir}/output", "/home/vagrant/spdk_repo/output", plugins_sync_backend
|
2020-02-27 14:43:13 +00:00
|
|
|
end
|
|
|
|
|
2018-09-26 17:11:36 +00:00
|
|
|
# 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
|
|
|
|
|
2020-05-27 15:21:50 +00:00
|
|
|
# Clear CFLAGS in clear linux
|
|
|
|
if distro == "clearlinux"
|
2020-06-18 13:03:08 +00:00
|
|
|
config.vm.provision "shell" do |setup|
|
|
|
|
setup.path = "#{spdk_dir}/scripts/vagrant/vagrantfiles/clearlinux_cflags.sh"
|
|
|
|
setup.privileged = false
|
|
|
|
end
|
2020-05-27 15:21:50 +00:00
|
|
|
end
|
|
|
|
|
2018-08-14 13:36:43 +00:00
|
|
|
# Copy in the user's tools if they exists
|
|
|
|
if File.directory?(File.expand_path("~/vagrant_tools"))
|
2020-03-30 10:15:36 +00:00
|
|
|
config.vm.synced_folder "~/vagrant_tools", "/home/vagrant/tools", files_sync_backend
|
2018-06-19 03:58:46 +00:00
|
|
|
end
|
2017-04-28 17:18:24 +00:00
|
|
|
end
|