From 8fc82508296c739244437f0d32c00b7aeaeb1a44 Mon Sep 17 00:00:00 2001 From: Markus Frei Date: Tue, 7 Jan 2025 13:12:55 +0100 Subject: [PATCH] chore: switch project to Python 3.9 --- .github/workflows/nuitka-compile.yml | 2 +- BUILD.rst | 6 ++--- CHANGELOG.md | 1 + INSTALL.rst | 10 ++++---- README.md | 2 +- build/shared/venv.sh | 12 +++++----- .../containerfiles/archlinux-vlatest | 2 +- .../unit-test/containerfiles/debian-v11 | 2 +- .../unit-test/containerfiles/debian-v12 | 2 +- .../unit-test/containerfiles/fedora-v41 | 2 +- .../unit-test/containerfiles/rhel-v8 | 10 ++++---- .../unit-test/containerfiles/rhel-v9 | 11 +++++---- .../unit-test/containerfiles/sles-v15 | 23 ------------------- .../unit-test/containerfiles/ubuntu-v2004 | 12 ++++++---- .../unit-test/containerfiles/ubuntu-v2204 | 2 +- .../unit-test/containerfiles/ubuntu-v2404 | 2 +- check-plugins/cpu-usage/unit-test/run | 12 ---------- 17 files changed, 41 insertions(+), 72 deletions(-) delete mode 100644 check-plugins/cpu-usage/unit-test/containerfiles/sles-v15 diff --git a/.github/workflows/nuitka-compile.yml b/.github/workflows/nuitka-compile.yml index d7a18eff..9f1fa076 100644 --- a/.github/workflows/nuitka-compile.yml +++ b/.github/workflows/nuitka-compile.yml @@ -80,7 +80,7 @@ jobs: - run: 'python.exe -m pip install --upgrade ordered-set Nuitka Nuitka' # install 3rd party libraries for all check plugins - - run: 'python.exe -m pip install --requirement ${{ github.workspace }}\monitoring-plugins\requirements.txt' + - run: 'python.exe -m pip install --requirement ${{ github.workspace }}\monitoring-plugins\requirements.txt --require-hashes' # info in case of errors - run: 'python.exe -m pip list' diff --git a/BUILD.rst b/BUILD.rst index 7b421a4a..34deefc2 100644 --- a/BUILD.rst +++ b/BUILD.rst @@ -131,7 +131,7 @@ Compile using PyInstaller: cd cd monitoring-plugins - python3.9 -m pip install --requirement requirements.txt + python3.9 -m pip install --requirement requirements.txt --require-hashes # compile with pyinstaller cd check-plugins/disk-usage @@ -178,7 +178,7 @@ Compile using Nuitka: cd cd monitoring-plugins - python3.9 -m pip install --requirement requirements.txt + python3.9 -m pip install --requirement requirements.txt --require-hashes # compile with nuitka cd check-plugins/disk-usage @@ -271,7 +271,7 @@ Setup Python on Windows: python.exe -m pip install --upgrade pip wheel setuptools python.exe -m pip install --upgrade ordered-set Nuitka pyinstaller - python.exe -m pip install --requirement=requirements.txt + python.exe -m pip install --requirement requirements.txt --require-hashes Compile using Nuitka+MSVC: diff --git a/CHANGELOG.md b/CHANGELOG.md index f020523a..76fd511a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,7 @@ Icinga Director: Monitoring Plugins: +* Since some libraries such as pymysql or openssl have security vulnerabilities for Python 3.6, the project now requires Python 3.9+ to use the plugins in the source code variant. * jitsi-videobridge-stats: Remove deprecated values ([PR #780](https://github.com/Linuxfabrik/monitoring-plugins/pull/780), thanks to [SnejPro](https://github.com/SnejPro)) * jitsi-videobridge-stats: Remove deprecated warning and critical parameters, always returns OK diff --git a/INSTALL.rst b/INSTALL.rst index 748bcb4e..8fbb3bc4 100644 --- a/INSTALL.rst +++ b/INSTALL.rst @@ -15,10 +15,10 @@ In general, you have two options: OS, Motivation, Install Linux, "Want to use my OS's package manager and have distro that uses rpm/deb package formats","Package from `Linuxfabrik's Repo Server `_" - Linux, "Don't want to use my OS's package manager or have distro that uses package formats other than rpm/deb and can't run Python 3.6+",Binaries from .tar or .zip file on `Linuxfabrik's Download Server `_ - Linux, "Want to use the latest development version and Python 3.6+ available", `Source code variant from GitHub `_ + Linux, "Don't want to use my OS's package manager or have distro that uses package formats other than rpm/deb and can't run Python 3.9+",Binaries from .tar or .zip file on `Linuxfabrik's Download Server `_ + Linux, "Want to use the latest development version and Python 3.9+ available", `Source code variant from GitHub `_ Windows,"Want to use EXE files",Binaries in ``/windows`` on `Linuxfabrik's Download Server `_ - Windows,"Want to use the latest development version and Python 3.6+ available", `Source code variant from GitHub `_ + Windows,"Want to use the latest development version and Python 3.9+ available", `Source code variant from GitHub `_ FAQ: @@ -115,7 +115,7 @@ Python: Run from Source Code You may use this if nothing from the above fits your needs. -If you run the Linuxfabrik check plugins directly from source (which is no problem at all), you need to install Python 3 on the remote host. The plugins work with at least Python 3.6, but some of them (currently ``disk-io``) will only run if Python 3.8+ is available. +If you run the Linuxfabrik check plugins directly from source (which is no problem at all), you need to install Python 3.9+ on the remote host. Installation @@ -178,7 +178,7 @@ We try to avoid dependencies on 3rd party OS- or Python-libraries wherever possi .. code-block:: bash python3 -m pip install --upgrade pip - python3 -m pip install --requirement requirements.txt + python3 -m pip install --requirement requirements.txt --require-hashes To make SELinux happy, after installing from source, run: diff --git a/README.md b/README.md index 624d2252..10dd48df 100644 --- a/README.md +++ b/README.md @@ -351,7 +351,7 @@ To avoid problems when passing *parameter values* that start with a `-`, the com ## Python -When running from source, almost all check plugins are happy with at least Python 3.6. All plugins define the `#!/usr/bin/env python3` shebang. +When running from source, almost all check plugins are happy with Python 3.9+. All plugins define the `#!/usr/bin/env python3` shebang. ## Icons diff --git a/build/shared/venv.sh b/build/shared/venv.sh index cf8771b4..c20e8334 100644 --- a/build/shared/venv.sh +++ b/build/shared/venv.sh @@ -1,12 +1,12 @@ #!/usr/bin/env bash -python3 -m venv --system-site-packages pyinstaller +python3.9 -m venv --system-site-packages pyinstaller source pyinstaller/bin/activate -python3 -m pip install --upgrade pip -python3 -m pip install --upgrade wheel -python3 -m pip install --upgrade setuptools -python3 -m pip install pyinstaller +python3.9 -m pip install pip==24.3.1 +python3.9 -m pip install wheel==0.45.1 +python3.9 -m pip install setuptools==50.3.2 +python3.9 -m pip install pyinstaller==6.11.1 # install any libraries specific for the project -python3 -m pip install --requirement=/repos/monitoring-plugins/requirements.txt +python3.9 -m pip install --requirement=/repos/monitoring-plugins/requirements.txt diff --git a/check-plugins/cpu-usage/unit-test/containerfiles/archlinux-vlatest b/check-plugins/cpu-usage/unit-test/containerfiles/archlinux-vlatest index ddb9d6b9..b82f15d5 100644 --- a/check-plugins/cpu-usage/unit-test/containerfiles/archlinux-vlatest +++ b/check-plugins/cpu-usage/unit-test/containerfiles/archlinux-vlatest @@ -16,7 +16,7 @@ ADD https://raw.githubusercontent.com/Linuxfabrik/monitoring-plugins/refs/heads/ RUN python -m venv /tmp/venv && \ . /tmp/venv/bin/activate && \ python -m pip install --upgrade pip && \ - python -m pip install --no-cache-dir --requirement requirements.txt + python -m pip install --no-cache-dir --requirement requirements.txt --require-hashes # Verify Python installation RUN /tmp/venv/bin/python --version diff --git a/check-plugins/cpu-usage/unit-test/containerfiles/debian-v11 b/check-plugins/cpu-usage/unit-test/containerfiles/debian-v11 index f12c91d8..88f0bca8 100644 --- a/check-plugins/cpu-usage/unit-test/containerfiles/debian-v11 +++ b/check-plugins/cpu-usage/unit-test/containerfiles/debian-v11 @@ -15,7 +15,7 @@ ADD https://raw.githubusercontent.com/Linuxfabrik/monitoring-plugins/refs/heads/ # Install dependencies using pip RUN python3 -m pip install --upgrade pip && \ - python3 -m pip install --no-cache-dir --requirement requirements.txt + python3 -m pip install --no-cache-dir --requirement requirements.txt --require-hashes # Verify Python installation RUN python3 --version diff --git a/check-plugins/cpu-usage/unit-test/containerfiles/debian-v12 b/check-plugins/cpu-usage/unit-test/containerfiles/debian-v12 index 05548d52..077eb80c 100644 --- a/check-plugins/cpu-usage/unit-test/containerfiles/debian-v12 +++ b/check-plugins/cpu-usage/unit-test/containerfiles/debian-v12 @@ -17,7 +17,7 @@ ADD https://raw.githubusercontent.com/Linuxfabrik/monitoring-plugins/refs/heads/ RUN python3 -m venv /tmp/venv && \ . /tmp/venv/bin/activate && \ python3 -m pip install --upgrade pip && \ - python3 -m pip install --no-cache-dir --requirement requirements.txt + python3 -m pip install --no-cache-dir --requirement requirements.txt --require-hashes # Verify Python installation RUN python3 --version diff --git a/check-plugins/cpu-usage/unit-test/containerfiles/fedora-v41 b/check-plugins/cpu-usage/unit-test/containerfiles/fedora-v41 index ad07db3d..bf4e28c1 100644 --- a/check-plugins/cpu-usage/unit-test/containerfiles/fedora-v41 +++ b/check-plugins/cpu-usage/unit-test/containerfiles/fedora-v41 @@ -13,7 +13,7 @@ ADD https://raw.githubusercontent.com/Linuxfabrik/monitoring-plugins/refs/heads/ # Install dependencies using pip RUN python3 -m pip install --upgrade pip wheel setuptools && \ - python3 -m pip install --no-cache-dir --requirement requirements.txt + python3 -m pip install --no-cache-dir --requirement requirements.txt --require-hashes # Verify Python installation RUN python3 --version diff --git a/check-plugins/cpu-usage/unit-test/containerfiles/rhel-v8 b/check-plugins/cpu-usage/unit-test/containerfiles/rhel-v8 index b137bb36..67eed4b8 100644 --- a/check-plugins/cpu-usage/unit-test/containerfiles/rhel-v8 +++ b/check-plugins/cpu-usage/unit-test/containerfiles/rhel-v8 @@ -1,8 +1,8 @@ # Base image: Official RHEL 8 FROM registry.access.redhat.com/ubi8 -# Install Python 3 -RUN dnf -y install python3 +# Install Python 3.9 +RUN dnf -y install python3.9 # Install tools RUN dnf -y install https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm && \ @@ -15,11 +15,11 @@ WORKDIR /tmp ADD https://raw.githubusercontent.com/Linuxfabrik/monitoring-plugins/refs/heads/main/requirements.txt /tmp/requirements.txt # Install dependencies using pip -RUN python3 -m pip install --upgrade pip && \ - python3 -m pip install --no-cache-dir --requirement requirements.txt +RUN python3.9 -m pip install --upgrade pip && \ + python3.9 -m pip install --no-cache-dir --requirement requirements.txt --require-hashes # Verify Python installation -RUN python3 --version +RUN python3.9 --version # Default command to keep the container running CMD ["sleep", "infinity"] \ No newline at end of file diff --git a/check-plugins/cpu-usage/unit-test/containerfiles/rhel-v9 b/check-plugins/cpu-usage/unit-test/containerfiles/rhel-v9 index bb8427fb..c555e650 100644 --- a/check-plugins/cpu-usage/unit-test/containerfiles/rhel-v9 +++ b/check-plugins/cpu-usage/unit-test/containerfiles/rhel-v9 @@ -1,8 +1,8 @@ # Base image: Official RHEL 9 FROM registry.access.redhat.com/ubi9 -# Install Python 3 -RUN dnf -y install python3 python3-pip +# Install Python 3.9 +RUN dnf -y install python3.9 python3.9-pip # Install tools RUN dnf -y install https://dl.fedoraproject.org/pub/epel/epel-release-latest-9.noarch.rpm && \ @@ -15,11 +15,12 @@ WORKDIR /tmp ADD https://raw.githubusercontent.com/Linuxfabrik/monitoring-plugins/refs/heads/main/requirements.txt /tmp/requirements.txt # Install dependencies using pip -RUN python3 -m pip install --upgrade pip && \ - python3 -m pip install --no-cache-dir --requirement requirements.txt +RUN dnf -y remove python3-requests +RUN python3.9 -m pip install --upgrade pip && \ + python3.9 -m pip install --no-cache-dir --requirement requirements.txt --require-hashes # Verify Python installation -RUN python3 --version +RUN python3.9 --version # Default command to keep the container running CMD ["sleep", "infinity"] \ No newline at end of file diff --git a/check-plugins/cpu-usage/unit-test/containerfiles/sles-v15 b/check-plugins/cpu-usage/unit-test/containerfiles/sles-v15 deleted file mode 100644 index 7d4e3a15..00000000 --- a/check-plugins/cpu-usage/unit-test/containerfiles/sles-v15 +++ /dev/null @@ -1,23 +0,0 @@ -# Base image: Official SLES 15 -FROM registry.suse.com/suse/sle15:latest - -# Install Python 3 and pip -RUN zypper --non-interactive ref && \ - zypper --non-interactive install python3 python3-pip && \ - zypper clean --all - -# Set the working directory in the container -WORKDIR /tmp - -# Use ADD to download the requirements.txt file -ADD https://raw.githubusercontent.com/Linuxfabrik/monitoring-plugins/refs/heads/main/requirements.txt /tmp/requirements.txt - -# Install dependencies using pip -RUN python3 -m pip install --upgrade pip && \ - python3 -m pip install --no-cache-dir --requirement requirements.txt - -# Verify Python installation -RUN python3 --version - -# Default command to keep the container running -CMD ["sleep", "infinity"] diff --git a/check-plugins/cpu-usage/unit-test/containerfiles/ubuntu-v2004 b/check-plugins/cpu-usage/unit-test/containerfiles/ubuntu-v2004 index 53e7f231..b0a9b4ee 100644 --- a/check-plugins/cpu-usage/unit-test/containerfiles/ubuntu-v2004 +++ b/check-plugins/cpu-usage/unit-test/containerfiles/ubuntu-v2004 @@ -4,9 +4,9 @@ FROM ubuntu:20.04 # Prevent interactive prompts during package installation ENV DEBIAN_FRONTEND=noninteractive -# Update and install Python 3 and pip +# Update and install Python 3.9 and pip RUN apt-get update && \ - apt-get install -y python3 python3-pip && \ + apt-get install -y python3.9 python3.9-venv python3-pip && \ apt-get clean && \ rm -rf /var/lib/apt/lists/* @@ -17,11 +17,13 @@ WORKDIR /tmp ADD https://raw.githubusercontent.com/Linuxfabrik/monitoring-plugins/refs/heads/main/requirements.txt /tmp/requirements.txt # Install dependencies using pip -RUN python3 -m pip install --upgrade pip && \ - python3 -m pip install --no-cache-dir --requirement requirements.txt +RUN python3.9 -m venv /tmp/venv && \ + . /tmp/venv/bin/activate && \ + python3.9 -m pip install --upgrade pip && \ + python3.9 -m pip install --no-cache-dir --requirement requirements.txt --require-hashes # Verify Python installation -RUN python3 --version +RUN python3.9 --version # Default command to keep the container running CMD ["sleep", "infinity"] diff --git a/check-plugins/cpu-usage/unit-test/containerfiles/ubuntu-v2204 b/check-plugins/cpu-usage/unit-test/containerfiles/ubuntu-v2204 index ca25dd65..91fc57d2 100644 --- a/check-plugins/cpu-usage/unit-test/containerfiles/ubuntu-v2204 +++ b/check-plugins/cpu-usage/unit-test/containerfiles/ubuntu-v2204 @@ -18,7 +18,7 @@ ADD https://raw.githubusercontent.com/Linuxfabrik/monitoring-plugins/refs/heads/ # Install dependencies using pip RUN python3 -m pip install --upgrade pip && \ - python3 -m pip install --no-cache-dir --requirement requirements.txt + python3 -m pip install --no-cache-dir --requirement requirements.txt --require-hashes # Verify Python installation RUN python3 --version diff --git a/check-plugins/cpu-usage/unit-test/containerfiles/ubuntu-v2404 b/check-plugins/cpu-usage/unit-test/containerfiles/ubuntu-v2404 index 61080a03..7b0e1448 100644 --- a/check-plugins/cpu-usage/unit-test/containerfiles/ubuntu-v2404 +++ b/check-plugins/cpu-usage/unit-test/containerfiles/ubuntu-v2404 @@ -20,7 +20,7 @@ ADD https://raw.githubusercontent.com/Linuxfabrik/monitoring-plugins/refs/heads/ RUN python3 -m venv /tmp/venv && \ . /tmp/venv/bin/activate && \ python3 -m pip install --upgrade pip && \ - python3 -m pip install --no-cache-dir --requirement requirements.txt + python3 -m pip install --no-cache-dir --requirement requirements.txt --require-hashes # Verify Python installation RUN python3 --version diff --git a/check-plugins/cpu-usage/unit-test/run b/check-plugins/cpu-usage/unit-test/run index 840de51e..2f18d7b4 100755 --- a/check-plugins/cpu-usage/unit-test/run +++ b/check-plugins/cpu-usage/unit-test/run @@ -90,18 +90,6 @@ TESTS = [ }, ], }, - { - 'containerfile': 'containerfiles/sles-v15', - 'podman-run-params': '', - 'tests': [ - { - 'run-where': 'container', - 'plugin-params': '', - 'assert-regex': r'\d+\.\d+% -.* user:', - 'assert-retc': 0, - }, - ], - }, { 'containerfile': 'containerfiles/ubuntu-v2004', 'podman-run-params': '',