From 30dfc6d505f0fa8214bd6ef1dc6359d757451e51 Mon Sep 17 00:00:00 2001 From: Daniel Mrzyglod Date: Tue, 28 Nov 2017 15:04:51 +0100 Subject: [PATCH] scripts/vagrant: add vagrant-libvirt provider This patch add another provider for libvirt. There are still few additional problems in vagrant-libvirt like: -most recent vagrant-libvirt (0.0.39+) -most recent qemu 2.10+ -must be run as: vagrant up --provider=libvirt Change-Id: I6ad3497cd06bb1a490259c0afc93c6ea610967f8 Signed-off-by: Daniel Mrzyglod Reviewed-on: https://review.gerrithub.io/389551 Tested-by: SPDK Automated Test System Reviewed-by: Jim Harris Reviewed-by: Daniel Verkamp --- doc/vagrant.md | 13 ++++++++++- scripts/vagrant/Vagrantfile | 36 ++++++++++++++++++++++++++++++ scripts/vagrant/create_nvme_img.sh | 12 ++++++++++ 3 files changed, 60 insertions(+), 1 deletion(-) create mode 100755 scripts/vagrant/create_nvme_img.sh diff --git a/doc/vagrant.md b/doc/vagrant.md index 6ab92bec5..b5136a7e1 100644 --- a/doc/vagrant.md +++ b/doc/vagrant.md @@ -21,6 +21,8 @@ export https_proxy=... vagrant plugin install vagrant-proxyconf ~~~ +In case you want use kvm/libvirt you should also install `vagrant-libvirt` + # VM Configuration {#vagrant_config} This vagrant environment creates a VM based on environment variables found in `env.sh`. @@ -55,7 +57,16 @@ By default, the VM created is configured with: # Providers {#vagrant_providers} -Currently only the VirtualBox provider is supported. +Currently VirtualBox & libvirt provider are supported. + +For libvirt currently there is only centos 7 image avaiable. + +To run with libvirt: + +~~~{.sh} + ./create_nvme_img.sh + vagrant up --provider=libvirt +~~~ # Running An Example {#vagrant_example} diff --git a/scripts/vagrant/Vagrantfile b/scripts/vagrant/Vagrantfile index b707b1f61..2e243e046 100644 --- a/scripts/vagrant/Vagrantfile +++ b/scripts/vagrant/Vagrantfile @@ -8,6 +8,10 @@ Vagrant.configure(2) do |config| if distro == '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') else config.vm.box = "puppetlabs/ubuntu-16.04-64-nocm" end @@ -67,4 +71,36 @@ Vagrant.configure(2) do |config| 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| + + # 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) + override.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" + + # rsync the vpp directory if provision hasn't happened yet + unless File.exist? (".vagrant/machines/default/libvirt/action_provision") + config.vm.synced_folder "../../", "/spdk", type: "rsync" + end + + end + end diff --git a/scripts/vagrant/create_nvme_img.sh b/scripts/vagrant/create_nvme_img.sh new file mode 100755 index 000000000..8fb8ff84a --- /dev/null +++ b/scripts/vagrant/create_nvme_img.sh @@ -0,0 +1,12 @@ +#!/usr/bin/env bash +WHICH_OS=`lsb_release -i | awk '{print $3}'` +nvme_disk='/var/lib/libvirt/images/nvme_disk.img' + +qemu-img create -f raw $nvme_disk 1024M +#Change SE Policy on Fedora +if [ $WHICH_OS == "Fedora" ]; then + sudo chcon -t svirt_image_t $nvme_disk +fi + +chmod 777 $nvme_disk +chown qemu:qemu $nvme_disk