Spdk/scripts/vagrant/Vagrantfile
Maciej Wawryk 344c318464 scripts/vagrant: Create prebuild box and allow using spdk boxes
Build local vagrant box and add it to local vagrant box list.
Check if spdk box exist and use it instead of generic boxes.

Signed-off-by: Maciej Wawryk <maciejx.wawryk@intel.com>
Change-Id: Ib3b87c9783354680657f96b5b5adea1706712c5e
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/848
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: Karol Latecki <karol.latecki@intel.com>
Reviewed-by: Tomasz Zawadzki <tomasz.zawadzki@intel.com>
Reviewed-by: Paul Luse <paul.e.luse@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
2020-02-17 10:06:09 +00:00

204 lines
8.3 KiB
Ruby

# -*- mode: ruby -*-
# vi: set ft=ruby :
require 'open3' def checkboxtype(distro)
localboxes, stderr, status = Open3.capture3("vagrant box list")
if localboxes.include? "spdk/"+distro
return "spdk/"+distro
else
return "generic/"+distro
end
end
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")
config.vm.box = checkboxtype(distro)
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
if ENV['VAGRANT_PASSWORD_AUTH'] == "1"
config.ssh.username = "vagrant"
config.ssh.password = "vagrant"
end
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