Skip to content

Run cgroup v2 tests using UML #50

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 20 commits into
base: master
Choose a base branch
from
3 changes: 1 addition & 2 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ jobs:
matrix:
os:
- "ubuntu-20.04"
- "macos-latest"
rust-target:
- "x86_64-unknown-linux-musl"
cgroups:
Expand All @@ -80,7 +79,7 @@ jobs:
- name: Test
run: |
bash ci/linux.sh
timeout-minutes: 10
timeout-minutes: 20
env:
CI_TARGET: ${{ matrix.rust-target }}
CI_CGROUPS: ${{ matrix.cgroups }}
Expand Down
43 changes: 8 additions & 35 deletions ci/linux.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,44 +6,17 @@ echo "Operating system: $CI_OS"

echo "this is hack, ignore this file" >> ./stracez-dummy

if [[ $CI_OS == "ubuntu-20.04" ]]; then
if [[ $CI_CGROUPS == "cgroup-v2" ]]; then
echo "Skipping: cgroup v2 runs in macos"
exit 0
fi
fi
if [[ $CI_OS == "macos-latest" ]]; then
if [[ $CI_CGROUPS == "cgroup-v1" ]]; then
echo "Skipping: cgroup v1 does not need virtualization"
exit 0
fi
fi

echo "::group::Preparing"

if [[ $CI_CGROUPS == "cgroup-v2" ]] && [ -z "${CI_VM+set}" ]; then
echo "::group::Preparing virtual machine"
vagrant --version
cat > Vagrantfile <<EOF
Vagrant.configure("2") do |config|
config.vm.box = "fedora/32-cloud-base"

config.vm.provider "virtualbox" do |vb|
vb.memory = "700"
end
end
EOF
top -l 1
cat Vagrantfile
sudo vagrant up
echo "::group::Installing packages"
sudo vagrant ssh --command "sudo dnf install -y strace zip"
echo "::group::Entering VM"
sudo vagrant ssh --command "bash -c 'cd /vagrant && CI_OS=$CI_OS CI_CGROUPS=$CI_CGROUPS CI_TARGET=$CI_TARGET CI_VM=1 bash ci/linux.sh'"
echo "Host: pulling logs from VM"
sudo vagrant ssh --command "cat /vagrant/logs.zip | base64" | base64 --decode > logs.zip
sudo apt install sshpass strace
wget http://ftp.debian.org/debian/pool/main/s/slirp/slirp_1.0.17-8_amd64.deb -O slirp.deb && sudo dpkg -i slirp.deb
( cd uml-ci; ./main.sh; )
#sudo sshpass -p user ssh -p 2224 [email protected] "cat /vagrant/logs.zip | base64" | base64 --decode > logs.zip # WTF??
sudo sshpass -p user ssh -p 2224 [email protected] sudo poweroff || true
rm stracez-dummy
unzip logs.zip
#unzip logs.zip
sleep 10
echo "Current directory after VM finish"
ls .
Expand All @@ -63,5 +36,5 @@ sudo --preserve-env ./tests/$CI_TARGET/minion-tests --trace
echo "::group::Finalize"
echo "Current directory after running tests"
ls .
echo "Collecting logs to archive"
zip logs.zip strace*
#echo "Collecting logs to archive"
#zip logs.zip strace*
26 changes: 26 additions & 0 deletions uml-ci/main.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/bash

set -e

wget -q https://download.fedoraproject.org/pub/fedora/linux/releases/33/Cloud/x86_64/images/Fedora-Cloud-Base-33-1.2.x86_64.raw.xz -O img.xz
unxz img.xz
wget -q https://cdn.kernel.org/pub/linux/kernel/v5.x/linux-5.4.93.tar.xz
tar -xJf linux-5.4.93.tar.xz
(
cd linux-5.4.93
export ARCH=um
make defconfig
bash
cat >> .config << EOF
CONFIG_CGROUP_PIDS=y
CONFIG_MEMCG=y
CONFIG_MEMCG_SWAP=y
CONFIG_MEMCG_SWAP_ENABLED=y
CONFIG_USER_NS=y
CONFIG_PID_NS=y
EOF
make -j3
)
linux-5.4.93/linux mem=4096M ubda=img rootfstype=hostfs init="$PWD"/uml-setup.sh
linux-5.4.93/linux mem=4096M ubda=img root=/dev/ubda1 rootfstype=ext4 hostfs=.. eth0=slirp,,./uml-slirp.sh &
./uml-ssh.sh
8 changes: 8 additions & 0 deletions uml-ci/payload.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash

sudo dnf install -y strace zip
export CI_OS=fedora
export CI_CGROUPS=cgroup-v2
export CI_TARGET=x86_64-unknown-linux-musl
export CI_VM=1
bash ci/linux.sh
24 changes: 24 additions & 0 deletions uml-ci/uml-setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/bash

mkdir /dev/mnt
mount /dev/ubda1 /dev/mnt
sed -i 's/.*PermitRootLogin.*/PermitRootLogin yes/' /dev/mnt/etc/ssh/sshd_config
echo >> /dev/mnt/usr/lib/systemd/system/rc-local.service
echo '[Install]' >> /dev/mnt/usr/lib/systemd/system/rc-local.service
echo 'WantedBy=multi-user.target' >> /dev/mnt/usr/lib/systemd/system/rc-local.service
sed -i 's/After=.*/After=sshd.service/' /dev/mnt/usr/lib/systemd/system/rc-local.service
chroot /dev/mnt systemctl enable rc-local
echo '#!/bin/bash

echo root:root | chpasswd
ifconfig eth0 10.0.2.15 netmask 255.255.255.0
route add default dev eth0
echo nameserver 10.0.2.3 > /etc/resolv.conf
ifconfig -a > /dev/console
route > /dev/console
exit 0
' > /dev/mnt/etc/rc.d/rc.local
chmod +x /dev/mnt/etc/rc.d/rc.local
umount /dev/mnt
sync
poweroff -f
3 changes: 3 additions & 0 deletions uml-ci/uml-slirp.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

exec slirp-fullbolt 'host addr 10.0.2.2' 'redir tcp 2224 10.0.2.15:22'
10 changes: 10 additions & 0 deletions uml-ci/uml-ssh.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash

# wait for vm startup
while ! echo incompatible | nc 127.0.0.1 2224; do sleep 1; done

set -e

sleep 10
sshpass -p root ssh -v -o 'StrictHostKeyChecking no' -p 2224 [email protected] 'sed -i '"'"'s/.*wheel.*/#\0/'"'"' /etc/sudoers; sed -i '"'"'s/#*\(.*wheel.*NOPASSWD.*\)/\1/'"'"' /etc/sudoers; adduser -g wheel --uid '"$(id -u)"' user; echo user:user | chpasswd'
sshpass -p user ssh -v -o 'StrictHostKeyChecking no' -p 2224 [email protected] 'sudo mount -t hostfs hostfs ~; cd; exec uml-ci/payload.sh'