]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
WIP: packaing tests using apkg's new test feature
authorVasek Sraier <git@vakabus.cz>
Tue, 17 May 2022 09:34:46 +0000 (11:34 +0200)
committerVasek Sraier <git@vakabus.cz>
Sun, 31 Jul 2022 15:26:39 +0000 (17:26 +0200)
ci/pkgtest.yaml
distro/tests/extra/all/control [new file with mode: 0644]
distro/tests/manager-packaging/control [new file with mode: 0644]
manager/etc/knot-resolver/config.yml
manager/knot_resolver_manager/datamodel/logging_schema.py
manager/scripts/make-package.sh
manager/tests/packaging/kresctl.sh [changed mode: 0644->0755]
manager/tests/packaging/systemd_service.sh [changed mode: 0644->0755]

index 955d64c1eb3f5281c867071457b50acd0365a881..6d6def6dac47aeff1f89bffacdf8a9d06d706144 100644 (file)
@@ -20,8 +20,14 @@ stages:
     paths:
       - pkg/
 
-.apkgbuild: &apkgbuild # new jinja2 breaks docs (sphinx/breathe)
-  - pip3 install -U apkg 'jinja2<3.1'
+.apkginstall: &apkginstall  # new jinja2 breaks docs (sphinx/breathe)
+  - git clone https://gitlab.nic.cz/packaging/apkg.git
+  - cd apkg; pip3 install -U . 'jinja2<3.1'; cd ..
+  # - pip3 install -U apkg 'jinja2<3.1'
+  
+
+.apkgbuild: &apkgbuild
+  - *apkginstall
   - apkg build-dep -y
   - apkg build
 
@@ -168,15 +174,17 @@ nixos-unstable:pkgbuild:
     - lxc
     - amd64
 
+.apkgtest: &apkgtest
+  - export PYTHONIOENCODING=utf8
+  - *apkginstall
+  - apkg test-dep
+  - apkg test
+
 .debpkgtest: &debpkgtest
   - *pkgdebrepo
-  - apt-get install -y knot-dnsutils
   - apt-get install -y $(find ./pkg/pkgs -name '*.deb' | grep -v module | grep -v debug | grep -v devel)
-  - systemctl start kresd@1
-  - kdig @127.0.0.1 nic.cz | grep -qi NOERROR
-  - systemctl stop kresd@1
-  - systemctl start knot-resolver
-  - kdig @127.0.0.1 nic.cz | grep -qi NOERROR
+  - apt-get install -y python3-pip
+  - *apkgtest
 
 centos-7:pkgtest:
   <<: *pkgtest
@@ -187,21 +195,9 @@ centos-7:pkgtest:
     - export LC_ALL=en_US.UTF-8
   script:
     - yum install -y epel-release
-    - yum install -y knot-utils findutils
+    - yum install -y findutils
     - yum install -y $(find ./pkg/pkgs -name '*.rpm' | grep -v module | grep -v debug | grep -v devel)
-    - systemctl start kresd@1
-    - kdig @127.0.0.1 nic.cz | grep -qi NOERROR
-
-debian-9:pkgtest:
-  <<: *pkgtest
-  needs:
-    - debian-9:pkgbuild
-  image: $CI_REGISTRY/labs/lxc-gitlab-runner/debian-9
-  variables:
-    OBS_REPO: knot-resolver-build
-    DISTROTEST_REPO: Debian_9.0
-  script:
-    - *debpkgtest
+    - *apkgtest
 
 debian-10:pkgtest:
   <<: *pkgtest
@@ -231,13 +227,9 @@ fedora-34:pkgtest:
     - fedora-34:pkgbuild
   image: $CI_REGISTRY/labs/lxc-gitlab-runner/fedora-34
   script:
-    - dnf install -y knot-utils findutils
+    - dnf install -y findutils python3-pip
     - dnf install -y $(find ./pkg/pkgs -name '*.rpm' | grep -v module | grep -v debug | grep -v devel)
-    - systemctl start kresd@1
-    - kdig @127.0.0.1 nic.cz | grep -qi NOERROR
-    - systemctl stop kresd@1
-    - systemctl start knot-resolver
-    - kdig @127.0.0.1 nic.cz | grep -qi NOERROR
+    - *apkgtest
 
 fedora-35:pkgtest:
   <<: *pkgtest
@@ -245,13 +237,10 @@ fedora-35:pkgtest:
     - fedora-35:pkgbuild
   image: $CI_REGISTRY/labs/lxc-gitlab-runner/fedora-35
   script:
-    - dnf install -y knot-utils findutils
+    - dnf install -y findutils python3-pip
     - dnf install -y $(find ./pkg/pkgs -name '*.rpm' | grep -v module | grep -v debug | grep -v devel)
-    - systemctl start kresd@1
-    - kdig @127.0.0.1 nic.cz | grep -qi NOERROR
-    - systemctl stop kresd@1
-    - systemctl start knot-resolver
-    - kdig @127.0.0.1 nic.cz | grep -qi NOERROR
+    - *apkgtest
+    
 
 opensuse-15.2:pkgtest:
   <<: *pkgtest
@@ -260,10 +249,9 @@ opensuse-15.2:pkgtest:
   image: $CI_REGISTRY/labs/lxc-gitlab-runner/opensuse-15.2
   script:
     - zypper addrepo -G -f https://download.opensuse.org/repositories/home:CZ-NIC:knot-resolver-build/openSUSE_Leap_15.2/home:CZ-NIC:knot-resolver-build.repo
-    - zypper install -y knot-utils
+    - zypper install -y python3-pip
     - zypper install --allow-unsigned-rpm -y $(find ./pkg/pkgs -name '*.rpm' | grep -v module | grep -v debug | grep -v devel)
-    - systemctl start kresd@1
-    - kdig @127.0.0.1 nic.cz | grep -qi NOERROR
+    - *apkgtest
 
 opensuse-15.3:pkgtest:
   <<: *pkgtest
@@ -272,10 +260,9 @@ opensuse-15.3:pkgtest:
   image: $CI_REGISTRY/labs/lxc-gitlab-runner/opensuse-15.3
   script:
     - zypper addrepo -G -f https://download.opensuse.org/repositories/home:CZ-NIC:knot-resolver-build/openSUSE_Leap_15.3/home:CZ-NIC:knot-resolver-build.repo
-    - zypper install -y knot-utils
+    - zypper install -y python3-pip
     - zypper install --allow-unsigned-rpm -y $(find ./pkg/pkgs -name '*.rpm' | grep -v module | grep -v debug | grep -v devel)
-    - systemctl start kresd@1
-    - kdig @127.0.0.1 nic.cz | grep -qi NOERROR
+    - *apkgtest
 
 rocky-8:pkgtest:
   <<: *pkgtest
@@ -284,10 +271,9 @@ rocky-8:pkgtest:
   image: $CI_REGISTRY/labs/lxc-gitlab-runner/rocky-8
   script:
     - dnf install -y epel-release
-    - dnf install -y knot-utils findutils
+    - dnf install -y findutils python39-pip
     - dnf install -y $(find ./pkg/pkgs -name '*.rpm' | grep -v module | grep -v debug | grep -v devel)
-    - systemctl start kresd@1
-    - kdig @127.0.0.1 nic.cz | grep -qi NOERROR
+    - *apkgtest
 
 ubuntu-18.04:pkgtest:
   <<: *pkgtest
diff --git a/distro/tests/extra/all/control b/distro/tests/extra/all/control
new file mode 100644 (file)
index 0000000..e77964d
--- /dev/null
@@ -0,0 +1,2 @@
+{# This adds all tests for manager's packaging #}
+{% include 'distro/tests/manager-packaging/control' %}
diff --git a/distro/tests/manager-packaging/control b/distro/tests/manager-packaging/control
new file mode 100644 (file)
index 0000000..09bc0e7
--- /dev/null
@@ -0,0 +1,24 @@
+{# Test that kresctl command exists and is in $PATH #}
+Tests: kresctl.sh
+Tests-Directory: manager/tests/packaging
+
+
+{# Tests that manager can be started with default config and it resolves some domains #}
+Tests: systemd_service.sh
+Tests-Directory: manager/tests/packaging
+Restrictions: needs-root
+{% if distro.match('fedora') -%}
+Depends: knot-utils
+{% elif distro.match('debian') or distro.match('ubuntu') -%}
+Depends: knot-dnsutils
+{% elif distro.match('arch') -%}
+Depends: knot
+{% elif distro.match('opensuse') -%}
+Depends: knot-utils
+{% elif distro.match('rocky') -%}
+Depends: knot-utils
+{% elif distro.match('centos') -%}
+Depends: knot-utils
+{% else -%}
+Depends: unsupported-distro-this-package-does-not-exist-and-the-test-should-fail
+{%- endif %}
index 72058b2588c8be2da816cb7f4d8cdad403592217..ce524b6f0f172d3fa9f8eed7c96047bfbbbb906c 100644 (file)
@@ -1,3 +1,6 @@
+id: distro
+rundir: /run/knot-resolver
+workers: 2
 cache:
   storage: /var/cache/knot-resolver
 logging:
@@ -5,9 +8,5 @@ logging:
 network:
   listen:
     - interface: 127.0.0.1@53
-server:
-  id: distro
-  workers: 2
-  rundir: /run/knot-resolver
-  management:
-    unix-socket: /run/knot-resolver/manager.sock
+management:
+  unix-socket: /run/knot-resolver/manager.sock
index 73ffa46fa20cecbfb25b03c34ea840ba4726a843..3fd5314f81eab4cb4c8c092af0cd679b2af127e9 100644 (file)
@@ -1,10 +1,19 @@
 from typing import List, Optional, Set, Union
 
-from typing_extensions import Literal, TypeAlias
+from typing_extensions import Literal
 
 from knot_resolver_manager.datamodel.types import CheckedPath, TimeUnit
 from knot_resolver_manager.utils.modeling import BaseSchema
 
+try:
+    # On Debian 10, the typing_extensions library does not contain TypeAlias.
+    # We don't strictly need the import for anything except for type checking,
+    # so this try-except makes sure it works either way.
+    from typing_extensions import TypeAlias  # pylint: disable=ungrouped-imports
+except ImportError:
+    TypeAlias = None  # type: ignore
+
+
 LogLevelEnum = Literal["crit", "err", "warning", "notice", "info", "debug"]
 LogTargetEnum = Literal["syslog", "stderr", "stdout"]
 LogGroupsEnum: TypeAlias = Literal[
index 60cf2fad755805d36e09b673ed2ead2ae1c9347a..85549e65f8165e53d5baa426288d308ff107ab46 100644 (file)
@@ -3,6 +3,16 @@
 set -o errexit
 set -o nounset
 
+function install_pipx {
+       python3 -m pip install --user pipx
+       python3 -m pipx ensurepath
+       export PATH="$PATH:/root/.local/bin"  # hack to make binaries installed with pipx work
+}
+
+function pipx {
+       python3 -m pipx ${@}
+}
+
 function init_debian {
     export DEBIAN_FRONTEND=noninteractive
 
@@ -38,10 +48,8 @@ else
 fi
 
 # install apkg
-python3 -m pip install --user pipx
-python3 -m pipx ensurepath
-PATH="$PATH:/root/.local/bin"  # hack to make binaries installed with pipx work
-python3 -m pipx install apkg
+install_pipx
+pipx install apkg
 
 # prepare the repo
 #git clone https://gitlab.nic.cz/knot/knot-resolver
old mode 100644 (file)
new mode 100755 (executable)
index 48fca73..579f1a1
@@ -4,4 +4,4 @@
 set -e
 
 # We expect `kresctl` command to exist in $PATH
-command -q -v kresctl
\ No newline at end of file
+command -v kresctl > /dev/null
old mode 100644 (file)
new mode 100755 (executable)
index 2afb5f8..e942b70
@@ -9,8 +9,18 @@ if test "$(id -u)" -ne 0; then
     exit 1
 fi
 
+# We will be starting a systemd service, but another tests might do the same
+# so this makes sure there is nothing left after we exit
+trap "systemctl stop knot-resolver.service" EXIT
 
-systemctl start knot-resolver.service
 
-# check that the resolvers are actually running
-kdig @127.0.0.1 nic.cz
\ No newline at end of file
+if ! systemctl start knot-resolver.service; then
+       echo
+       echo "Failed to start service, here is its status:"
+       systemctl status knot-resolver.service
+       
+else
+       # check that the resolvers are actually running
+       kdig @127.0.0.1 nic.cz
+fi
+