github.com/kata-containers/tests@v0.0.0-20240307153542-772105b56064/Vagrantfile (about) 1 # Copyright (c) 2021 Red Hat, Inc. 2 # 3 # SPDX-License-Identifier: Apache-2.0 4 # 5 # This is a Vagrant configuration file. 6 # 7 8 # -*- mode: ruby -*- 9 # vi: set ft=ruby : 10 11 # Read the Kata Containers CI job from the CI_JOB environment variable. 12 job = ENV['CI_JOB'] || "" 13 guest_user = 'vagrant' 14 guest_home_dir = '/home/vagrant' 15 # The file on the guest where environment variables are going to be set 16 # to export. 17 guest_env_file = guest_home_dir + '/ci_job_env' 18 host_arch = `uname -m`.strip 19 20 # All Vagrant configuration is done below. The "2" in Vagrant.configure 21 # configures the configuration version (we support older styles for 22 # backwards compatibility). Please don't change it unless you know what 23 # you're doing. 24 Vagrant.configure("2") do |config| 25 26 config.trigger.before [:up, :ssh] do |trigger| 27 if ENV['GOPATH'] == nil 28 trigger.warn = "You must export the GOPATH environment variable" 29 trigger.abort = true 30 end 31 end 32 33 # By default vagrant sync the current directory. Let's disabled it because the directory 34 # will be synced later to the proper destination. 35 config.vm.synced_folder ".", "/vagrant", disabled:true 36 config.vm.synced_folder ".", "#{guest_home_dir}/go/src/github.com/kata-containers/tests", type:"rsync" 37 config.vm.synced_folder "#{ENV['GOPATH']}/src/github.com/kata-containers/kata-containers", 38 "#{guest_home_dir}/go/src/github.com/kata-containers/kata-containers", type:"rsync" 39 40 config.vm.provider "libvirt" do |lv| 41 lv.driver = "kvm" 42 lv.cpus = "4" 43 lv.memory = "8192" 44 # Domains on Libvirt will be created with the following prefix. 45 lv.default_prefix = "kata_containers_test-" 46 if host_arch == "x86_64" 47 lv.machine_type = "q35" 48 end 49 # The VM needs one additional virtio-net device and iommu enabled 50 # for the vfio tests. 51 if host_arch == "x86_64" 52 lv.qemuargs :value => "-machine" 53 lv.qemuargs :value => "kernel-irqchip=split" 54 lv.qemuargs :value => "-device" 55 lv.qemuargs :value => "intel-iommu,intremap=on,caching-mode=on,device-iotlb=on" 56 # Currently the vfio test picks the last virtio-net device from lspci's 57 # output. Here we add the device in a PCIe root port with higher slot 58 # number on the hope it will be the last in the list. 59 lv.qemuargs :value => "-device" 60 lv.qemuargs :value => "pcie-root-port,port=0x16,chassis=7,id=pcie.7,multifunction=on,bus=pcie.0,addr=0xF" 61 lv.qemuargs :value => "-netdev" 62 lv.qemuargs :value => "user,id=vfio1" 63 lv.qemuargs :value => "-device" 64 lv.qemuargs :value => "virtio-net-pci,netdev=vfio1,bus=pcie.7,disable-legacy=on,disable-modern=off,iommu_platform=on,ats=on" 65 end 66 end 67 68 # Shared provision script. 69 config.vm.provision "shell", env: {"CI_JOB" => job}, inline: <<-SHELL 70 71 export GOPATH="#{guest_home_dir}/go" 72 # The repositories were copied to the vagrant user's home by the root 73 # user. So let's fix the files ownership. 74 chown -R #{guest_user}:#{guest_user} "${GOPATH}" 75 kata_tests_repo_dir="${GOPATH}/src/github.com/kata-containers/tests" 76 77 env_file="#{guest_env_file}" 78 sudo -E PATH=$PATH -H -u #{guest_user} \ 79 cat <<-EOF > ${env_file} 80 export GOPATH="$GOPATH" 81 export PATH="/usr/local/go/bin:\$GOPATH/bin:\$PATH" 82 export CI="true" 83 export CI_JOB="$CI_JOB" 84 pushd $kata_tests_repo_dir &>/dev/null 85 source .ci/ci_job_flags.sh 86 popd &>/dev/null 87 EOF 88 89 source ${env_file} 90 91 # Customize the .bashrc so that it will have the variables exported 92 # after log-in. 93 sudo -E PATH=$PATH -u #{guest_user} \ 94 echo "cd $kata_tests_repo_dir" >> #{guest_home_dir}/.bashrc 95 sudo -E PATH=$PATH -u #{guest_user} \ 96 echo "source $env_file" >> #{guest_home_dir}/.bashrc 97 SHELL 98 99 config.vm.define "fedora", autostart: false do |fedora| 100 fedora.vm.box = "generic/fedora32" 101 # Fedora is required to reboot so that the change to cgroups v1 102 # and kernel arguments take effect. 103 fedora.vm.provision "shell", reboot: true, inline: <<-SHELL 104 # Set the kernel parameter to use cgroups v1. 105 sudo grubby --update-kernel=ALL --args="systemd.unified_cgroup_hierarchy=0" 106 # Set iommu's kernel parameters for vfio tests. 107 source "#{guest_env_file}" 108 if [ "${CI_JOB}" == "VFIO" ]; then 109 grubby --update-kernel=ALL --args="intel_iommu=on iommu=pt" 110 fi 111 SHELL 112 113 fedora.vm.provision "shell", inline: <<-SHELL 114 source "#{guest_env_file}" 115 cd "${GOPATH}/src/github.com/kata-containers/tests" 116 sudo -E PATH=$PATH -H -u #{guest_user} bash -c '.ci/setup.sh' 117 SHELL 118 end 119 120 config.vm.define "fedora35", autostart: false do |fedora| 121 fedora.vm.box = "generic/fedora35" 122 # Fedora is required to reboot so that the change to cgroups v1 123 # and kernel arguments take effect. 124 fedora.vm.provision "shell", reboot: true, inline: <<-SHELL 125 # Set the kernel parameter to use cgroups v1. 126 sudo grubby --update-kernel=ALL --args="systemd.unified_cgroup_hierarchy=0" 127 # Set iommu's kernel parameters for vfio tests. 128 source "#{guest_env_file}" 129 if [ "${CI_JOB}" == "VFIO" ]; then 130 grubby --update-kernel=ALL --args="intel_iommu=on iommu=pt" 131 fi 132 SHELL 133 134 fedora.vm.provision "shell", inline: <<-SHELL 135 source "#{guest_env_file}" 136 cd "${GOPATH}/src/github.com/kata-containers/tests" 137 sudo -E PATH=$PATH -H -u #{guest_user} bash -c '.ci/setup.sh' 138 SHELL 139 end 140 141 config.vm.define "ubuntu", autostart: false do |ubuntu| 142 ubuntu.vm.box = "generic/ubuntu2004" 143 if job == "VFIO" 144 ubuntu.vm.provision "shell", reboot: true, inline: <<-SHELL 145 # Set iommu's kernel parameters for vfio tests. That requires a reboot. 146 sed -i 's/\\(GRUB_CMDLINE_LINUX_DEFAULT\\)="\\(.*\\)"/\\1="\\2 intel_iommu=on iommu=pt"/' /etc/default/grub 147 update-grub 148 SHELL 149 end 150 151 ubuntu.vm.provision "shell", inline: <<-SHELL 152 source "#{guest_env_file}" 153 cd "${GOPATH}/src/github.com/kata-containers/tests" 154 sudo -E PATH=$PATH -H -u #{guest_user} bash -c '.ci/setup.sh' 155 SHELL 156 end 157 end