diff --git a/.github/actions/test-packages/action.yml b/.github/actions/test-packages/action.yml index 2099ed55..20399aac 100644 --- a/.github/actions/test-packages/action.yml +++ b/.github/actions/test-packages/action.yml @@ -10,29 +10,202 @@ inputs: cache_key: description: "The cache key to restore packages" required: true + test_type: + description: "The type of test to run: dependency, library or stream-connector" + required: true runs: using: "composite" steps: - if: ${{ inputs.package_extension == 'rpm' }} - name: Install zstd and Centreon GPG key + name: Install dependencies and configure Centreon repositories + env: + DISTRIB: ${{ inputs.distrib }} + TEST_TYPE: ${{ inputs.test_type }} run: | - dnf install -y zstd + dnf install -y 'dnf-command(config-manager)' epel-release zstd + dnf install -y --allowerasing curl + # Enable additional repos depending on distrib + dnf config-manager --set-enabled powertools 2>/dev/null || true # el8 + dnf config-manager --set-enabled crb 2>/dev/null || true # el9, el10 # Import Centreon GPG key - GPG_KEY_URL="https://yum-gpg.centreon.com/RPM-GPG-KEY-CES" - curl -sSL "$GPG_KEY_URL" -o RPM-GPG-KEY-CES + curl -sSL "https://yum-gpg.centreon.com/RPM-GPG-KEY-CES" -o RPM-GPG-KEY-CES rpm --import RPM-GPG-KEY-CES + # Select the Centreon version based on distribution + if [[ "$DISTRIB" == "el8" || "$DISTRIB" == "el9" ]]; then + CENTREON_VERSION="25.10" + else + CENTREON_VERSION="26.10" # el10 - repo not yet available + fi + # Add Centreon plugins and standard repositories + { + echo '[centreon-plugins-stable]' + echo 'name=centreon plugins stable x86_64' + echo "baseurl=https://packages.centreon.com/rpm-plugins/$DISTRIB/stable/x86_64" + echo 'enabled=1' + echo 'gpgcheck=1' + echo 'gpgkey=https://yum-gpg.centreon.com/RPM-GPG-KEY-CES' + echo '' + echo '[centreon-plugins-stable-noarch]' + echo 'name=centreon plugins stable noarch' + echo "baseurl=https://packages.centreon.com/rpm-plugins/$DISTRIB/stable/noarch" + echo 'enabled=1' + echo 'gpgcheck=1' + echo 'gpgkey=https://yum-gpg.centreon.com/RPM-GPG-KEY-CES' + echo '' + echo '[centreon-plugins-testing]' + echo 'name=centreon plugins testing x86_64' + echo "baseurl=https://packages.centreon.com/rpm-plugins/$DISTRIB/testing/x86_64" + echo 'enabled=1' + echo 'gpgcheck=1' + echo 'gpgkey=https://yum-gpg.centreon.com/RPM-GPG-KEY-CES' + echo '' + echo '[centreon-plugins-testing-noarch]' + echo 'name=centreon plugins testing noarch' + echo "baseurl=https://packages.centreon.com/rpm-plugins/$DISTRIB/testing/noarch" + echo 'enabled=1' + echo 'gpgcheck=1' + echo 'gpgkey=https://yum-gpg.centreon.com/RPM-GPG-KEY-CES' + echo '' + echo '[centreon-plugins-unstable]' + echo 'name=centreon plugins unstable x86_64' + echo "baseurl=https://packages.centreon.com/rpm-plugins/$DISTRIB/unstable/x86_64" + echo 'enabled=1' + echo 'gpgcheck=1' + echo 'gpgkey=https://yum-gpg.centreon.com/RPM-GPG-KEY-CES' + echo '' + echo '[centreon-plugins-unstable-noarch]' + echo 'name=centreon plugins unstable noarch' + echo "baseurl=https://packages.centreon.com/rpm-plugins/$DISTRIB/unstable/noarch" + echo 'enabled=1' + echo 'gpgcheck=1' + echo 'gpgkey=https://yum-gpg.centreon.com/RPM-GPG-KEY-CES' + if [[ "$TEST_TYPE" != "dependency" ]]; then + echo '' + echo "[centreon-${CENTREON_VERSION}-stable]" + echo 'name=Centreon open source software repository.' + echo "baseurl=https://packages.centreon.com/rpm-standard/${CENTREON_VERSION}/$DISTRIB/stable/x86_64/" + echo 'enabled=1' + echo 'gpgcheck=1' + echo 'gpgkey=https://yum-gpg.centreon.com/RPM-GPG-KEY-CES' + echo 'module_hotfixes=1' + echo '' + echo "[centreon-${CENTREON_VERSION}-stable-noarch]" + echo 'name=Centreon open source software repository.' + echo "baseurl=https://packages.centreon.com/rpm-standard/${CENTREON_VERSION}/$DISTRIB/stable/noarch/" + echo 'enabled=1' + echo 'gpgcheck=1' + echo 'gpgkey=https://yum-gpg.centreon.com/RPM-GPG-KEY-CES' + echo 'module_hotfixes=1' + echo '' + echo "[centreon-${CENTREON_VERSION}-testing-release]" + echo 'name=Centreon open source software repository.' + echo "baseurl=https://packages.centreon.com/rpm-standard/${CENTREON_VERSION}/$DISTRIB/testing-release/x86_64/" + echo 'enabled=1' + echo 'gpgcheck=1' + echo 'gpgkey=https://yum-gpg.centreon.com/RPM-GPG-KEY-CES' + echo 'module_hotfixes=1' + echo '' + echo "[centreon-${CENTREON_VERSION}-testing-release-noarch]" + echo 'name=Centreon open source software repository.' + echo "baseurl=https://packages.centreon.com/rpm-standard/${CENTREON_VERSION}/$DISTRIB/testing-release/noarch/" + echo 'enabled=1' + echo 'gpgcheck=1' + echo 'gpgkey=https://yum-gpg.centreon.com/RPM-GPG-KEY-CES' + echo 'module_hotfixes=1' + echo '' + echo "[centreon-${CENTREON_VERSION}-testing-hotfix]" + echo 'name=Centreon open source software repository.' + echo "baseurl=https://packages.centreon.com/rpm-standard/${CENTREON_VERSION}/$DISTRIB/testing-hotfix/x86_64/" + echo 'enabled=1' + echo 'gpgcheck=1' + echo 'gpgkey=https://yum-gpg.centreon.com/RPM-GPG-KEY-CES' + echo 'module_hotfixes=1' + echo '' + echo "[centreon-${CENTREON_VERSION}-testing-hotfix-noarch]" + echo 'name=Centreon open source software repository.' + echo "baseurl=https://packages.centreon.com/rpm-standard/${CENTREON_VERSION}/$DISTRIB/testing-hotfix/noarch/" + echo 'enabled=1' + echo 'gpgcheck=1' + echo 'gpgkey=https://yum-gpg.centreon.com/RPM-GPG-KEY-CES' + echo 'module_hotfixes=1' + echo '' + echo "[centreon-${CENTREON_VERSION}-unstable]" + echo 'name=Centreon open source software repository.' + echo "baseurl=https://packages.centreon.com/rpm-standard/${CENTREON_VERSION}/$DISTRIB/unstable/x86_64/" + echo 'enabled=1' + echo 'gpgcheck=1' + echo 'gpgkey=https://yum-gpg.centreon.com/RPM-GPG-KEY-CES' + echo 'module_hotfixes=1' + echo '' + echo "[centreon-${CENTREON_VERSION}-unstable-noarch]" + echo 'name=Centreon open source software repository.' + echo "baseurl=https://packages.centreon.com/rpm-standard/${CENTREON_VERSION}/$DISTRIB/unstable/noarch/" + echo 'enabled=1' + echo 'gpgcheck=1' + echo 'gpgkey=https://yum-gpg.centreon.com/RPM-GPG-KEY-CES' + echo 'module_hotfixes=1' + fi + } > /etc/yum.repos.d/centreon-plugins.repo shell: bash - if: ${{ inputs.package_extension == 'deb' }} - name: Install zstd and Centreon GPG key + name: Install dependencies and configure Centreon repositories + env: + DISTRIB: ${{ inputs.distrib }} + TEST_TYPE: ${{ inputs.test_type }} run: | export DEBIAN_FRONTEND=noninteractive + # Avoid apt to clean packages cache directory + rm -f /etc/apt/apt.conf.d/docker-clean apt-get update apt-get install -y zstd wget gpg wget -O- https://apt-key.centreon.com | gpg --dearmor | tee /etc/apt/trusted.gpg.d/centreon.gpg > /dev/null 2>&1 - # Avoid apt to clean packages cache directory - rm -f /etc/apt/apt.conf.d/docker-clean + # Select the correct repo and version depending on distrib + # Format <= 24.10: https://packages.centreon.com/{repo}-{stability}/ {distrib} main + # Format >= 25.10: https://packages.centreon.com/{repo}/ {distrib}-{version}-{stability} main + if [[ "$DISTRIB" == "jammy" ]]; then + standard_base="ubuntu-standard-24.04" + standard_distrib="$DISTRIB" + plugins_prefix="ubuntu-plugins" + new_repo_format=false + elif [[ "$DISTRIB" == "noble" ]]; then + standard_base="ubuntu-standard-24.10" + standard_distrib="$DISTRIB" + plugins_prefix="ubuntu-plugins" + new_repo_format=false + elif [[ "$DISTRIB" == "bullseye" ]]; then + standard_base="apt-standard-24.04" + standard_distrib="$DISTRIB" + plugins_prefix="apt-plugins" + new_repo_format=false + elif [[ "$DISTRIB" == "bookworm" ]]; then + standard_base="apt-standard" + standard_distrib="${DISTRIB}-25.10" + plugins_prefix="apt-plugins" + new_repo_format=true + elif [[ "$DISTRIB" == "trixie" ]]; then + standard_base="apt-standard" + standard_distrib="${DISTRIB}-26.10" # repo not yet available + plugins_prefix="apt-plugins" + new_repo_format=true + fi + # Add Centreon standard repository (provides centreon-broker-core and other core packages) + if [[ "$TEST_TYPE" != "dependency" ]]; then + if [[ "$new_repo_format" == "true" ]]; then + echo "deb https://packages.centreon.com/${standard_base}/ ${standard_distrib}-stable main" | tee /etc/apt/sources.list.d/centreon-standard.list + echo "deb https://packages.centreon.com/${standard_base}/ ${standard_distrib}-testing main" | tee -a /etc/apt/sources.list.d/centreon-standard.list + echo "deb https://packages.centreon.com/${standard_base}/ ${standard_distrib}-unstable main" | tee -a /etc/apt/sources.list.d/centreon-standard.list + else + echo "deb https://packages.centreon.com/${standard_base}-stable/ ${standard_distrib} main" | tee /etc/apt/sources.list.d/centreon-standard.list + echo "deb https://packages.centreon.com/${standard_base}-testing/ ${standard_distrib} main" | tee -a /etc/apt/sources.list.d/centreon-standard.list + echo "deb https://packages.centreon.com/${standard_base}-unstable/ ${standard_distrib} main" | tee -a /etc/apt/sources.list.d/centreon-standard.list + fi + fi + # Add Centreon plugins repositories (stable, testing, unstable) + echo "deb https://packages.centreon.com/${plugins_prefix}-stable/ $DISTRIB main" | tee /etc/apt/sources.list.d/centreon-plugins.list + echo "deb https://packages.centreon.com/${plugins_prefix}-testing/ $DISTRIB main" | tee -a /etc/apt/sources.list.d/centreon-plugins.list + echo "deb https://packages.centreon.com/${plugins_prefix}-unstable/ $DISTRIB main" | tee -a /etc/apt/sources.list.d/centreon-plugins.list apt-get update shell: bash @@ -47,27 +220,47 @@ runs: name: Check packages installation / uninstallation env: DISTRIB: ${{ inputs.distrib }} + TEST_TYPE: ${{ inputs.test_type }} run: | error_log="install_error_$DISTRIB.log" for package in ./*.rpm; do echo "Installing package: $package" - # Install package, then uninstall it with all his dependencies echo "Package installation..." error_output=$(dnf install -y "$package" 2>&1) || { echo "$error_output" >> "$error_log"; echo "Error during installation of the package $package" >> "$error_log"; true; } echo "Package installation done." pack_name=$(echo "$package" | sed 's/\.\///' | sed 's/-[0-9\.-]*.el[0-9]*..*.rpm//') - if [[ -f ./tests/packaging/$pack_name.lua ]]; then - echo "Testing package..." - error_output=$(lua "tests/packaging/${pack_name}.lua" 2>&1) || { echo "$error_output" >> "$error_log"; echo "Error during the usage test of the package $package" >> "$error_log"; true; } - echo "Testing done." - else - echo "No test script found for the package $package" - fi + case "$TEST_TYPE" in + dependency) + test_dir="tests/packaging/dependencies" + if [[ -f "${test_dir}/${pack_name}.lua" ]]; then + echo "Testing package..." + error_output=$(lua "${test_dir}/${pack_name}.lua" 2>&1) || { echo "$error_output" >> "$error_log"; echo "Error during the usage test of the package $package" >> "$error_log"; true; } + echo "Testing done." + else + echo "No test script found for the package $package" + fi + ;; + library) + test_dir="tests/packaging/library" + for test_script in "${test_dir}"/*.lua; do + [[ -f "$test_script" ]] || continue + echo "Running test: $test_script" + error_output=$(lua "$test_script" 2>&1) || { echo "$error_output" >> "$error_log"; echo "Error during $test_script" >> "$error_log"; true; } + done + ;; + stream-connector) + test_dir="tests/packaging/stream-connectors" + for test_script in "${test_dir}"/*.lua; do + [[ -f "$test_script" ]] || continue + echo "Running test: $test_script" + error_output=$(lua "$test_script" 2>&1) || { echo "$error_output" >> "$error_log"; echo "Error during $test_script" >> "$error_log"; true; } + done + ;; + esac echo "Package uninstallation..." error_output=$(dnf autoremove --setopt=keepcache=True -y "$pack_name" 2>&1) || { echo "$error_output" >> "$error_log"; echo "Error during autoremove of the package $package" >> "$error_log"; true; } echo "Package uninstallation done." done - # If the file error_log exists and is not empty, the workflow is in error if [[ -s "$error_log" ]]; then cat "$error_log" exit 1 @@ -78,27 +271,47 @@ runs: name: Check packages installation / uninstallation env: DISTRIB: ${{ inputs.distrib }} + TEST_TYPE: ${{ inputs.test_type }} run: | error_log="install_error_${DISTRIB}.log" for package in ./*.deb; do echo "Installing package: $package" - # Install package, then uninstall it with all his dependencies echo "Package installation..." error_output=$(apt-get install -y "$package" 2>&1) || { echo "$error_output" >> "$error_log"; echo "Error during installation of the package $package" >> "$error_log"; true; } echo "Package installation done." pack_name=$(echo "$package" | sed 's/\.\///' | sed 's/_[0-9\.-]*~[a-z]*_.*\.deb//') - if [[ -f "./tests/packaging/${pack_name}.lua" ]]; then - echo "Testing package..." - error_output=$(lua "tests/packaging/${pack_name}.lua" 2>&1) || { echo "$error_output" >> "$error_log"; echo "Error during the usage test of the package $package" >> "$error_log"; true; } - echo "Testing done." - else - echo "No test script found for the package $package" - fi + case "$TEST_TYPE" in + dependency) + test_dir="tests/packaging/dependencies" + if [[ -f "${test_dir}/${pack_name}.lua" ]]; then + echo "Testing package..." + error_output=$(lua "${test_dir}/${pack_name}.lua" 2>&1) || { echo "$error_output" >> "$error_log"; echo "Error during the usage test of the package $package" >> "$error_log"; true; } + echo "Testing done." + else + echo "No test script found for the package $package" + fi + ;; + library) + test_dir="tests/packaging/library" + for test_script in "${test_dir}"/*.lua; do + [[ -f "$test_script" ]] || continue + echo "Running test: $test_script" + error_output=$(lua "$test_script" 2>&1) || { echo "$error_output" >> "$error_log"; echo "Error during $test_script" >> "$error_log"; true; } + done + ;; + stream-connector) + test_dir="tests/packaging/stream-connectors" + for test_script in "${test_dir}"/*.lua; do + [[ -f "$test_script" ]] || continue + echo "Running test: $test_script" + error_output=$(lua "$test_script" 2>&1) || { echo "$error_output" >> "$error_log"; echo "Error during $test_script" >> "$error_log"; true; } + done + ;; + esac echo "Package uninstallation..." error_output=$(apt-get autoremove -y --purge "$pack_name" 2>&1) || { echo "$error_output" >> "$error_log"; echo "Error during autoremove of the package $package" >> "$error_log"; true; } echo "Package uninstallation done." done - # If the file error_log exists and is not empty, the workflow is in error if [[ -s "$error_log" ]]; then cat "$error_log" exit 1 diff --git a/.github/workflows/lua-cffi.yml b/.github/workflows/lua-cffi.yml index 42c6cb11..e69983a3 100644 --- a/.github/workflows/lua-cffi.yml +++ b/.github/workflows/lua-cffi.yml @@ -177,6 +177,7 @@ jobs: package_extension: ${{ matrix.package_extension }} distrib: ${{ matrix.distrib }} cache_key: ${{ github.sha }}-${{ github.run_id }}-${{ matrix.package_extension }}-lua-cffi-${{ matrix.distrib }} + test_type: dependency - name: Upload error log if: failure() diff --git a/.github/workflows/lua-lsqlite3.yml b/.github/workflows/lua-lsqlite3.yml index 8b4bbdd5..f0b3fff9 100644 --- a/.github/workflows/lua-lsqlite3.yml +++ b/.github/workflows/lua-lsqlite3.yml @@ -169,6 +169,7 @@ jobs: package_extension: ${{ matrix.package_extension }} distrib: ${{ matrix.distrib }} cache_key: ${{ github.sha }}-${{ github.run_id }}-${{ matrix.package_extension }}-lua-lsqlite3-${{ matrix.distrib }} + test_type: dependency - name: Upload error log if: failure() diff --git a/.github/workflows/lua-sql-mysql.yml b/.github/workflows/lua-sql-mysql.yml index 4b9f1f94..f6936db0 100644 --- a/.github/workflows/lua-sql-mysql.yml +++ b/.github/workflows/lua-sql-mysql.yml @@ -136,6 +136,7 @@ jobs: package_extension: ${{ matrix.package_extension }} distrib: ${{ matrix.distrib }} cache_key: ${{ github.sha }}-${{ github.run_id }}-rpm-lua-sql-mysql-${{ matrix.distrib }} + test_type: dependency - name: Upload error log if: failure() diff --git a/.github/workflows/lua-tz.yml b/.github/workflows/lua-tz.yml index 4e231988..2b1d97e9 100644 --- a/.github/workflows/lua-tz.yml +++ b/.github/workflows/lua-tz.yml @@ -146,6 +146,7 @@ jobs: package_extension: ${{ matrix.package_extension }} distrib: ${{ matrix.distrib }} cache_key: ${{ github.sha }}-${{ github.run_id }}-${{ matrix.package_extension }}-lua-tz-${{ matrix.distrib }} + test_type: dependency - name: Upload error log if: failure() diff --git a/.github/workflows/stream-connectors-lib.yml b/.github/workflows/stream-connectors-lib.yml index 0550c756..4dc8b83f 100644 --- a/.github/workflows/stream-connectors-lib.yml +++ b/.github/workflows/stream-connectors-lib.yml @@ -92,13 +92,65 @@ jobs: stability: ${{ needs.get-environment.outputs.stability }} artifact_name: "package-stream-connectors-lib-${{ matrix.distrib }}" + test-packages: + needs: [get-environment, package] + strategy: + fail-fast: false + matrix: + include: + - package_extension: rpm + image: almalinux:8 + distrib: el8 + - package_extension: rpm + image: almalinux:9 + distrib: el9 +# - package_extension: rpm +# image: almalinux:10 +# distrib: el10 + - package_extension: deb + image: debian:bullseye + distrib: bullseye + - package_extension: deb + image: debian:bookworm + distrib: bookworm +# - package_extension: deb +# image: debian:trixie +# distrib: trixie + - package_extension: deb + image: ubuntu:jammy + distrib: jammy + - package_extension: deb + image: ubuntu:noble + distrib: noble + runs-on: ubuntu-24.04 + container: + image: ${{ matrix.image }} + name: test packages on ${{ matrix.package_extension }} ${{ matrix.distrib }} + steps: + - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 + + - name: Test packaged libs + uses: ./.github/actions/test-packages + with: + package_extension: ${{ matrix.package_extension }} + distrib: ${{ matrix.distrib }} + cache_key: ${{ github.sha }}-${{ github.run_id }}-${{ matrix.package_extension }}-${{ matrix.distrib }} + test_type: library + + - name: Upload error log + if: failure() + uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5.0.0 + with: + name: install_error_log_${{ matrix.distrib }} + path: install_error_${{ matrix.distrib }}.log + deliver-rpm: if: ${{ contains(fromJson('["unstable", "testing", "stable"]'), needs.get-environment.outputs.stability) }} - needs: [get-environment, package] + needs: [get-environment, package, test-packages] runs-on: ubuntu-24.04 strategy: matrix: - distrib: [el8, el9, el10] + distrib: [el8, el9] #, el10] name: deliver ${{ matrix.distrib }} steps: @@ -116,11 +168,11 @@ jobs: deliver-deb: if: ${{ contains(fromJson('["unstable", "testing", "stable"]'), needs.get-environment.outputs.stability) }} - needs: [get-environment, package] + needs: [get-environment, package, test-packages] runs-on: ubuntu-24.04 strategy: matrix: - distrib: [bullseye, bookworm, trixie, jammy, noble] + distrib: [bullseye, bookworm, jammy, noble] #, trixie, jammy, noble] name: deliver ${{ matrix.distrib }} steps: diff --git a/.github/workflows/stream-connectors.yml b/.github/workflows/stream-connectors.yml index f3631a66..12a07a47 100644 --- a/.github/workflows/stream-connectors.yml +++ b/.github/workflows/stream-connectors.yml @@ -168,13 +168,68 @@ jobs: stability: ${{ needs.get-environment.outputs.stability }} artifact_name: "package-${{ matrix.connector_path }}-${{ matrix.distrib }}" + test-packages: + if: false + needs: [get-environment, detect-changes, package] + strategy: + fail-fast: false + matrix: + distrib: [el8, el9, el10, bullseye, bookworm, trixie, jammy, noble] + connector_path: ${{ fromJson(needs.detect-changes.outputs.connectors) }} + include: + - distrib: el8 + package_extension: rpm + image: almalinux:8 + - distrib: el9 + package_extension: rpm + image: almalinux:9 +# - distrib: el10 +# package_extension: rpm +# image: almalinux:10 + - distrib: bullseye + package_extension: deb + image: debian:bullseye + - distrib: bookworm + package_extension: deb + image: debian:bookworm +# - distrib: trixie +# package_extension: deb +# image: debian:trixie + - distrib: jammy + package_extension: deb + image: ubuntu:jammy + - distrib: noble + package_extension: deb + image: ubuntu:noble + runs-on: ubuntu-24.04 + container: + image: ${{ matrix.image }} + name: Test ${{ matrix.distrib }} ${{ matrix.connector_path }} + steps: + - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 + + - name: Test packaged connector + uses: ./.github/actions/test-packages + with: + package_extension: ${{ matrix.package_extension }} + distrib: ${{ matrix.distrib }} + cache_key: ${{ github.sha }}-${{ github.run_id }}-${{ matrix.package_extension }}-${{ matrix.connector_path }}-${{ matrix.distrib }} + test_type: stream-connector + + - name: Upload error log + if: failure() + uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5.0.0 + with: + name: install_error_log_${{ matrix.connector_path }}_${{ matrix.distrib }} + path: install_error_${{ matrix.distrib }}.log + deliver-rpm: if: ${{ contains(fromJson('["unstable", "testing", "stable"]'), needs.get-environment.outputs.stability) }} - needs: [get-environment, detect-changes, package] + needs: [get-environment, detect-changes, package, test-packages] runs-on: ubuntu-24.04 strategy: matrix: - distrib: [el8, el9, el10] + distrib: [el8, el9] #, el10] connector_path: ${{ fromJson(needs.detect-changes.outputs.connectors) }} name: Deliver ${{ matrix.distrib }} ${{ matrix.connector_path }} @@ -193,11 +248,11 @@ jobs: deliver-deb: if: ${{ contains(fromJson('["unstable", "testing", "stable"]'), needs.get-environment.outputs.stability) }} - needs: [get-environment, detect-changes, package] + needs: [get-environment, detect-changes, package, test-packages] runs-on: ubuntu-24.04 strategy: matrix: - distrib: [bullseye, bookworm, trixie, jammy, noble] + distrib: [bullseye, bookworm, jammy, noble] #, trixie, jammy, noble] connector_path: ${{ fromJson(needs.detect-changes.outputs.connectors) }} name: Deliver ${{ matrix.distrib }} ${{ matrix.connector_path }} diff --git a/packaging/connectors-lib/centreon-stream-connectors-lib.yaml b/packaging/connectors-lib/centreon-stream-connectors-lib.yaml index 721a11e5..e3492391 100644 --- a/packaging/connectors-lib/centreon-stream-connectors-lib.yaml +++ b/packaging/connectors-lib/centreon-stream-connectors-lib.yaml @@ -27,12 +27,12 @@ overrides: rpm: depends: - lua-socket >= 3.0 - - centreon-broker-core >= 24.10.0 + - centreon-broker-core >= 24.04.0 - lua-curl >= 0.3.13-10 - lua deb: depends: - - "centreon-broker-core (>= 24.10.0)" + - "centreon-broker-core (>= 24.04.0)" - "lua-socket (>= 3.0~)" - "lua-curl (>= 0.3.13-10)" - "lua@luaver@" diff --git a/tests/packaging/lua-cffi.lua b/tests/packaging/dependencies/lua-cffi.lua similarity index 100% rename from tests/packaging/lua-cffi.lua rename to tests/packaging/dependencies/lua-cffi.lua diff --git a/tests/packaging/lua-lsqlite3.lua b/tests/packaging/dependencies/lua-lsqlite3.lua similarity index 100% rename from tests/packaging/lua-lsqlite3.lua rename to tests/packaging/dependencies/lua-lsqlite3.lua diff --git a/tests/packaging/lua-sql-mysql.lua b/tests/packaging/dependencies/lua-sql-mysql.lua similarity index 100% rename from tests/packaging/lua-sql-mysql.lua rename to tests/packaging/dependencies/lua-sql-mysql.lua diff --git a/tests/packaging/lua-tz.lua b/tests/packaging/dependencies/lua-tz.lua similarity index 100% rename from tests/packaging/lua-tz.lua rename to tests/packaging/dependencies/lua-tz.lua diff --git a/tests/packaging/library/centreon-stream-connectors-lib.lua b/tests/packaging/library/centreon-stream-connectors-lib.lua new file mode 100644 index 00000000..1aec1f41 --- /dev/null +++ b/tests/packaging/library/centreon-stream-connectors-lib.lua @@ -0,0 +1,107 @@ +#!/usr/bin/env lua + +dofile("tests/packaging/mocks.lua") + +local ok = true +local function assert_eq(label, expected, result) + if expected == result then + print("✓ " .. label) + else + print("✗ " .. label .. " (expected=" .. tostring(expected) .. " got=" .. tostring(result) .. ")") + ok = false + end +end + +local function find_lib_path() + for _, version in ipairs({"5.3", "5.4"}) do + local path = "/usr/share/lua/" .. version + local f = io.open(path .. "/centreon-stream-connectors-lib/sc_common.lua", "r") + if f then + f:close() + return path + end + end +end + +local lib_path = find_lib_path() +if not lib_path then + print("ERROR: centreon-stream-connectors-lib not found in /usr/share/lua/5.3 or /usr/share/lua/5.4") + os.exit(1) +end +print("Library found at: " .. lib_path) + +-- sc_logger +local sc_logger = require("centreon-stream-connectors-lib.sc_logger") +local logger = sc_logger.new("/tmp/test-packaging.log", 3) +print("✓ sc_logger: loaded and instantiated") + +-- sc_common +local sc_common = require("centreon-stream-connectors-lib.sc_common") +local common = sc_common.new(logger) +print("✓ sc_common: loaded and instantiated") +assert_eq("sc_common:ifnil_or_empty(nil) → alt", "alt", common:ifnil_or_empty(nil, "alt")) +assert_eq("sc_common:ifnil_or_empty(\"\") → alt", "alt", common:ifnil_or_empty("", "alt")) +assert_eq("sc_common:ifnil_or_empty(value) → value", "kept", common:ifnil_or_empty("kept", "alt")) +assert_eq("sc_common:if_wrong_type(ok) → value", 42, common:if_wrong_type(42, "number", 0)) +assert_eq("sc_common:if_wrong_type(bad) → default", 0, common:if_wrong_type("str", "number", 0)) +assert_eq("sc_common:boolean_to_number(true) → 1", 1, common:boolean_to_number(true)) +assert_eq("sc_common:boolean_to_number(false) → 0", 0, common:boolean_to_number(false)) +assert_eq("sc_common:split result[1]", "a", common:split("a,b,c", ",")[1]) +assert_eq("sc_common:split result[3]", "c", common:split("a,b,c", ",")[3]) +assert_eq("sc_common:compare_numbers(<)", true, common:compare_numbers(1, 2, "<")) +assert_eq("sc_common:compare_numbers(>)", false, common:compare_numbers(1, 2, ">")) + +-- sc_broker +local sc_broker = require("centreon-stream-connectors-lib.sc_broker") +local broker_obj = sc_broker.new(logger) +print("✓ sc_broker: loaded and instantiated") +assert_eq("sc_broker:get_host_all_infos(nil) → false", false, broker_obj:get_host_all_infos(nil)) + +-- sc_params +local sc_params = require("centreon-stream-connectors-lib.sc_params") +local params = sc_params.new(common, logger) +print("✓ sc_params: loaded and instantiated") +assert_eq("sc_params:is_mandatory_config_set(set) → true", true, params:is_mandatory_config_set({"key"}, {key = "value"})) +assert_eq("sc_params:is_mandatory_config_set(unset) → false", false, params:is_mandatory_config_set({"key"}, {})) +params:build_accepted_elements_info() + +-- sc_macros +local sc_macros = require("centreon-stream-connectors-lib.sc_macros") +local macros = sc_macros.new(params.params, logger, common) +print("✓ sc_macros: loaded and instantiated") +assert_eq("sc_macros:transform_short(multiline) → first line", "line1", macros:transform_short("line1\nline2")) +assert_eq("sc_macros:transform_type(0) → SOFT", "SOFT", macros:transform_type(0)) +assert_eq("sc_macros:transform_type(1) → HARD", "HARD", macros:transform_type(1)) +assert_eq("sc_macros:transform_number(\"42\") → 42", 42, macros:transform_number("42")) +assert_eq("sc_macros:transform_string(3.14) → \"3.14\"", "3.14", macros:transform_string(3.14)) + +-- sc_flush +local sc_flush = require("centreon-stream-connectors-lib.sc_flush") +local flush = sc_flush.new(params.params, logger) +print("✓ sc_flush: loaded and instantiated") +assert_eq("sc_flush:get_queues_size() → 0", 0, flush:get_queues_size()) + +-- sc_storage +local sc_storage = require("centreon-stream-connectors-lib.sc_storage") +local storage = sc_storage.new(common, logger, params.params) +print("✓ sc_storage: loaded and instantiated") +assert_eq("sc_storage:is_valid_storage_object(host_1) → true", true, storage:is_valid_storage_object("host_1")) +assert_eq("sc_storage:is_valid_storage_object(invalid) → false", false, storage:is_valid_storage_object("invalid")) + +-- sc_event +local sc_event = require("centreon-stream-connectors-lib.sc_event") +local event = sc_event.new({}, params.params, common, logger, broker_obj, storage) +print("✓ sc_event: loaded and instantiated") +assert_eq("sc_event:find_in_mapping(match) → true", true, event:find_in_mapping({neb = 1}, "neb", 1)) +assert_eq("sc_event:find_in_mapping(no match) → false", false, event:find_in_mapping({neb = 1}, "storage", 1)) + +-- sc_test +local sc_test = require("centreon-stream-connectors-lib.sc_test") +print("✓ sc_test: loaded") +assert_eq("sc_test:compare_result(match) contains OK", true, string.find(sc_test.compare_result("x", "x"), "OK") ~= nil) +assert_eq("sc_test:compare_result(no match) contains NOK", true, string.find(sc_test.compare_result("x", "y"), "NOK") ~= nil) + +if not ok then + os.exit(1) +end +print("\nAll tests passed!") diff --git a/tests/packaging/mocks.lua b/tests/packaging/mocks.lua new file mode 100644 index 00000000..44093de0 --- /dev/null +++ b/tests/packaging/mocks.lua @@ -0,0 +1,14 @@ +-- Mock the broker globals injected at runtime by Centreon Broker +broker_log = { + set_parameters = function() end, + error = function() end, + warning = function() end, + info = function() end, +} +broker = { + bbdo_version = function() return "3.0.0" end, + json_encode = function() return "{}" end, + json_decode = function() return {} end, +} +-- flexible mock: any method call returns nil without crashing +broker_cache = setmetatable({}, {__index = function() return function() return nil end end}) diff --git a/tests/packaging/stream-connectors/test_stream_connector.lua b/tests/packaging/stream-connectors/test_stream_connector.lua new file mode 100644 index 00000000..1217bd66 --- /dev/null +++ b/tests/packaging/stream-connectors/test_stream_connector.lua @@ -0,0 +1,49 @@ +dofile("tests/packaging/mocks.lua") + +local install_dir = "/usr/share/centreon-broker/lua" +local ok = true + +local handle = io.popen("find " .. install_dir .. " -maxdepth 1 -name '*.lua' -type f 2>/dev/null") +if not handle then + print("Cannot list files in " .. install_dir) + os.exit(1) +end + +local files = {} +for filepath in handle:lines() do + files[#files + 1] = filepath +end +handle:close() + +if #files == 0 then + print("No Lua files found in " .. install_dir) + os.exit(1) +end + +for _, filepath in ipairs(files) do + local script = filepath:match("([^/]+)$") + local loaded, load_err = pcall(dofile, filepath) + if not loaded then + print("✗ " .. script .. ": load error: " .. tostring(load_err)) + ok = false + else + local inited, init_err = pcall(init, {logfile = "/tmp/test-packaging.log"}) + if not inited then + print("✗ " .. script .. ": init() error: " .. tostring(init_err)) + ok = false + else + local wrote, write_err = pcall(write, {}) + if not wrote then + print("✗ " .. script .. ": write() error: " .. tostring(write_err)) + ok = false + else + print("✓ " .. script) + end + end + end +end + +if not ok then + os.exit(1) +end +print("\nAll tests passed!")