Spdk/scripts/vagrant/Vagrantfile
Karol Latecki e0a8a21dab scripts/vagrant: Adjust Vagrantfile for FreeBSD boxes
- Use "scsi" libvirt disk bus
  generic/freebsd boxes do not boot with default
  "virtio" bus
- Manually provision proxy settings
  Proxyconf plugin seems to not work with generic/freebsd boxes.
  Adjust shell and pkg proxy settings manually via scripts.
- Disable synced_folders provisioning
  FreeBSD boxes don't have rsync and NFS installed by default.
  Vagrantfile "synced_folders" step executes before "priovision"
  steps responsible for setting proxiy settings, therefore we
  are unable to install it.

Change-Id: I1386ec6e89cff6b8412e97e4df95a6149da2a02c
Signed-off-by: Karol Latecki <karol.latecki@intel.com>
Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/477805
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
Reviewed-by: Tomasz Zawadzki <tomasz.zawadzki@intel.com>
Community-CI: SPDK CI Jenkins <sys_sgci@intel.com>
2019-12-16 12:30:47 +00:00

225 lines
9.2 KiB
Ruby

# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure(2) do |config|
# Pick the right distro and bootstrap, default is fedora30
distro = ( ENV['SPDK_VAGRANT_DISTRO'] || "fedora30")
provider = (ENV['SPDK_VAGRANT_PROVIDER'] || "virtualbox")
case distro
when "centos7"
# See: https://app.vagrantup.com/generic/boxes/centos7
config.vm.box = "generic/centos7"
when "centos8"
# See: https://app.vagrantup.com/generic/boxes/centos8
config.vm.box = "generic/centos8"
when "ubuntu16"
#See: https://app.vagrantup.com/generic/boxes/ubuntu1604
config.vm.box = "generic/ubuntu1604"
when "ubuntu18"
#See: https://app.vagrantup.com/generic/boxes/ubuntu1804
config.vm.box = "generic/ubuntu1804"
when "fedora29"
#See: https://app.vagrantup.com/generic/boxes/fedora29
config.vm.box = "generic/fedora29"
when "fedora30"
#See: https://app.vagrantup.com/generic/boxes/fedora30
config.vm.box = "generic/fedora30"
when "fedora31"
#See: https://app.vagrantup.com/generic/boxes/fedora31
config.vm.box = "generic/fedora31"
when "freebsd11"
#See: https://app.vagrantup.com/generic/boxes/freebsd11
config.vm.box = "generic/freebsd11"
when "freebsd12"
#See: https://app.vagrantup.com/generic/boxes/freebsd12
config.vm.box = "generic/freebsd12"
when "arch-linux"
#See: https://app.vagrantup.com/generic/boxes/arch
config.vm.box = "generic/arch"
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")
$tsocks_copy = <<-SCRIPT
sudo -s
mv -f tsocks.conf /etc/tsocks.conf
chown root /etc/tsocks.conf
chmod 644 /etc/tsocks.conf
SCRIPT
config.vm.provision "file", source: "/etc/tsocks.conf", destination: "tsocks.conf"
config.vm.provision "shell", inline: $tsocks_copy
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
if (distro.include?("ubuntu"))
# Ubuntu boxes from generic/ubuntuX do not generate /etc/resolv.conf files properly which causes
# DNS to not work. Copy host /etc/resolv.conf file to the VM as a workaround.
config.vm.network "private_network", type: "dhcp"
config.vm.provision "file", source: "/etc/resolv.conf", destination: "/home/vagrant/resolv.conf"
config.vm.provision "shell", inline: "sudo mv -f /home/vagrant/resolv.conf /etc/resolv.conf"
end
# use http proxy if avaiable
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")
$freebsd_proxy = <<-SCRIPT
sudo -s
echo "export http_proxy=#{ENV['http_proxy']}" >> /etc/profile
echo "export https_proxy=#{ENV['http_proxy']}" >> /etc/profile
echo "pkg_env: {http_proxy: #{ENV['http_proxy']}}" > /usr/local/etc/pkg.conf
chown root:wheel /usr/local/etc/pkg.conf
chmod 644 /usr/local/etc/pkg.conf
SCRIPT
config.vm.provision "shell", inline: $freebsd_proxy
end
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")
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(',')
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=(ENV['NVME_FILE'] || "nvme_disk.img")
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"
# 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
if not vmemulator.empty?
libvirt.emulator_path = "#{vmemulator}"
end
# we put nvme_disk inside default pool to eliminate libvirt/SELinux Permissions Problems
# and to be able to run vagrant from user $HOME directory
# 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"
if nvme_namespaces["#{index}".to_i].nil? || nvme_namespaces["#{index}".to_i] == "1"
libvirt.qemuargs :value => "nvme,drive=#{nvme_disk_id},serial=1234#{index}"
else
libvirt.qemuargs :value => "nvme,drive=#{nvme_disk_id},serial=1234#{index},namespaces=#{nvme_namespaces["#{index}".to_i]}"
end
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
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=/var/lib/libvirt/images/ocssd_md,nsdatafile=/var/lib/libvirt/images/ocssd_blknvme.ns,laer_thread_sleep=3000,stride=4"
end
}
libvirt.driver = "kvm"
libvirt.graphics_type = "vnc"
libvirt.memory = "#{vmram}"
libvirt.cpus = "#{vmcpu}"
libvirt.video_type = "cirrus"
# 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
# Warning: rsync does not work with freebsd boxes, so this step is disabled
if ENV['COPY_SPDK_DIR'] == "1" && spdk_dir != "none" && !distro.include?("freebsd")
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