From 27ffd3bfdff8bf43bdbbfd01f03e90c0057eb246 Mon Sep 17 00:00:00 2001 From: Radostin Stoyanov Date: Sun, 28 Nov 2021 15:24:30 +0000 Subject: [PATCH] Create release and development VMs (#439) * vm: trim trailing whitespace Signed-off-by: Radostin Stoyanov * Create dev and release VMs Signed-off-by: Radostin Stoyanov --- vm-ubuntu-20.04/README.md | 9 ++- vm-ubuntu-20.04/Vagrantfile | 63 +++++++++------ vm-ubuntu-20.04/root-common-bootstrap.sh | 40 ++++++++++ ...oot-bootstrap.sh => root-dev-bootstrap.sh} | 42 +--------- vm-ubuntu-20.04/root-release-bootstrap.sh | 45 +++++++++++ vm-ubuntu-20.04/user-common-bootstrap.sh | 78 +++++++++++++++++++ ...ser-bootstrap.sh => user-dev-bootstrap.sh} | 78 +------------------ 7 files changed, 213 insertions(+), 142 deletions(-) create mode 100755 vm-ubuntu-20.04/root-common-bootstrap.sh rename vm-ubuntu-20.04/{root-bootstrap.sh => root-dev-bootstrap.sh} (74%) create mode 100755 vm-ubuntu-20.04/root-release-bootstrap.sh create mode 100755 vm-ubuntu-20.04/user-common-bootstrap.sh rename vm-ubuntu-20.04/{user-bootstrap.sh => user-dev-bootstrap.sh} (78%) diff --git a/vm-ubuntu-20.04/README.md b/vm-ubuntu-20.04/README.md index 264990d1e..e2e190b41 100644 --- a/vm-ubuntu-20.04/README.md +++ b/vm-ubuntu-20.04/README.md @@ -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 diff --git a/vm-ubuntu-20.04/Vagrantfile b/vm-ubuntu-20.04/Vagrantfile index b6efab9fa..33e9efd26 100644 --- a/vm-ubuntu-20.04/Vagrantfile +++ b/vm-ubuntu-20.04/Vagrantfile @@ -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 diff --git a/vm-ubuntu-20.04/root-common-bootstrap.sh b/vm-ubuntu-20.04/root-common-bootstrap.sh new file mode 100755 index 000000000..773e836b0 --- /dev/null +++ b/vm-ubuntu-20.04/root-common-bootstrap.sh @@ -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 diff --git a/vm-ubuntu-20.04/root-bootstrap.sh b/vm-ubuntu-20.04/root-dev-bootstrap.sh similarity index 74% rename from vm-ubuntu-20.04/root-bootstrap.sh rename to vm-ubuntu-20.04/root-dev-bootstrap.sh index c57d83d47..878faf329 100755 --- a/vm-ubuntu-20.04/root-bootstrap.sh +++ b/vm-ubuntu-20.04/root-dev-bootstrap.sh @@ -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 \ No newline at end of file diff --git a/vm-ubuntu-20.04/root-release-bootstrap.sh b/vm-ubuntu-20.04/root-release-bootstrap.sh new file mode 100755 index 000000000..45c9cbb6f --- /dev/null +++ b/vm-ubuntu-20.04/root-release-bootstrap.sh @@ -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 diff --git a/vm-ubuntu-20.04/user-common-bootstrap.sh b/vm-ubuntu-20.04/user-common-bootstrap.sh new file mode 100755 index 000000000..e8cbd475e --- /dev/null +++ b/vm-ubuntu-20.04/user-common-bootstrap.sh @@ -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 diff --git a/vm-ubuntu-20.04/user-bootstrap.sh b/vm-ubuntu-20.04/user-dev-bootstrap.sh similarity index 78% rename from vm-ubuntu-20.04/user-bootstrap.sh rename to vm-ubuntu-20.04/user-dev-bootstrap.sh index c07e4d641..3378a8056 100755 --- a/vm-ubuntu-20.04/user-bootstrap.sh +++ b/vm-ubuntu-20.04/user-dev-bootstrap.sh @@ -3,7 +3,7 @@ # Print script commands and exit on errors. set -xe -#Src +#Src BMV2_COMMIT="b0fb01ecacbf3a7d7f0c01e2f149b0c6a957f779" # 2021-Sep-07 PI_COMMIT="a5fd855d4b3293e23816ef6154e83dc6621aed6a" # 2021-Sep-07 P4C_COMMIT="149634bbe4842fb7c1e80d1b7c9d1e0ec91b0051" # 2021-Sep-07 @@ -212,18 +212,6 @@ cd ../.. find /usr/lib /usr/local $HOME/.local | sort > $HOME/usr-local-6-after-p4c.txt -# --- 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 - # --- PTF --- # git clone git://github.com/p4lang/ptf cd ptf @@ -231,66 +219,4 @@ git checkout ${PTF_COMMIT} sudo python3 setup.py install cd .. -find /usr/lib /usr/local $HOME/.local | sort > $HOME/usr-local-8-after-ptf-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 +find /usr/lib /usr/local $HOME/.local | sort > $HOME/usr-local-8-after-ptf-install.txt \ No newline at end of file