From 59f500f5c8bad982c1d56d23cbd5dbe91012c875 Mon Sep 17 00:00:00 2001 From: Sanne Raymaekers Date: Thu, 14 Aug 2025 13:17:31 +0200 Subject: [PATCH 1/3] plans: add gating tests This tmt[0] test runs the playwright tests as gating tests. Having the gating tests upstream avoids duplication across fedora and centos dist-git repositories, and running them upstream should keep them in working order. [0]: https://tmt.readthedocs.io/en/stable/index.html --- .fmf/version | 1 + packit.yaml | 14 +++++++++++++- plans/all.fmf | 14 ++++++++++++++ schutzbot/playwright.fmf | 8 ++++++++ schutzbot/playwright_tests.sh | 35 +++++++++++++++++++---------------- 5 files changed, 55 insertions(+), 17 deletions(-) create mode 100644 .fmf/version create mode 100644 plans/all.fmf create mode 100644 schutzbot/playwright.fmf diff --git a/.fmf/version b/.fmf/version new file mode 100644 index 00000000..d00491fd --- /dev/null +++ b/.fmf/version @@ -0,0 +1 @@ +1 diff --git a/packit.yaml b/packit.yaml index bd019940..a8f65e02 100644 --- a/packit.yaml +++ b/packit.yaml @@ -16,6 +16,19 @@ srpm_build_deps: - npm jobs: + - job: tests + identifier: self + trigger: pull_request + tmt_plan: /plans/all/main + targets: + - centos-stream-9 + - centos-stream-9-aarch64 + - centos-stream-10 + - centos-stream-10-aarch64 + - fedora-41 + - fedora-42 + - fedora-latest-stable-aarch64 + - job: copr_build trigger: pull_request targets: &build_targets @@ -24,7 +37,6 @@ jobs: - centos-stream-10 - centos-stream-10-aarch64 - fedora-all - - fedora-all-aarch64 - job: copr_build trigger: commit diff --git a/plans/all.fmf b/plans/all.fmf new file mode 100644 index 00000000..66deae89 --- /dev/null +++ b/plans/all.fmf @@ -0,0 +1,14 @@ +summary: cockpit-image-builder playwright tests +prepare: + how: install + package: + - cockpit-image-builder +discover: + how: fmf +execute: + how: tmt + +/main: + summary: playwright tests + discover+: + test: /schutzbot/playwright diff --git a/schutzbot/playwright.fmf b/schutzbot/playwright.fmf new file mode 100644 index 00000000..bbc5721a --- /dev/null +++ b/schutzbot/playwright.fmf @@ -0,0 +1,8 @@ +summary: run playwright tests +test: ./playwright_tests.sh +require: + - cockpit-image-builder + - podman + - nodejs + - nodejs-npm +duration: 30m diff --git a/schutzbot/playwright_tests.sh b/schutzbot/playwright_tests.sh index d6a5a87f..2ad039e4 100755 --- a/schutzbot/playwright_tests.sh +++ b/schutzbot/playwright_tests.sh @@ -1,16 +1,16 @@ #!/bin/bash set -euo pipefail -# As playwright isn't supported on fedora/el, install dependencies -# beforehand. -sudo dnf install -y \ - alsa-lib \ - libXrandr-devel \ - libXdamage-devel \ - libXcomposite-devel \ - at-spi2-atk-devel \ - cups \ - atk +TMT_SOURCE_DIR=${TMT_SOURCE_DIR:-} +if [ -n "$TMT_SOURCE_DIR" ]; then + # Move to the directory with sources + cd "${TMT_SOURCE_DIR}/cockpit-image-builder" + npm ci +elif [ "${CI:-}" != "true" ]; then + # packit drops us into the schutzbot directory + cd ../ + npm ci +fi sudo systemctl enable --now cockpit.socket @@ -19,10 +19,13 @@ sudo usermod -aG wheel admin echo "admin ALL=(ALL:ALL) NOPASSWD: ALL" | sudo tee "/etc/sudoers.d/admin-nopasswd" function upload_artifacts { - mkdir -p /tmp/artifacts/extra-screenshots - USER="$(whoami)" - sudo chown -R "$USER:$USER" playwright-report - mv playwright-report /tmp/artifacts/ + if [ -n "${TMT_TEST_DATA:-}" ]; then + mv playwright-report "$TMT_TEST_DATA"/playwright-report + else + USER="$(whoami)" + sudo chown -R "$USER:$USER" playwright-report + mv playwright-report /tmp/artifacts/ + fi } trap upload_artifacts EXIT @@ -73,8 +76,8 @@ sudo podman run \ -e "CI=true" \ -e "PLAYWRIGHT_USER=admin" \ -e "PLAYWRIGHT_PASSWORD=foobar" \ - -e "CURRENTS_PROJECT_ID=$CURRENTS_PROJECT_ID" \ - -e "CURRENTS_RECORD_KEY=$CURRENTS_RECORD_KEY" \ + -e "CURRENTS_PROJECT_ID=${CURRENTS_PROJECT_ID:-}" \ + -e "CURRENTS_RECORD_KEY=${CURRENTS_RECORD_KEY:-}" \ --net=host \ -v "$PWD:/tests" \ -v '/etc:/etc' \ From 1c3ed838891961d028cf5b555cd8d3193114741d Mon Sep 17 00:00:00 2001 From: Sanne Raymaekers Date: Mon, 18 Aug 2025 16:30:13 +0200 Subject: [PATCH 2/3] squash --- packit.yaml | 2 -- 1 file changed, 2 deletions(-) diff --git a/packit.yaml b/packit.yaml index a8f65e02..86237d42 100644 --- a/packit.yaml +++ b/packit.yaml @@ -21,8 +21,6 @@ jobs: trigger: pull_request tmt_plan: /plans/all/main targets: - - centos-stream-9 - - centos-stream-9-aarch64 - centos-stream-10 - centos-stream-10-aarch64 - fedora-41 From 8f1ba74759d02eaeff7d6a6250b4c4e5f1b0dcdb Mon Sep 17 00:00:00 2001 From: Sanne Raymaekers Date: Tue, 19 Aug 2025 12:46:50 +0200 Subject: [PATCH 3/3] playwright: wait until distro and arch have been initialized On-prem the distro and architecture are set after the wizard has been opened. This triggers a reload of the image types and makes the tests very flaky. --- playwright/helpers/helpers.ts | 41 ++++++++++++++++++++++++++++++++ playwright/helpers/navHelpers.ts | 11 +++++++-- schutzbot/playwright_tests.sh | 1 + 3 files changed, 51 insertions(+), 2 deletions(-) diff --git a/playwright/helpers/helpers.ts b/playwright/helpers/helpers.ts index 33291ac0..d7acf64b 100644 --- a/playwright/helpers/helpers.ts +++ b/playwright/helpers/helpers.ts @@ -1,3 +1,6 @@ +import { execSync } from 'child_process'; +import { readFileSync } from 'node:fs'; + import { expect, type Page } from '@playwright/test'; export const togglePreview = async (page: Page) => { @@ -42,3 +45,41 @@ export const closePopupsIfExist = async (page: Page) => { }); } }; + +// copied over from constants +const ON_PREM_RELEASES = new Map([ + ['centos-10', 'CentOS Stream 10'], + ['fedora-41', 'Fedora Linux 41'], + ['fedora-42', 'Fedora Linux 42'], + ['rhel-10', 'Red Hat Enterprise Linux (RHEL) 10'], +]); + +/* eslint-disable @typescript-eslint/no-explicit-any */ +export const getHostDistroName = (): string => { + const osRelData = readFileSync('/etc/os-release'); + const lines = osRelData + .toString('utf-8') + .split('\n') + .filter((l) => l !== ''); + const osRel = {}; + + for (const l of lines) { + const lineData = l.split('='); + (osRel as any)[lineData[0]] = lineData[1].replace(/"/g, ''); + } + const distro = ON_PREM_RELEASES.get( + `${(osRel as any)['ID']}-${(osRel as any)['VERSION_ID']}`, + ); + + if (distro === undefined) { + /* eslint-disable no-console */ + console.error('getHostDistroName failed, os-release config:', osRel); + throw new Error('getHostDistroName failed, distro undefined'); + } + + return distro; +}; + +export const getHostArch = (): string => { + return execSync('uname -m').toString('utf-8').replace(/\s/g, ''); +}; diff --git a/playwright/helpers/navHelpers.ts b/playwright/helpers/navHelpers.ts index 40c1007c..0fa6fe1d 100644 --- a/playwright/helpers/navHelpers.ts +++ b/playwright/helpers/navHelpers.ts @@ -1,6 +1,6 @@ -import type { FrameLocator, Page } from '@playwright/test'; +import { expect, FrameLocator, Page } from '@playwright/test'; -import { isHosted } from './helpers'; +import { getHostArch, getHostDistroName, isHosted } from './helpers'; /** * Opens the wizard, fills out the "Image Output" step, and navigates to the optional steps @@ -8,6 +8,13 @@ import { isHosted } from './helpers'; */ export const navigateToOptionalSteps = async (page: Page | FrameLocator) => { await page.getByRole('button', { name: 'Create image blueprint' }).click(); + if (!isHosted()) { + // wait until the distro and architecture aligns with the host + await expect(page.getByTestId('release_select')).toHaveText( + getHostDistroName(), + ); + await expect(page.getByTestId('arch_select')).toHaveText(getHostArch()); + } await page.getByRole('checkbox', { name: 'Virtualization' }).click(); await page.getByRole('button', { name: 'Next' }).click(); }; diff --git a/schutzbot/playwright_tests.sh b/schutzbot/playwright_tests.sh index 2ad039e4..052faed2 100755 --- a/schutzbot/playwright_tests.sh +++ b/schutzbot/playwright_tests.sh @@ -81,6 +81,7 @@ sudo podman run \ --net=host \ -v "$PWD:/tests" \ -v '/etc:/etc' \ + -v '/etc/os-release:/etc/os-release' \ --privileged \ --rm \ --init \