diff --git a/scripts/vagrant/README.md b/scripts/vagrant/README.md new file mode 100644 index 0000000000..ddef9ba80a --- /dev/null +++ b/scripts/vagrant/README.md @@ -0,0 +1,214 @@ +# SPDK Vagrant and VirtualBox + +The following guide explains how to use the scripts in the `spdk/scripts/vagrant`. Both Mac and Windows platforms are supported. + +1. Install and configure [Git](https://git-scm.com/) on your platform. +2. Install [VirtualBox 5.1](https://www.virtualbox.org/wiki/Downloads) or newer +3. Install [VirtualBox Extension Pack](https://www.virtualbox.org/wiki/Downloads) +4. Install and configure [Vagrant 1.9.4](https://www.vagrantup.com) or newer + +## Mac OSX Setup (High Sierra) + +OSX platforms already have Git installed, however, installing the [Apple xCode](https://developer.apple.com/xcode/) developer kit and [xCode Command Line tools](https://developer.apple.com/xcode/features/) will provide UNIX command line tools such as make, awk, sed, ssh, tar, and zip. xCode can be installed through the App Store on you Mac. + +Quick start instructions for OSX: + +1. Install Homebrew +2. Install Virtual Box Cask +3. Install Virtual Box Extentions +4. Install Vagrant Cask + +``` + /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" + brew doctor + brew update + brew cask install virtualbox + brew cask install virtualbox-extension-pack + brew cask install vagrant +``` + +## Windows 10 Setup + +1. Windows platforms should install [Git](https://git-scm.com/download/win) from git-scm.com. + - This provides everything needed to use git on Windows, including a `git-bash` command line environment. +2. Install [VirtualBox 5.1](https://www.virtualbox.org/wiki/Downloads) or newer +3. Install [VirtualBox Extension Pack](https://www.virtualbox.org/wiki/Downloads) +4. Install and configure [Vagrant 1.9.4](https://www.vagrantup.com) or newer + +- Note: VirtualBox requires virtualization to be enabled in the BIOS. +- Note: You should disable Hyper-V in Windows RS 3 laptop. Search `windows features` uncheck Hyper-V, restart laptop + +## Configure Vagrant + +If you are behind a corporate firewall, configure the following proxy settings. + +1. Set the http_proxy and https_proxy +2. Install the proxyconf plugin + +``` + $ export http_proxy=.... + $ export https_proxy=.... + $ vagrant plugin install vagrant-proxyconf +``` + +## Download SPDK from GitHub + +Use git to clone a new spdk repository. GerritHub can also be used. See the instructions at [spdk.io](http://www.spdk.io/development/#gerrithub) to setup your GerritHub account. Note that this spdk repository will be rsync'd into your VM, so you can use this repository to continue development within the VM. + +## Create a Virtual Box + +Use the `spdk/scripts/vagrant/create_vbox.sh` script to create a VM of your choice. Supported VM platforms are: + +- centos7 +- ubuntu16 +- ubuntu18 +- fedora26 +- fedora27 +- freebsd11 + +``` +$ spdk/scripts/vagrant/create_vbox.sh -h + Usage: create_vbox.sh [-n ] [-s ] [-x ] [-hvr] + + distro = + + -s in kb default: 4096 + -n 1 to 4 default: 4 + -x default: "" + -r dry-run + -h help + -v verbose + + Examples: + + spdk/scripts/vagrant/create_vbox.sh -x http://user:password@host:port fedora27 + spdk/scripts/vagrant/create_vbox.sh -s 2048 -n 2 ubuntu16 + spdk/scripts/vagrant/create_vbox.sh -rv freebsd + spdk/scripts/vagrant/create_vbox.sh fedora26 +``` + +It is recommended that you call the `create_vbox.sh` script from outside of the spdk repository. Call this script from a parent directory. This will allow the creation of multiple VMs in separate directories, all using the same spdk repository. For example: + +``` + $ spdk/scripts/vagrant/create_vbox.sh -s 2048 -n 2 fedora26 +``` + +This script will: + +1. create a subdirectory named in your $PWD +2. copy the needed files from `spdk/scripts/vagrant/` into the directory +3. create a working virtual box in the directory +4. rsycn the `~/.gitconfig` file to `/home/vagrant/` in the newly provisioned virtual box +5. rsync a copy of the source `spdk` repository to `/home/vagrant/spdk_repo/spdk` +6. rsync a copy of the `~/vagrant_tools` directory to `/home/vagrant/tools` (optional) + +This arrangement allows the provisioning of multiple, different VMs within that same directory hiearchy using the same spdk repository. Following the creation of the vm you'll need to ssh into your virtual box and finish the VM initializaton. + +``` + $ cd + $ vagrant ssh +``` + +## Finish VM Initializtion + +A copy of the `spdk` repository you cloned will exist in the `spdk_repo` directory of the `/home/vagrant` user account. After using `vagrant ssh` to enter your VM you must complete the initialization of your VM by running the `scripts/vagrant/update.sh` script. For example: + +``` + $ script -c 'sudo spdk_repo/spdk/scripts/vagrant/update.sh' update.log +``` + +The `update.sh` script completes initialization of the VM by automating the following steps. + +1. Runs yum/apt-get update (Linux) +2. Runs the scripts/pdkdep.sh script +3. Installs the FreeBSD source in /usr/sys (FreeBSD only) + +This only needs to be done once. + +## Post VM Initializtion + +Following VM initializtion you must: + +1. Verify you have an emulated NVMe device +2. Compile your spdk source tree +3. Run the hello_world example to validate the environment is set up correctly + +### Verify you have an emulated NVMe device + +``` + $ lspci | grep "Non-Volatile" + 00:0e.0 Non-Volatile memory controller: InnoTek Systemberatung GmbH Device 4e56 +``` + +### Compile SPDK + +``` + $ cd spdk_repo/spdk + $ git submodule update --init + $ ./configure --enable-debug + $ make +``` + +### Run the hello_world example script + +``` + $ sudo scripts/setup.sh + $ sudo examples/bdev/hello_world/hello_bdev +``` + +## Additional Setup for Fedora 26 + +As of this writing the `vm_setup.sh` script only supports Fedora 26. To complete the full installation of all packages needed to run autotest.sh on your fedora26 VM, run the `spdk/test/common/config/vm_setup.sh` script. Note: this will take some time. It is recommended that the output of vm_setup.sh is captured in a script log. + +``` + $ script -c 'spdk_repo/spdk/test/common/config/vm_setup.sh -i -t librxe,iscsi,rocksdb,fio,flamegraph,libiscsi' vm_setup.log +``` + +### Running autorun.sh with vagrant + +After running vm_setup.sh the `run-autorun.sh` can be used to run `spdk/autorun.sh` on a Fedora 26 vagrant machine. Note that the `spdk/scripts/vagrant/autorun-spdk.conf` should be copied to `~/autorun-spdk.conf` before starting your tests. + +``` + $ cp spdk/scripts/vagrant/autorun-spdk.conf ~/ + $ spdk/scripts/vagrant/run-autorun.sh -h + Usage: scripts/vagrant/run-autorun.sh -d [-h] | [-q] | [-n] + -d : Specify a path to an SPDK source tree + -q : No output to screen + -n : Noop - dry-run + -h : This help + + Examples: + run-spdk-autotest.sh -d . -q + run-spdk-autotest.sh -d /home/vagrant/spdk_repo/spdk +``` + +## FreeBSD Appendix + +--- +**NOTE:** As of this writing the FreeBSD Virtualbox instance does not correctly support the vagrant-proxyconf feature. +--- + +The following steps are done by the `update.sh` script. It is recommened that you capture the output of `update.sh` with a typescript. E.g.: + +``` + $ script update.log sudo spdk_repo/spdk/scripts/vagrant/update.sh +``` + +1. Updates the pkg catalog +1. Installs the needed FreeBSD packages on the system by calling pkgdep.sh +2. Installs the FreeBSD source in /usr/src + +``` + $ sudo pkg upgrade -f + $ sudo spdk_repo/spdk/scripts/pkgdep.sh + $ sudo git clone --depth 10 -b releases/11.1.0 https://github.com/freebsd/freebsd.git /usr/src +``` + +To build spdk on FreeBSD use `gmake MAKE=gmake`. E.g.: + +``` + $ cd spdk_repo/spdk + $ git submodule update --init + $ ./configure --enable-debug + $ gmake MAKE=gmake +``` diff --git a/scripts/vagrant/Vagrantfile b/scripts/vagrant/Vagrantfile index 2e243e0469..3be024c3ed 100644 --- a/scripts/vagrant/Vagrantfile +++ b/scripts/vagrant/Vagrantfile @@ -4,23 +4,38 @@ Vagrant.configure(2) do |config| # Pick the right distro and bootstrap, default is ubuntu1604 - distro = ( ENV['SPDK_VAGRANT_DISTRO'] || "ubuntu1604") - if distro == 'centos7' + 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" + config.vm.box = "centos/7" end if Vagrant.has_plugin?('vagrant-libvirt') - else + 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 "freebsd11" + #See: https://app.vagrantup.com/generic/boxes/freebsd11 + config.vm.box = "generic/freebsd11" + else + "Invalid argument #{distro}" + abort("Invalid argument!") end config.vm.box_check_update = false - config.vm.provision :shell, :path => File.join(File.dirname(__FILE__),"update.sh") - config.vm.provision :shell, :path => File.join(File.dirname(__FILE__),"build.sh") - config.vm.provision :shell, inline: "/spdk/scripts/setup.sh", run: "always" - # Copy in the .gitconfig if it exists if File.file?(File.expand_path("~/.gitconfig")) config.vm.provision "file", source: "~/.gitconfig", destination: ".gitconfig" @@ -46,30 +61,38 @@ Vagrant.configure(2) do |config| vmcpu=(ENV['SPDK_VAGRANT_VMCPU'] || 2) vmram=(ENV['SPDK_VAGRANT_VMRAM'] || 4096) + spdk_dir=(ENV['SPDK_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}" + vb.customize ["modifyvm", :id, "--ioapic", "on"] + vb.memory = "#{vmram}" + vb.cpus = "#{vmcpu}" - # rsync the vpp directory if provision hasn't happened yet - unless File.exist? (".vagrant/machines/default/virtualbox/action_provision") - config.vm.synced_folder "../../", "/spdk", type: "rsync", rsync__auto: false + # rsync the spdk directory if provision hasn't happened yet + unless File.exist? (".vagrant/machines/default/virtualbox/action_provision") + if spdk_dir != "none" + config.vm.synced_folder "#{spdk_dir}", "/home/vagrant/spdk_repo/spdk", type: "rsync", rsync__auto: false end - 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"] + # 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 - #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"] + 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 @@ -77,30 +100,31 @@ Vagrant.configure(2) do |config| # 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" + # 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 spdk directory if provision hasn't happened yet + unless File.exist? (".vagrant/machines/default/virtualbox/action_provision") + if spdk_dir != "none" + config.vm.synced_folder "#{spdk_dir}", "/home/vagrant/spdk_repo/spdk", type: "rsync" 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 + end end diff --git a/scripts/vagrant/autorun-spdk.conf b/scripts/vagrant/autorun-spdk.conf new file mode 100644 index 0000000000..4a815a518e --- /dev/null +++ b/scripts/vagrant/autorun-spdk.conf @@ -0,0 +1,28 @@ +# assign a value of 1 to all of the pertinent tests +SPDK_BUILD_DOC=1 +SPDK_RUN_CHECK_FORMAT=1 +SPDK_RUN_SCANBUILD=1 +SPDK_RUN_VALGRIND=1 +SPDK_TEST_UNITTEST=1 +SPDK_TEST_ISCSI=0 +SPDK_TEST_ISCSI_INITIATOR=0 +SPDK_TEST_NVME=0 +SPDK_TEST_NVME_CLI=0 +SPDK_TEST_NVMF=1 +SPDK_TEST_RBD=0 +# requires some extra configuration. see TEST_ENV_SETUP_README +SPDK_TEST_VHOST=0 +SPDK_TEST_VHOST_INIT=0 +SPDK_TEST_BLOCKDEV=1 +# doesn't work on vm +SPDK_TEST_IOAT=0 +SPDK_TEST_EVENT=1 +SPDK_TEST_BLOBFS=0 +SPDK_TEST_PMDK=0 +SPDK_TEST_LVOL=0 +SPDK_RUN_ASAN=1 +SPDK_RUN_UBSAN=1 +# Reduce the size of the hugepages +HUGEMEM=1024 +# Set up the DEPENDENCY_DIR +DEPENDENCY_DIR=/home/vagrant diff --git a/scripts/vagrant/build.sh b/scripts/vagrant/build.sh deleted file mode 100755 index a0a133f243..0000000000 --- a/scripts/vagrant/build.sh +++ /dev/null @@ -1,39 +0,0 @@ -#!/bin/bash - -SPDK_DIR=/spdk - -SUDOCMD="sudo -H -u vagrant" -echo 0:$0 -echo 1:$1 -echo 2:$2 -echo SUDOCMD: $SUDOCMD - -# Figure out what system we are running on -if [ -f /etc/lsb-release ];then - . /etc/lsb-release -elif [ -f /etc/redhat-release ];then - sudo yum install -y redhat-lsb - DISTRIB_ID=`lsb_release -si` - DISTRIB_RELEASE=`lsb_release -sr` - DISTRIB_CODENAME=`lsb_release -sc` - DISTRIB_DESCRIPTION=`lsb_release -sd` -fi -KERNEL_OS=`uname -o` -KERNEL_MACHINE=`uname -m` -KERNEL_RELEASE=`uname -r` -KERNEL_VERSION=`uname -v` - -echo KERNEL_OS: $KERNEL_OS -echo KERNEL_MACHINE: $KERNEL_MACHINE -echo KERNEL_RELEASE: $KERNEL_RELEASE -echo KERNEL_VERSION: $KERNEL_VERSION -echo DISTRIB_ID: $DISTRIB_ID -echo DISTRIB_RELEASE: $DISTRIB_RELEASE -echo DISTRIB_CODENAME: $DISTRIB_CODENAME -echo DISTRIB_DESCRIPTION: $DISTRIB_DESCRIPTION - -cd $SPDK_DIR -./scripts/pkgdep.sh -$SUDOCMD ./configure --enable-debug -$SUDOCMD make clean -$SUDOCMD make -j2 diff --git a/scripts/vagrant/create_nvme_img.sh b/scripts/vagrant/create_nvme_img.sh index 8fb8ff84aa..07ed3555cb 100755 --- a/scripts/vagrant/create_nvme_img.sh +++ b/scripts/vagrant/create_nvme_img.sh @@ -1,12 +1,16 @@ #!/usr/bin/env bash -WHICH_OS=`lsb_release -i | awk '{print $3}'` -nvme_disk='/var/lib/libvirt/images/nvme_disk.img' +SYSTEM=`uname -s` -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 +if [ ! "${SYSTEM}" = "FreeBSD" ]; then + 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 fi - -chmod 777 $nvme_disk -chown qemu:qemu $nvme_disk diff --git a/scripts/vagrant/create_vbox.sh b/scripts/vagrant/create_vbox.sh new file mode 100755 index 0000000000..88f5647db2 --- /dev/null +++ b/scripts/vagrant/create_vbox.sh @@ -0,0 +1,165 @@ +#!/bin/sh -e + +# create_vbox.sh +# +# Creates a virtual box with vagrant in the $PWD. +# +# This script creates a subdirectory called $PWD/ and copies the Vagrantfile +# into that directory before running 'vagrant up' + +VAGRANT_TARGET="$PWD" + +DIR="$( cd "$( dirname $0 )" && pwd )" +SPDK_DIR="$( cd "${DIR}/../../" && pwd )" + +# The command line help +display_help() { + echo + echo " Usage: ${0##*/} [-n ] [-s ] [-x ] [-hvr] " + echo + echo " distro = " + echo + echo " -s in kb default: ${SPDK_VAGRANT_VMRAM}" + echo " -n 1 to 4 default: ${SPDK_VAGRANT_VMCPU}" + echo " -x default: \"${SPDK_VAGRANT_HTTP_PROXY}\"" + echo " -r dry-run" + echo " -h help" + echo " -v verbose" + echo + echo " Examples:" + echo + echo " $0 -x http://user:password@host:port fedora27" + echo " $0 -s 2048 -n 2 ubuntu16" + echo " $0 -rv freebsd" + echo " $0 fedora26 " + echo +} + +# Set up vagrant proxy. Assumes git-bash on Windows +# https://stackoverflow.com/questions/19872591/how-to-use-vagrant-in-a-proxy-environment +SPDK_VAGRANT_HTTP_PROXY="" + +VERBOSE=0 +HELP=0 +DRY_RUN=0 +SPDK_VAGRANT_DISTRO="distro" +SPDK_VAGRANT_VMCPU=4 +SPDK_VAGRANT_VMRAM=4096 +OPTIND=1 + +while getopts ":n:s:x:vrh" opt; do + case "${opt}" in + x) + http_proxy=$OPTARG + https_proxy=$http_proxy + SPDK_VAGRANT_HTTP_PROXY="${http_proxy}" + ;; + n) + SPDK_VAGRANT_VMCPU=$OPTARG + ;; + s) + SPDK_VAGRANT_VMRAM=$OPTARG + ;; + v) + VERBOSE=1 + ;; + r) + DRY_RUN=1 + ;; + h) + display_help >&2 + exit 0 + ;; + *) + echo " Invalid argument: -$OPTARG" >&2 + echo " Try: \"$0 -h\"" >&2 + exit 1 + ;; + esac +done + +shift "$((OPTIND-1))" # Discard the options and sentinel -- + +SPDK_VAGRANT_DISTRO="$@" + +case "$SPDK_VAGRANT_DISTRO" in + centos7) + export SPDK_VAGRANT_DISTRO + ;; + ubuntu16) + export SPDK_VAGRANT_DISTRO + ;; + ubuntu18) + export SPDK_VAGRANT_DISTRO + ;; + fedora26) + export SPDK_VAGRANT_DISTRO + ;; + fedora27) + export SPDK_VAGRANT_DISTRO + ;; + freebsd11) + export SPDK_VAGRANT_DISTRO + ;; + *) + echo " Invalid argument \"${SPDK_VAGRANT_DISTRO}\"" + echo " Try: \"$0 -h\"" >&2 + exit 1 + ;; +esac + +if [ ${VERBOSE} = 1 ]; then + echo + echo DIR=${DIR} + echo SPDK_DIR=${SPDK_DIR} + echo VAGRANT_TARGET=${VAGRANT_TARGET} + echo HELP=$HELP + echo DRY_RUN=$DRY_RUN + echo SPDK_VAGRANT_DISTRO=$SPDK_VAGRANT_DISTRO + echo SPDK_VAGRANT_VMCPU=$SPDK_VAGRANT_VMCPU + echo SPDK_VAGRANT_VMRAM=$SPDK_VAGRANT_VMRAM + echo SPDK_VAGRANT_HTTP_PROXY=$SPDK_VAGRANT_HTTP_PROXY + echo +fi + +export SPDK_VAGRANT_HTTP_PROXY +export SPDK_VAGRANT_VMCPU +export SPDK_VAGRANT_VMRAM +export SPDK_DIR + +if [ ${DRY_RUN} = 1 ]; then + echo "Environemnt Variables" + printenv SPDK_VAGRANT_DISTRO + printenv SPDK_VAGRANT_VMRAM + printenv SPDK_VAGRANT_VMCPU + printenv SPDK_VAGRANT_HTTP_PROXY + printenv SPDK_DIR +fi + +if [ -d "${VAGRANT_TARGET}/${SPDK_VAGRANT_DISTRO}" ]; then + echo "Error: ${VAGRANT_TARGET}/${SPDK_VAGRANT_DISTRO} already exists!" + exit 1 +fi + +if [ ${DRY_RUN} != 1 ]; then + mkdir -vp "${VAGRANT_TARGET}/${SPDK_VAGRANT_DISTRO}" + cp ${DIR}/Vagrantfile ${VAGRANT_TARGET}/${SPDK_VAGRANT_DISTRO} + pushd "${VAGRANT_TARGET}/${SPDK_VAGRANT_DISTRO}" + if [ ! -z "${http_proxy}" ]; then + export http_proxy + export https_proxy + if vagrant plugin list | grep -q vagrant-proxyconf; then + echo "vagrant-proxyconf already installed... skipping" + else + vagrant plugin install vagrant-proxyconf + fi + fi + vagrant up + echo "" + echo " SUCCESS!" + echo "" + echo " cd to ${SPDK_VAGRANT_DISTRO} and type \"vagrant ssh\" to use." + echo " Use vagrant \"suspend\" and vagrant \"resume\" to stop and start." + echo " Use vagrant \"destroy\" followed by \"rm -rf ${SPDK_VAGRANT_DISTRO}\" to destroy all trace of vm." + echo "" +fi diff --git a/scripts/vagrant/env.sh b/scripts/vagrant/env.sh deleted file mode 100644 index bcdcf0a9bf..0000000000 --- a/scripts/vagrant/env.sh +++ /dev/null @@ -1,7 +0,0 @@ -#!/usr/bin/env bash - -# centos7 also supported -export SPDK_VAGRANT_DISTRO="ubuntu1604" - -export SPDK_VAGRANT_VMCPU=4 -export SPDK_VAGRANT_VMRAM=4096 diff --git a/scripts/vagrant/run-autorun.sh b/scripts/vagrant/run-autorun.sh new file mode 100755 index 0000000000..d01096c70b --- /dev/null +++ b/scripts/vagrant/run-autorun.sh @@ -0,0 +1,235 @@ +#!/bin/bash + +# +# BSD LICENSE +# +# Copyright (c) 2018 by NetApp, Inc. +# All Rights Reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in +# the documentation and/or other materials provided with the +# distribution. +# * Neither the name of Intel Corporation nor the names of its +# contributors may be used to endorse or promote products derived +# from this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# + +if [ -z "${MAKE}" ]; then + export MAKE=make +fi + +if [ -z "${GIT}" ]; then + export GIT=git +fi + +if [ -z "${READLINK}" ]; then + export READLINK=readlink +fi + +AUTOTEST_DRIVER_PATH=$($READLINK -f ${BASH_SOURCE%/*}) +SPDK_AUTOTEST_LOCAL_PATH=$PWD +TIMESTAMP=`date +"%Y%m%d%H%M%S"` +BUILD_NAME="build-${TIMESTAMP}" + +# The command line help +display_help() { + echo + echo "Usage: $0 -d [-h] | [-q] | [-n]" + echo " -d : Specify a path to an SPDK source tree" + echo " -q : No output to screen" + echo " -n : Noop - dry-run" + echo " -h : This help" + echo + echo "Examples:" + echo " run-spdk-autotest.sh -d . -q" + echo " run-spdk-autotest.sh -d /home/vagrant/spdk_repo/spdk" + echo +} + +set -e + +NOOP=0 +METHOD=0 +V=1 +OPTIND=1 # Reset in case getopts has been used previously in the shell. +while getopts "d:qhn" opt; do + case "$opt" in + d) SPDK_SOURCE_PATH=$($READLINK -f $OPTARG) + echo Using SPDK source at ${SPDK_SOURCE_PATH} + METHOD=1 + ;; + q) V=0 + ;; + n) NOOP=1 + ;; + h) display_help >&2 + exit 0 + ;; + esac +done + +if [ -z "${SPDK_SOURCE_PATH}" ]; then + echo "Error: Must specify a source path " + display_help + exit 1 +fi + +# The following code verifies the input parameters and sets up the following variables: +# +# SPDK_AUTOTEST_LOCAL_PATH +# GIT_REPO_PATH +# GIT_BRANCH +# + +case "$METHOD" in + 1) + if [ ! -d "${SPDK_SOURCE_PATH}" ]; then + echo "${SPDK_SOURCE_PATH} does not exist!" + exit 1 + fi + if [ ! -d "${SPDK_SOURCE_PATH}/.git" ]; then + echo "${SPDK_SOURCE_PATH} is not a git repository" + exit 1 + fi + + GIT_REPO_SRC_DIR=$($READLINK -f "${SPDK_SOURCE_PATH}" | tr -t '/' ' ' | awk '{print $NF}') + + if [ ! "${GIT_REPO_SRC_DIR}" = "spdk" ]; then + echo "The ${SPDK_SOURCE_PATH} git repository is not named \"spdk\"" + exit 1 + fi + + pushd "${SPDK_SOURCE_PATH}" + GIT_REPO_SRC=$(git rev-parse --show-toplevel) + GIT_BRANCH=$(git rev-parse --abbrev-ref HEAD) + popd + + if [ "${SPDK_AUTOTEST_LOCAL_PATH}" = "${SPDK_SOURCE_PATH}" ]; then + SPDK_AUTOTEST_LOCAL_PATH=$($READLINK -f ${SPDK_AUTOTEST_LOCAL_PATH}/..) + echo "Set SPDK_AUTOTEST_LOCAL_PATH to ${SPDK_AUTOTEST_LOCAL_PATH}" + fi + + if [ -d "${SPDK_AUTOTEST_LOCAL_PATH}/${GIT_BRANCH}" ]; then + if [ -d "${SPDK_AUTOTEST_LOCAL_PATH}/${GIT_BRANCH}/.git" ]; then + echo "${SPDK_AUTOTEST_LOCAL_PATH}/${GIT_BRANCH} is a git repository!" + exit 1 + fi + fi + + GIT_REPO_PATH="${SPDK_AUTOTEST_LOCAL_PATH}/${GIT_BRANCH}/${BUILD_NAME}" + ;; + *) + echo "Internal Error: Must specify a source path or branch name" + display_help + exit 1 + ;; +esac + +AUTOTEST_RESULTS="${SPDK_AUTOTEST_LOCAL_PATH}/${GIT_BRANCH}/${BUILD_NAME}" +AUTOTEST_OUTPUT_PATH="${GIT_REPO_PATH}/output" +rootdir="${GIT_REPO_PATH}/spdk" +BUILD_LOG_FILE="${AUTOTEST_OUTPUT_PATH}/build.log" + +if [[ ${NOOP} -eq 1 ]]; then + echo "AUTOTEST_DRIVER_PATH $AUTOTEST_DRIVER_PATH" + #echo "SPDK_AUTOTEST_LOCAL_PATH $SPDK_AUTOTEST_LOCAL_PATH" + echo "AUTOTEST_OUTPUT_PATH $AUTOTEST_OUTPUT_PATH" + #echo "rootdir $rootdir" + echo "BUILD_LOG_FILE $BUILD_LOG_FILE" + #echo "GIT_BRANCH $GIT_BRANCH" + #echo "BUILD_NAME $BUILD_NAME" + echo "GIT_REPO_PATH $GIT_REPO_PATH" + echo "AUTOTEST_RESULTS $AUTOTEST_RESULTS" +fi + +# +# I'd like to keep these files under source control +# +if [[ -e "${AUTOTEST_DRIVER_PATH}/autorun-spdk.conf" ]]; then + conf="${AUTOTEST_DRIVER_PATH}/autorun-spdk.conf" +fi +if [[ -e ~/autorun-spdk.conf ]]; then + conf=~/autorun-spdk.conf +fi + +if [[ -z $conf ]]; then + echo Conf file not found. + exit 1 +fi + +mkdir -pv --mode=775 "${AUTOTEST_OUTPUT_PATH}" +rm -f latest +ln -sv ${GIT_REPO_PATH} latest + +if [[ ${NOOP} -eq 0 ]]; then + echo V=$V + if [[ $V -eq 0 ]]; then + echo Quieting output + exec 3>&1 4>&2 > "${BUILD_LOG_FILE}" 2>&1 + else + echo Teeing to ${BUILD_LOG_FILE} + exec > >(tee -a "${BUILD_LOG_FILE}") 2>&1 + fi + + case "$METHOD" in + 1) + echo "rsync git repository from ${GIT_REPO_SRC} to ${GIT_REPO_PATH}" + rsync -av "${GIT_REPO_SRC}" "${GIT_REPO_PATH}" + pushd "${GIT_REPO_PATH}/spdk" + sudo "${MAKE}" clean -j $(nproc) + sudo "${GIT}" clean -d -f + popd + ;; + *) + echo "Internal Error: Must specify a source path or branch name" + display_help + exit 1 + ;; + esac + + trap "echo ERROR; exit" INT TERM EXIT + + pushd "${AUTOTEST_OUTPUT_PATH}" + export output_dir="${AUTOTEST_OUTPUT_PATH}" + + # Runs agent scripts + "${rootdir}/autobuild.sh" "$conf" + sudo -E "${rootdir}/autotest.sh" "$conf" + "${rootdir}/autopackage.sh" "$conf" + sudo -E "${rootdir}/autorun_post.py" -d "${AUTOTEST_OUTPUT_PATH}" -r "${rootdir}" + + echo "All Tests Passed" > ${GIT_REPO_PATH}/passed + + # Redirect back to screen + if [[ $V -eq 0 ]]; then + echo Redirect to screen + exec 1>&3 2>&4 > >(tee -a "${BUILD_LOG_FILE}") 2>&1 + fi + + popd + +fi + +echo "all tests passed" + +echo Output directory: ${GIT_REPO_PATH} +echo Build log: "${BUILD_LOG_FILE}" diff --git a/scripts/vagrant/update.sh b/scripts/vagrant/update.sh old mode 100644 new mode 100755 index bfb9eecef8..b2ffbca6b3 --- a/scripts/vagrant/update.sh +++ b/scripts/vagrant/update.sh @@ -1,44 +1,99 @@ -#!/bin/bash +#!/usr/bin/env bash -# Make sure that we get the hugepages we need on provision boot -# Note: The package install should take care of this at the end -# But sometimes after all the work of provisioning, we can't -# get the requested number of hugepages without rebooting. -# So do it here just in case -sysctl -w vm.nr_hugepages=1024 -HUGEPAGES=`sysctl -n vm.nr_hugepages` -if [ $HUGEPAGES != 1024 ]; then - echo "ERROR: Unable to get 1024 hugepages, only got $HUGEPAGES. Cannot finish." - exit +if [ ! "$USER" = "root" ]; then + echo + echo Error: must be run as root! + echo + exit 1 fi -# Figure out what system we are running on -if [ -f /etc/lsb-release ];then - . /etc/lsb-release -elif [ -f /etc/redhat-release ];then - yum install -y redhat-lsb - DISTRIB_ID=`lsb_release -si` - DISTRIB_RELEASE=`lsb_release -sr` - DISTRIB_CODENAME=`lsb_release -sc` - DISTRIB_DESCRIPTION=`lsb_release -sd` +set -e + +DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +SPDK_DIR="$( cd "${DIR}/../../" && pwd )" +echo "SPDK_DIR = $SPDK_DIR" + +# Bug fix for vagrant rsync problem +if [ -d /home/vagrant/spdk_repo ]; then + echo "Fixing permissions on /home/vagrant/spdk_repo" + chown vagrant /home/vagrant/spdk_repo + chgrp vagrant /home/vagrant/spdk_repo fi -# Do initial setup for the system -if [ $DISTRIB_ID == "Ubuntu" ]; then - - export DEBIAN_PRIORITY=critical - export DEBIAN_FRONTEND=noninteractive - export DEBCONF_NONINTERACTIVE_SEEN=true - APT_OPTS="--assume-yes --no-install-suggests --no-install-recommends -o Dpkg::Options::=\"--force-confdef\" -o Dpkg::Options::=\"--force-confold\"" - - # Standard update + upgrade dance - apt-get update ${APT_OPTS} - apt-get upgrade ${APT_OPTS} - - # Install useful but non-mandatory tools - apt-get install -y gdb git gdisk sysstat -elif [ $DISTRIB_ID == "CentOS" ]; then - # Standard update + upgrade dance - yum check-update - yum update -y +# Setup for run-autorun.sh +if [ ! -f /home/vagrant/autorun-spdk.conf ]; then + echo "Copying scripts/vagrant/autorun-spdk.conf to /home/vagrant" + cp ${SPDK_DIR}/scripts/vagrant/autorun-spdk.conf /home/vagrant + chown vagrant /home/vagrant/autorun-spdk.conf + chgrp vagrant /home/vagrant/autorun-spdk.conf +fi + +SYSTEM=`uname -s` + +if [ "$SYSTEM" = "FreeBSD" ]; then + # Do initial setup for the system + pkg upgrade -f + ${SPDK_DIR}/scripts/pkgdep.sh + if [ -d /usr/src/.git ]; then + echo + echo "/usr/src/ is a git repository" + echo "consider \"cd /usr/src/; git pull\" to update" + echo + else + git clone --depth 10 -b release/11.1.0 https://github.com/freebsd/freebsd.git /usr/src + fi +else + + # Make sure that we get the hugepages we need on provision boot + # Note: The package install should take care of this at the end + # But sometimes after all the work of provisioning, we can't + # get the requested number of hugepages without rebooting. + # So do it here just in case + sysctl -w vm.nr_hugepages=1024 + HUGEPAGES=`sysctl -n vm.nr_hugepages` + if [ $HUGEPAGES != 1024 ]; then + echo "Warning: Unable to get 1024 hugepages, only got $HUGEPAGES" + echo "Warning: Adjusting HUGEMEM in /home/vagrant/autorun-spdk.conf" + sed "s/HUGEMEM=.*$/HUGEMEM=${HUGEPAGES}/g" /home/vagrant/autorun-spdk.conf > /home/vagrant/foo.conf + mv -f /home/vagrant/foo.conf /home/vagrant/autorun-spdk.conf + fi + + # Figure out what system we are running on + if [ -f /etc/lsb-release ];then + . /etc/lsb-release + elif [ -f /etc/redhat-release ];then + yum update -y + yum install -y redhat-lsb + DISTRIB_ID=`lsb_release -si` + DISTRIB_RELEASE=`lsb_release -sr` + DISTRIB_CODENAME=`lsb_release -sc` + DISTRIB_DESCRIPTION=`lsb_release -sd` + fi + + # Do initial setup for the system + if [ "$DISTRIB_ID" == "Ubuntu" ]; then + set -xv + export DEBIAN_PRIORITY=critical + export DEBIAN_FRONTEND=noninteractive + export DEBCONF_NONINTERACTIVE_SEEN=true + # Standard update + upgrade dance + apt-get update --assume-yes --no-install-suggests --no-install-recommends -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" + apt-get upgrade --assume-yes --no-install-suggests --no-install-recommends -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" + ${SPDK_DIR}/scripts/pkgdep.sh + elif [ "$DISTRIB_ID" == "CentOS" ]; then + # Standard update + upgrade dance + yum check-update + yum update -y + ${SPDK_DIR}/scripts/pkgdep.sh + elif [ "$DISTRIB_ID" == "Fedora" ]; then + if [ "$DISTRIB_RELEASE" = "26" ]; then + echo + echo " Run \"${SPDK_DIR}/test/common/config/vm_setup.sh\" to complete setup of Fedora 26" + echo + else + yum check-update + yum update -y + ${SPDK_DIR}/scripts/pkgdep.sh + fi + fi fi