summaryrefslogtreecommitdiffstats
path: root/src/spdk/scripts/vagrant/Vagrantfile_openstack_vm
blob: c66405a2c250f42d05af5e1784a32440d2970ca1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# -*- mode: ruby -*-
# vi: set ft=ruby :

Vagrant.configure(2) do |config|

  # See: https://app.vagrantup.com/bento/boxes/ubuntu-18.04
  config.vm.box = "bento/ubuntu-18.04"
  config.vm.box_check_update = false

  config.vm.provider :virtualbox do |vb|
    vb.customize ["modifyvm", :id, "--hwvirtex", "off"]
  end
  if Vagrant.has_plugin?("vagrant-cachier")
    config.cache.scope = :box
  end

  # use http proxy if avaiable
  if ENV['http_proxy'] && Vagrant.has_plugin?("vagrant-proxyconf")
    config.proxy.http     = ENV['http_proxy']
    config.proxy.https    = ENV['http_proxy']
    config.proxy.no_proxy = "localhost,127.0.0.1,10.0.2.15"
  end

  vmcpu=(ENV['SPDK_VAGRANT_VMCPU'] || 10)
  vmram=(ENV['SPDK_VAGRANT_VMRAM'] || 8192)
  spdk_dir=(ENV['SPDK_DIR'] || "none")

  config.ssh.forward_agent = true
  config.ssh.forward_x11 = true

  # Change root passwd and allow root SSH
  config.vm.provision "shell", inline: 'echo -e "root\nroot" | sudo passwd root'
  config.vm.provision "shell", inline: 'sudo sh -c "echo \"PermitRootLogin yes\" >> /etc/ssh/sshd_config"'
  config.vm.provision "shell", inline: 'useradd -m -p sys_sgci -s /bin/bash sys_sgci'
  config.vm.provision "shell", inline: 'usermod -aG sudo sys_sgci'

  # Install needed deps
  $apt_script = <<-SCRIPT
  sudo apt -y update
  sudo DEBIAN_FRONTEND=noninteractive apt -y -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" upgrade
  SCRIPT
  config.vm.provision "shell", inline: $apt_script

  # TODO: Next 2 lines break any future ssh communication via "vagrant ssh"
  # I'd be good to check NIC names in ifconfig and then sed them in /etc/network/interfaces to eht0, eht1, and so on
  config.vm.provision "shell", inline: 'sudo sh -c "echo \"auto eth0\" >> /etc/network/interfaces"'
  config.vm.provision "shell", inline: 'sudo sh -c "echo \"iface eth0 inet dhcp\" >> /etc/network/interfaces"'

  # This is to avoid annoying "Start job is running for wait for network to be configured" 2 minute timeout
  # in case of not-so-perfect NIC and virtual network configuration for the VM
  config.vm.provision "shell", inline: 'systemctl disable systemd-networkd-wait-online.service'
  config.vm.provision "shell", inline: 'systemctl mask systemd-networkd-wait-online.service'

  config.vm.provider "virtualbox" do |vb|
    vb.customize ["modifyvm", :id, "--ioapic", "on"]
    vb.memory = "#{vmram}"
    vb.cpus = "#{vmcpu}"

    #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

  if spdk_dir != "none"
    config.vm.synced_folder "#{spdk_dir}", "/home/vagrant/spdk", type: "rsync",
      rsync__exclude: ["ubuntu18"]
  end

  # Install needed drivers and tools
  config.vm.provision "shell", inline: 'sudo apt-get install -y libibverbs* librdmacm* libnuma-dev libaio-dev libcunit1-dev ibverbs-utils rdma-core'

  # 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

  config.vm.provision "shell", inline: 'sudo useradd -s /bin/bash -d /opt/stack -m stack | echo "stack ALL=(ALL) NOPASSWD: ALL" | sudo tee /etc/sudoers.d/stack'
  config.vm.provision "shell", inline: 'sudo su - stack bash -c "git clone -b stable/stein https://git.openstack.org/openstack-dev/devstack /opt/stack/devstack"'
  config.vm.provision "file", source: "#{spdk_dir}/scripts/vagrant/local.conf", destination: "/home/vagrant/local.conf"
  config.vm.provision "shell", inline: 'sudo su - stack bash -c "cp /home/vagrant/local.conf /opt/stack/devstack"'
  config.vm.provision "shell", inline: 'sudo su - stack bash -c "cd /opt/stack/devstack; ./stack.sh"'
end