Skip to content

Commit

Permalink
Create release and development VMs (p4lang#439)
Browse files Browse the repository at this point in the history
* vm: trim trailing whitespace

Signed-off-by: Radostin Stoyanov <[email protected]>

* Create dev and release VMs

Signed-off-by: Radostin Stoyanov <[email protected]>
  • Loading branch information
rst0git authored Nov 28, 2021
1 parent deb6ace commit 27ffd3b
Show file tree
Hide file tree
Showing 7 changed files with 213 additions and 142 deletions.
9 changes: 6 additions & 3 deletions vm-ubuntu-20.04/README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
# Creating the VM

Start creating a brand new VM by running `vagrant up` in this
directory (install vagrant on your system if needed). It can take one
to several hours, depending upon the speed of your computer and
Internet connection.
directory (install vagrant on your system if needed). This command
would create a _release_ VM that includes P4 software installed from
packages and allows to update it with `apt upgrade`. Alternatively,
a development VM can be created by running `vagrant up dev`.
Note that creating a development VM can take one to several hours,
depending upon the speed of your computer and Internet connection.

Steps taken to prepare a VM _after_ running `vagrant up` on the host
OS. Some of these could probably be automated with programs, and
Expand Down
63 changes: 41 additions & 22 deletions vm-ubuntu-20.04/Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,34 +3,53 @@

Vagrant.configure(2) do |config|
config.vm.box = "bento/ubuntu-20.04"
config.vm.define "p4-tutorial" do |tutorial|

config.vm.synced_folder '.', '/vagrant', disabled: true
config.vm.hostname = "p4"
config.vm.provision "file", source: "p4-logo.png", destination: "/home/vagrant/p4-logo.png"
config.vm.provision "file", source: "p4_16-mode.el", destination: "/home/vagrant/p4_16-mode.el"
config.vm.provision "file", source: "p4.vim", destination: "/home/vagrant/p4.vim"

config.vm.define "dev", autostart: false do |dev|
dev.vm.provider "virtualbox" do |v|
v.name = "P4 Tutorial Development" + Time.now.strftime(" %Y-%m-%d")
end
dev.vm.provision "file", source: "py3localpath.py", destination: "/home/vagrant/py3localpath.py"
dev.vm.provision "shell", inline: "chmod 755 /home/vagrant/py3localpath.py"
dev.vm.provision "file", source: "patches/disable-Wno-error-and-other-small-changes.diff", destination: "/home/vagrant/patches/disable-Wno-error-and-other-small-changes.diff"
dev.vm.provision "file", source: "patches/behavioral-model-use-correct-libssl-pkg.patch", destination: "/home/vagrant/patches/behavioral-model-use-correct-libssl-pkg.patch"
dev.vm.provision "file", source: "patches/mininet-dont-install-python2.patch", destination: "/home/vagrant/patches/mininet-dont-install-python2.patch"
dev.vm.provision "file", source: "clean.sh", destination: "/home/vagrant/clean.sh"
dev.vm.provision "shell", inline: "chmod 755 /home/vagrant/clean.sh"
dev.vm.provision "shell", path: "root-dev-bootstrap.sh"
dev.vm.provision "shell", path: "root-common-bootstrap.sh"
dev.vm.provision "shell", privileged: false, path: "user-dev-bootstrap.sh"
dev.vm.provision "shell", privileged: false, path: "user-common-bootstrap.sh"
end

config.vm.define "release", primary: true do |release|
release.vm.provider "virtualbox" do |v|
v.name = "P4 Tutorial Release" + Time.now.strftime(" %Y-%m-%d")
end
release.vm.provision "shell", path: "root-release-bootstrap.sh"
release.vm.provision "shell", path: "root-common-bootstrap.sh"
release.vm.provision "shell", privileged: false, path: "user-common-bootstrap.sh"
end

config.vm.provider "virtualbox" do |vb|
vb.name = "P4 Tutorial" + Time.now.strftime(" %Y-%m-%d")
vb.gui = true
vb.memory = 2048
vb.cpus = 2
vb.customize ["modifyvm", :id, "--cableconnected1", "on"]
vb.customize ["storageattach", :id,
"--storagectl", "IDE Controller",
"--port", "0", "--device", "0",
"--type", "dvddrive",
"--medium", "emptydrive"]
vb.customize [
"storageattach", :id,
"--storagectl", "IDE Controller",
"--port", "0",
"--device", "0",
"--type", "dvddrive",
"--medium", "emptydrive"
]
vb.customize ["modifyvm", :id, "--vram", "32"]

end
config.vm.synced_folder '.', '/vagrant', disabled: true
config.vm.hostname = "p4"
config.vm.provision "file", source: "p4-logo.png", destination: "/home/vagrant/p4-logo.png"
config.vm.provision "file", source: "p4_16-mode.el", destination: "/home/vagrant/p4_16-mode.el"
config.vm.provision "file", source: "p4.vim", destination: "/home/vagrant/p4.vim"
config.vm.provision "file", source: "py3localpath.py", destination: "/home/vagrant/py3localpath.py"
config.vm.provision "shell", inline: "chmod 755 /home/vagrant/py3localpath.py"
config.vm.provision "file", source: "patches/disable-Wno-error-and-other-small-changes.diff", destination: "/home/vagrant/patches/disable-Wno-error-and-other-small-changes.diff"
config.vm.provision "file", source: "patches/behavioral-model-use-correct-libssl-pkg.patch", destination: "/home/vagrant/patches/behavioral-model-use-correct-libssl-pkg.patch"
config.vm.provision "file", source: "patches/mininet-dont-install-python2.patch", destination: "/home/vagrant/patches/mininet-dont-install-python2.patch"
config.vm.provision "file", source: "clean.sh", destination: "/home/vagrant/clean.sh"
config.vm.provision "shell", inline: "chmod 755 /home/vagrant/clean.sh"
config.vm.provision "shell", path: "root-bootstrap.sh"
config.vm.provision "shell", privileged: false, path: "user-bootstrap.sh"

end
40 changes: 40 additions & 0 deletions vm-ubuntu-20.04/root-common-bootstrap.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/bin/bash

# Print commands and exit on errors
set -xe

useradd -m -d /home/p4 -s /bin/bash p4
echo "p4:p4" | chpasswd
echo "p4 ALL=(ALL) NOPASSWD:ALL" > /etc/sudoers.d/99_p4
chmod 440 /etc/sudoers.d/99_p4
usermod -aG vboxsf p4

# Install p4 logo as wallpaper
mv /home/vagrant/p4-logo.png /usr/share/lubuntu/wallpapers/lubuntu-default-wallpaper.png

# 2021-Mar-06 this command failed with an error that the file did not exist.
#sed -i s@#background=@background=/usr/share/lubuntu/wallpapers/1604-lubuntu-default-wallpaper.png@ /etc/lightdm/lightdm-gtk-greeter.conf
# The following command will hopefully cause the P4 logo to be normal
# size and centered on the initial desktop image, rather than scaled
# and stretched and cropped horribly.
#sed -i s@wallpaper_mode=crop@wallpaper_mode=center@ /etc/xdg/pcmanfm/lubuntu/desktop-items-0.conf

# If that does not have the desired effect, another possibility is
# executing that command to edit the same string in file
# /etc/xdg/pcmanfm/lubuntu/pcmanfm.conf

# TBD: Ubuntu 20.04 does not have the light-locker package, so it
# fails if you try to remove it. Probably enabling auto-login
# requires a different modification than is done below with the cat <<
# EOF command.

# Disable screensaver
#apt-get -y remove light-locker

# Automatically log into the P4 user
#cat << EOF | tee -a /etc/lightdm/lightdm.conf.d/10-lightdm.conf
#[SeatDefaults]
#autologin-user=p4
#autologin-user-timeout=0
#user-session=Lubuntu
#EOF
Original file line number Diff line number Diff line change
Expand Up @@ -135,44 +135,4 @@ sudo pip3 install ipaddr
sudo pip3 install pypcap

# Things needed for `cd tutorials/exercises/basic ; make run` to work:
sudo pip3 install psutil crcmod

useradd -m -d /home/p4 -s /bin/bash p4
echo "p4:p4" | chpasswd
echo "p4 ALL=(ALL) NOPASSWD:ALL" > /etc/sudoers.d/99_p4
chmod 440 /etc/sudoers.d/99_p4
usermod -aG vboxsf p4

cd /usr/share/lubuntu/wallpapers/
cp /home/vagrant/p4-logo.png .
rm lubuntu-default-wallpaper.png
ln -s p4-logo.png lubuntu-default-wallpaper.png
rm /home/vagrant/p4-logo.png
cd ~

# 2021-Mar-06 this command failed with an error that the file did not exist.
#sed -i s@#background=@background=/usr/share/lubuntu/wallpapers/1604-lubuntu-default-wallpaper.png@ /etc/lightdm/lightdm-gtk-greeter.conf
# The following command will hopefully cause the P4 logo to be normal
# size and centered on the initial desktop image, rather than scaled
# and stretched and cropped horribly.
#sed -i s@wallpaper_mode=crop@wallpaper_mode=center@ /etc/xdg/pcmanfm/lubuntu/desktop-items-0.conf

# If that does not have the desired effect, another possibility is
# executing that command to edit the same string in file
# /etc/xdg/pcmanfm/lubuntu/pcmanfm.conf

# TBD: Ubuntu 20.04 does not have the light-locker package, so it
# fails if you try to remove it. Probably enabling auto-login
# requires a different modification than is done below with the cat <<
# EOF command.

# Disable screensaver
#apt-get -y remove light-locker

# Automatically log into the P4 user
#cat << EOF | tee -a /etc/lightdm/lightdm.conf.d/10-lightdm.conf
#[SeatDefaults]
#autologin-user=p4
#autologin-user-timeout=0
#user-session=Lubuntu
#EOF
sudo pip3 install psutil crcmod
45 changes: 45 additions & 0 deletions vm-ubuntu-20.04/root-release-bootstrap.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/bin/bash

# Print commands and exit on errors
set -xe

export DEBIAN_FRONTEND=noninteractive

# Atom install steps came from this page on 2020-May-11:
# https://flight-manual.atom.io/getting-started/sections/installing-atom/#platform-linux

echo "deb [arch=amd64] https://packagecloud.io/AtomEditor/atom/any/ any main" | sudo tee /etc/apt/sources.list.d/atom.list
wget -qO - https://packagecloud.io/AtomEditor/atom/gpgkey | apt-key add -

# Add repository with P4 packages
# https://build.opensuse.org/project/show/home:p4lang

echo "deb http://download.opensuse.org/repositories/home:/p4lang/xUbuntu_20.04/ /" | sudo tee /etc/apt/sources.list.d/home:p4lang.list
wget -qO - "http://download.opensuse.org/repositories/home:/p4lang/xUbuntu_20.04/Release.key" | apt-key add -

apt-get update -qq

apt-get -qq -y -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" upgrade
apt-get install -qq -y --no-install-recommends --fix-missing\
atom \
ca-certificates \
curl \
emacs \
git \
iproute2 \
lubuntu-desktop \
net-tools \
python3 \
python3-pip \
tcpdump \
unzip \
valgrind \
vim \
wget \
xcscope-el \
xterm \
p4lang-p4c \
p4lang-bmv2 \
p4lang-pi

sudo pip3 install -U scapy ipaddr ptf psutil grpcio
78 changes: 78 additions & 0 deletions vm-ubuntu-20.04/user-common-bootstrap.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
#!/bin/bash

# Print script commands and exit on errors.
set -xe

# --- Mininet --- #
git clone git://github.com/mininet/mininet mininet
cd mininet
PATCH_DIR="${HOME}/patches"
patch -p1 < "${PATCH_DIR}/mininet-dont-install-python2.patch" || echo "Errors while attempting to patch mininet, but continuing anyway ..."
cd ..
# TBD: Try without installing openvswitch, i.e. no '-v' option, to see
# if everything still works well without it.
sudo ./mininet/util/install.sh -nw

find /usr/lib /usr/local $HOME/.local | sort > $HOME/usr-local-7-after-mininet-install.txt

# --- Tutorials --- #
git clone https://github.com/p4lang/tutorials
sudo mv tutorials /home/p4
sudo chown -R p4:p4 /home/p4/tutorials

# --- Emacs --- #
sudo cp p4_16-mode.el /usr/share/emacs/site-lisp/
sudo mkdir /home/p4/.emacs.d/
echo "(autoload 'p4_16-mode' \"p4_16-mode.el\" \"P4 Syntax.\" t)" > init.el
echo "(add-to-list 'auto-mode-alist '(\"\\.p4\\'\" . p4_16-mode))" | tee -a init.el
sudo mv init.el /home/p4/.emacs.d/
sudo ln -s /usr/share/emacs/site-lisp/p4_16-mode.el /home/p4/.emacs.d/p4_16-mode.el
sudo chown -R p4:p4 /home/p4/.emacs.d/

# --- Vim --- #
cd ~
mkdir .vim
cd .vim
mkdir ftdetect
mkdir syntax
echo "au BufRead,BufNewFile *.p4 set filetype=p4" >> ftdetect/p4.vim
echo "set bg=dark" >> ~/.vimrc
sudo mv ~/.vimrc /home/p4/.vimrc
cp ~/p4.vim syntax/p4.vim
cd ~
sudo mv .vim /home/p4/.vim
sudo chown -R p4:p4 /home/p4/.vim
sudo chown p4:p4 /home/p4/.vimrc

# --- Adding Desktop icons --- #
DESKTOP=/home/${USER}/Desktop
mkdir -p ${DESKTOP}

cat > ${DESKTOP}/Terminal.desktop << EOF
[Desktop Entry]
Encoding=UTF-8
Type=Application
Name=Terminal
Name[en_US]=Terminal
Icon=konsole
Exec=/usr/bin/x-terminal-emulator
Comment[en_US]=
EOF

cat > ${DESKTOP}/Wireshark.desktop << EOF
[Desktop Entry]
Encoding=UTF-8
Type=Application
Name=Wireshark
Name[en_US]=Wireshark
Icon=wireshark
Exec=/usr/bin/wireshark
Comment[en_US]=
EOF

sudo mkdir -p /home/p4/Desktop
sudo mv /home/${USER}/Desktop/* /home/p4/Desktop
sudo chown -R p4:p4 /home/p4/Desktop/

# Do this last!
sudo reboot
Loading

0 comments on commit 27ffd3b

Please sign in to comment.