[neon/ubuntu-core/ago/ui-tests] selenium: Building dockerfile and launch script, fails to boot

Antoine Gonzalez null at kde.org
Fri Apr 26 16:12:44 BST 2024


Git commit 554bce96d9a5c6f48b311c8e362f0c5b5206b596 by Antoine Gonzalez.
Committed on 26/04/2024 at 15:12.
Pushed by daspood into branch 'ago/ui-tests'.

Building dockerfile and launch script, fails to boot

A  +61   -0    selenium/Dockerfile
A  +5    -0    selenium/README.md
A  +72   -0    selenium/run.sh

https://invent.kde.org/neon/ubuntu-core/-/commit/554bce96d9a5c6f48b311c8e362f0c5b5206b596

diff --git a/selenium/Dockerfile b/selenium/Dockerfile
new file mode 100644
index 0000000..b53457c
--- /dev/null
+++ b/selenium/Dockerfile
@@ -0,0 +1,61 @@
+# Ubuntu 22.04, 23.10, 24.04 do not work
+FROM ubuntu:22.04
+WORKDIR /seleniumtest
+
+# Name of the application contained in the testsnap.snap. We need it to manually connect kf6-core22.
+# `docker build --build-arg SNAP_NAME=kcalc .`
+#ARG SNAP_NAME=kcalc
+
+ENV DEBIAN_FRONTEND=noninteractive
+ENV PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin"
+ENV container docker
+ENV LANG C.UTF-8
+ENV LC_ALL C.UTF-8
+
+RUN apt update  \
+    && apt upgrade -y \
+    && apt install -y cmake gcc g++ git ruby dh-python dh-virtualenv debhelper-compat sed \
+                      python3-pip python3-all-dev python3-pyatspi python3-cairo python3-gi-cairo python3-virtualenv \
+    && apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 444DABCF3667D0283F894EDDE6D4736255751E5D \
+    && echo "deb [ arch=amd64,arm64 ] https://archive.neon.kde.org/user jammy main" | tee /etc/apt/sources.list.d/kde-neon.list \
+    && apt update  \
+    && apt install -y accerciser at-spi2-core gobject-introspection \
+                      libgirepository1.0-dev plasma-wayland-protocols libcairo2-dev libpipewire-0.3-dev \
+                      libgirepository-1.0-1 libcairo2 \
+                      pkg-kde-tools-neon kf6-extra-cmake-modules kf6-kcoreaddons-dev kf6-kwindowsystem-dev kwayland6-dev qt6-base-dev qt6-base-private-dev qt6-wayland-dev libkpipewire-dev  \
+                      kf6-kcoreaddons kf6-kwindowsystem kwayland6 qt6-base qt6-wayland libqt6core6 libqt6dbus6 libqt6waylandclient6 libkpipewire6
+
+# Installing selenium
+RUN cd /tmp \
+    && git clone https://invent.kde.org/sdk/selenium-webdriver-at-spi.git \
+    && cd selenium-webdriver-at-spi \
+    && sed -i 's/ORG_KDE_KWIN_FAKE_INPUT_DESTROY_SINCE_VERSION/ORG_KDE_KWIN_FAKE_INPUT_BUTTON_SINCE_VERSION/g' inputsynth/interaction.cpp \
+    && pip3 install -r requirements.txt \
+    && echo export PATH="~/.local/bin:$PATH" >> ${HOME}/.bashrc \
+    && mkdir build \
+    && cd build \
+    && cmake -DQT_MAJOR_VERSION=6 -DBUILD_WITH_QT6=ON .. \
+    && make \
+    && make install
+
+# Copying test files
+COPY ./testsnap.snap /seleniumtest/
+COPY ./testsuite.py /seleniumtest/
+RUN chmod +x testsuite.py
+
+# Attempt to get snapd to run in the final container
+RUN apt install -y fuse snapd squashfuse sudo init \
+    && apt clean \
+    && dpkg-divert --local --rename --add /sbin/udevadm \
+    && ln -s /bin/true /sbin/udevadm \
+    && systemctl enable snapd
+VOLUME ["/sys/fs/cgroup"]
+STOPSIGNAL SIGRTMIN+3
+CMD ["/sbin/init"]
+
+# Ideally we would only want to run this, but snapd cannot run without systemd
+#RUN apt install -y snapd
+#RUN snap install kf6-core22
+#RUN snap install --dangerous testsnap.snap
+#RUN snap connect $SNAP_NAME:kf6-core22 kf6-core22:kf6-core22
+#CMD ["/bin/bash", "-c", "selenium-webdriver-at-spi-run testsuite.py"]
diff --git a/selenium/README.md b/selenium/README.md
new file mode 100644
index 0000000..1c688fa
--- /dev/null
+++ b/selenium/README.md
@@ -0,0 +1,5 @@
+- put the snap package to test in the current directory, renaming it `testsnap.snap`
+- put the python test script to run with Selenium in the current directory, renaming it `testsuite.py`
+- launch `run.sh`, which will build the docker image and run a container in which the tests can be launched
+
+Currently: container fails to start, `systemd` struggles with cgroups.
\ No newline at end of file
diff --git a/selenium/run.sh b/selenium/run.sh
new file mode 100755
index 0000000..cee5b19
--- /dev/null
+++ b/selenium/run.sh
@@ -0,0 +1,72 @@
+# Adapting https://github.com/ogra1/snapd-docker/blob/master/build.sh
+# Changes:
+#   - Kept the clean_up function
+#   - Kept the docker build and run commands
+#   - Removed the use of arguments
+#   - Removed the build-related sections of the script as we have a dedicated custom Dockerfile for that
+#   - Replaced snapd healthcheck with container healthcheck
+#   - Added use-case-specific commands at the end of the script
+
+clean_up() {
+    sleep 1
+    docker logs -f snaptest > container_logs.txt || true
+    docker rm -f snaptest >/dev/null 2>&1 || true
+    docker rmi snaptest >/dev/null 2>&1 || true
+    docker rmi $(docker images -f "dangling=true" -q) >/dev/null 2>&1 || true
+    exit 1
+}
+trap clean_up 1 2 3 4 9 15
+
+# Build the image
+docker build -t snaptest --force-rm=true . || clean_up
+
+# Start the detached container
+docker run \
+    --name=snaptest \
+    -ti \
+    --tmpfs /run \
+    --tmpfs /run/lock \
+    --tmpfs /tmp \
+    --cap-add SYS_ADMIN \
+    --device=/dev/fuse \
+    --security-opt apparmor:unconfined \
+    --security-opt seccomp:unconfined \
+    -v /sys/fs/cgroup:/sys/fs/cgroup:ro \
+    -v /lib/modules:/lib/modules:ro \
+    -d snaptest || clean_up
+
+# FIXME:
+#   systemd 249.11-0ubuntu3.12 running in system mode (+PAM +AUDIT +SELINUX +APPARMOR +IMA +SMACK +SECCOMP +GCRYPT +GNUTLS +OPENSSL +ACL +BLKID +CURL +ELFUTILS +FIDO2 +IDN2 -IDN +IPTC +KMOD +LIBCRYPTSETUP +LIBFDISK +PCRE2 -PWQUALITY -P11KIT -QRENCODE +BZIP2 +LZ4 +XZ +ZLIB +ZSTD -XKBCOMMON +UTMP +SYSVINIT default-hierarchy=unified)
+#   Detected virtualization docker.
+#   Detected architecture x86-64.
+#
+#   Welcome to Ubuntu 22.04.4 LTS!
+#
+#   Failed to create /init.scope control group: Read-only file system
+#   Failed to allocate manager object: Read-only file system
+#   Failed to allocate manager object.
+#   Exiting PID 1...
+
+# Wait for snapd to start
+TIMEOUT=30
+SLEEP=0.1
+echo -n "Waiting up to $(($TIMEOUT/10)) seconds for container startup"
+while [ "$( docker container inspect -f '{{.State.Status}}' snaptest )" != "running" ]; do
+    echo -n "."
+    sleep $SLEEP || clean_up
+    if [ "$TIMEOUT" -le "0" ]; then
+        echo " Timed out!"
+        clean_up
+    fi
+    TIMEOUT=$(($TIMEOUT-1))
+done
+echo " done"
+
+# Install test snap and kf6
+docker exec snaptest snap install kf6-core22 || clean_up
+docker exec snaptest snap install --dangerous testsnap.snap || clean_up
+docker exec snaptest snap connect $SNAP_NAME:kf6-core22 kf6-core22:kf6-core22 || clean_up
+
+# Run the tests
+docker exec snaptest selenium-webdriver-at-spi-run testsuite.py > testsuite_output.txt
+clean_up


More information about the Neon-commits mailing list