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 \