Skip to content

Commit 92d0be5

Browse files
committed
wip: expand export test and verify exported content
1 parent 192dc64 commit 92d0be5

File tree

4 files changed

+116
-34
lines changed

4 files changed

+116
-34
lines changed

playwright/Customizations/Kernel.spec.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,19 @@ test('Create a blueprint with Kernel customization', async ({
107107

108108
// This is for hosted service only as these features are not available in cockpit plugin
109109
await test.step('Export BP', async (step) => {
110-
step.skip(!isHosted(), 'Exporting is not available in the plugin');
111-
await exportBlueprint(page, blueprintName);
110+
// step.skip(!isHosted(), 'Exporting is not available in the plugin');
111+
await exportBlueprint(page, `name = "${blueprintName}"
112+
113+
[customizations]
114+
[customizations.kernel]
115+
name = "kernel"
116+
append = "rootwait console=tty0 console=ttyS0,115200n8 new=argument"
117+
118+
[customizations.timezone]
119+
timezone = "Etc/UTC"
120+
121+
[customizations.locale]
122+
languages = [ "C.UTF-8" ]`);
112123
});
113124

114125
await test.step('Import BP', async (step) => {

playwright/Customizations/OpenSCAP.spec.ts

Lines changed: 61 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { expect } from '@playwright/test';
22
import { v4 as uuidv4 } from 'uuid';
33

44
import { test } from '../fixtures/cleanup';
5-
import { isHosted } from '../helpers/helpers';
5+
import { isHosted, getHostDistro } from '../helpers/helpers';
66
import { ensureAuthenticated } from '../helpers/login';
77
import { ibFrame, navigateToLandingPage } from '../helpers/navHelpers';
88
import {
@@ -171,9 +171,67 @@ test('Create a blueprint with OpenSCAP customization', async ({
171171
.click();
172172
});
173173

174-
// This is for hosted service only as these features are not available in cockpit plugin
175174
await test.step('Export BP', async () => {
176-
await exportBlueprint(page, blueprintName);
175+
await exportBlueprint(frame, blueprintName, JSON.stringify(
176+
{
177+
"name": blueprintName,
178+
"description": "",
179+
"distribution": isHosted() ? "rhel-9" : getHostDistro(),
180+
"image_requests": [
181+
{
182+
"architecture": "x86_64",
183+
"image_type": "guest-image",
184+
"upload_request": {
185+
"type": "aws.s3",
186+
"options": {}
187+
}
188+
}
189+
],
190+
"customizations": {
191+
"filesystem": [
192+
{
193+
"min_size": 1073741824,
194+
"mountpoint": "/tmp"
195+
}
196+
],
197+
"kernel": {
198+
"append": ""
199+
},
200+
"openscap": {
201+
"profile_description": "This profile defines a baseline that aligns to the \"Level 1 - Server\" configuration from the Center for Internet Security® Red Hat Enterprise Linux 9 Benchmark™, v2.0.0, released 2024-06-20. This profile includes Center for Internet Security® Red Hat Enterprise Linux 9 CIS Benchmarks™ content.",
202+
"profile_id": "xccdf_org.ssgproject.content_profile_cis_server_l1",
203+
"profile_name": "CIS Red Hat Enterprise Linux 9 Benchmark for Level 1 - Server"
204+
},
205+
"packages": [
206+
"aide",
207+
"sudo",
208+
"libpwquality",
209+
"systemd-journal-remote",
210+
"firewalld",
211+
"nftables",
212+
"libselinux",
213+
"cronie",
214+
"chrony"
215+
],
216+
"services": {
217+
"enabled": [
218+
"crond",
219+
"firewalld",
220+
"systemd-journald"
221+
],
222+
"masked": [
223+
"cups",
224+
"nfs-server",
225+
"rpcbind",
226+
"avahi-daemon",
227+
"autofs",
228+
"bluetooth",
229+
"nftables"
230+
]
231+
}
232+
}
233+
}
234+
));
177235
});
178236

179237
await test.step('Import BP', async () => {

playwright/helpers/helpers.ts

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -59,32 +59,36 @@ const ON_PREM_RELEASES = new Map([
5959
['rhel-10', 'Red Hat Enterprise Linux (RHEL) 10'],
6060
]);
6161

62+
63+
export const getHostDistro = (): string => {
64+
return "fedora-42";
65+
// const osRelData = readFileSync('/etc/os-release');
66+
// const lines = osRelData
67+
// .toString('utf-8')
68+
// .split('\n')
69+
// .filter((l) => l !== '');
70+
// const osRel = {};
71+
72+
// for (const l of lines) {
73+
// const lineData = l.split('=');
74+
// (osRel as any)[lineData[0]] = lineData[1].replace(/"/g, '');
75+
// }
76+
// return `${(osRel as any)['ID']}-${(osRel as any)['VERSION_ID'].split('.')[0]}`
77+
}
78+
6279
/* eslint-disable @typescript-eslint/no-explicit-any */
6380
export const getHostDistroName = (): string => {
64-
const osRelData = readFileSync('/etc/os-release');
65-
const lines = osRelData
66-
.toString('utf-8')
67-
.split('\n')
68-
.filter((l) => l !== '');
69-
const osRel = {};
70-
71-
for (const l of lines) {
72-
const lineData = l.split('=');
73-
(osRel as any)[lineData[0]] = lineData[1].replace(/"/g, '');
74-
}
81+
const distro = getHostDistro();
7582

7683
// strip minor version from rhel
77-
const distro = ON_PREM_RELEASES.get(
78-
`${(osRel as any)['ID']}-${(osRel as any)['VERSION_ID'].split('.')[0]}`,
79-
);
84+
const distroName = ON_PREM_RELEASES.get(distro);
8085

81-
if (distro === undefined) {
86+
if (distroName === undefined) {
8287
/* eslint-disable no-console */
83-
console.error('getHostDistroName failed, os-release config:', osRel);
88+
console.error('getHostDistroName failed, host distro:', distro);
8489
throw new Error('getHostDistroName failed, distro undefined');
8590
}
86-
87-
return distro;
91+
return distroName;
8892
};
8993

9094
export const getHostArch = (): string => {

playwright/helpers/wizardHelpers.ts

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import * as fs from 'fs';
2+
import * as fsPromises from 'fs/promises';
23
import * as path from 'path';
4+
import * as os from 'os';
35

46
import { expect, FrameLocator, type Page, test } from '@playwright/test';
57

@@ -110,19 +112,26 @@ export const deleteBlueprint = async (page: Page, blueprintName: string) => {
110112

111113
/**
112114
* Export the blueprint
113-
* This function executes only on the hosted service
114-
* @param page - the page object
115+
* @param page - the page or frame object
116+
* @param expectedContent - the expected content of the exported blueprint file
115117
*/
116-
export const exportBlueprint = async (page: Page, blueprintName: string) => {
117-
if (isHosted()) {
118-
await page.getByRole('button', { name: 'Menu toggle' }).click();
119-
const downloadPromise = page.waitForEvent('download');
120-
await page
121-
.getByRole('menuitem', { name: 'Download blueprint (.json)' })
122-
.click();
123-
const download = await downloadPromise;
124-
await download.saveAs('../../downloads/' + blueprintName + '.json');
118+
export const exportBlueprint = async (page: Page | FrameLocator, expectedContent: string) => {
119+
const frame = await ibFrame(page);
120+
const downloadPromise = page.waitForEvent('download');
121+
await frame.getByRole('button', { name: 'blueprint menu toggle' }).click();
122+
await frame.getByRole('menuitem', { name: isHosted() ? 'Download blueprint (.json)' : 'Download blueprint (.toml)' }).click();
123+
const download = await downloadPromise;
124+
if (expectedContent === "") {
125+
return
125126
}
127+
128+
const tempDir = await fsPromises.mkdtemp(path.join(os.tmpdir(), 'export-bp-'));
129+
const filepath = path.join(tempDir, download.suggestedFilename());
130+
await download.saveAs(filepath);
131+
const content = fs.readFileSync(filepath);
132+
fsPromises.rm(tempDir, { recursive: true });
133+
console.log(content.toString())
134+
expect(content.toString()).toEqual(expectedContent);
126135
};
127136

128137
/**

0 commit comments

Comments
 (0)