Skip to content

Commit 3a5dab7

Browse files
authored
feat(smoke-tests): test rpm installer for RHEL / Rocky linux COMPASS-8713 (#6704)
* Implement Linux rpm installer * Add linux_rpm and arm CI with the RHEL build variant * Wrapping dnf commands in sudo
1 parent 89bd79c commit 3a5dab7

File tree

5 files changed

+99
-7
lines changed

5 files changed

+99
-7
lines changed

.evergreen/buildvariants-and-tasks.in.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,12 @@ const SMOKETEST_BUILD_VARIANTS = [
7373
run_on: 'windows-vsCurrent-large',
7474
depends_on: 'package-windows',
7575
},
76-
// {
77-
// name: 'smoketest-rhel',
78-
// display_name: 'Smoketest RHEL',
79-
// run_on: 'rhel80-large',
80-
// depends_on: 'package-rhel',
81-
// },
76+
{
77+
name: 'smoketest-rhel',
78+
display_name: 'Smoketest RHEL',
79+
run_on: 'rhel80-large',
80+
depends_on: 'package-rhel',
81+
},
8282
{
8383
name: 'smoketest-macos-x64',
8484
display_name: 'Smoketest MacOS Intel',

.evergreen/buildvariants-and-tasks.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,14 @@ buildvariants:
9292
variant: package-windows
9393
tasks:
9494
- name: smoketest-compass
95+
- name: smoketest-rhel-compass
96+
display_name: Smoketest RHEL (compass)
97+
run_on: rhel80-large
98+
depends_on:
99+
- name: package-compass
100+
variant: package-rhel
101+
tasks:
102+
- name: smoketest-compass
95103
- name: smoketest-macos-x64-compass
96104
display_name: Smoketest MacOS Intel (compass)
97105
run_on: macos-14-gui

.evergreen/functions.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -698,7 +698,7 @@ functions:
698698
fi
699699
700700
if [[ "$IS_RHEL" == "true" ]]; then
701-
# TODO: linux_rpm
701+
npm run --unsafe-perm --workspace @mongodb-js/compass-smoke-tests start -- --package=linux_rpm --tests=time-to-first-query
702702
npm run --unsafe-perm --workspace @mongodb-js/compass-smoke-tests start -- --package=linux_tar --tests=time-to-first-query
703703
fi
704704

packages/compass-smoke-tests/src/installers/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { installWindowsMSI } from './windows-msi';
66
import { installWindowsSetup } from './windows-setup';
77
import { installLinuxTar } from './linux-tar';
88
import { installLinuxDeb } from './linux-deb';
9+
import { installLinuxRpm } from './linux-rpm';
910

1011
export function getInstaller(kind: PackageKind) {
1112
if (kind === 'osx_dmg') {
@@ -22,6 +23,8 @@ export function getInstaller(kind: PackageKind) {
2223
return installLinuxTar;
2324
} else if (kind === 'linux_deb') {
2425
return installLinuxDeb;
26+
} else if (kind === 'linux_rpm') {
27+
return installLinuxRpm;
2528
} else {
2629
throw new Error(`Installer for '${kind}' is not yet implemented`);
2730
}
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
import assert from 'node:assert/strict';
2+
import cp from 'node:child_process';
3+
import path from 'node:path';
4+
import fs from 'node:fs';
5+
6+
import type { InstalledAppInfo, InstallablePackage } from './types';
7+
import { execute } from '../execute';
8+
/**
9+
* Call dnf to get the package name
10+
*/
11+
function getPackageName(filepath: string) {
12+
const { status, stdout, stderr } = cp.spawnSync(
13+
'rpm',
14+
['--query', '--queryformat', '%{NAME}', '--package', filepath],
15+
{ encoding: 'utf8' }
16+
);
17+
assert.equal(
18+
status,
19+
0,
20+
`Expected a clean exit, got status ${status || 'null'}: ${stderr}`
21+
);
22+
return stdout.trim();
23+
}
24+
25+
/**
26+
* Check if a package is installed (by name)
27+
*/
28+
export function isInstalled(packageName: string) {
29+
const result = cp.spawnSync(
30+
'sudo',
31+
['dnf', 'list', 'installed', packageName],
32+
{
33+
stdio: 'inherit',
34+
}
35+
);
36+
return result.status === 0;
37+
}
38+
39+
export function installLinuxRpm({
40+
appName,
41+
filepath,
42+
}: InstallablePackage): InstalledAppInfo {
43+
const packageName = getPackageName(filepath);
44+
const installPath = `/usr/lib/${packageName}`;
45+
const appPath = path.resolve(installPath, appName);
46+
47+
function uninstall() {
48+
execute('sudo', ['dnf', 'remove', '-y', packageName]);
49+
}
50+
51+
if (isInstalled(packageName)) {
52+
console.warn(
53+
'Found an existing install directory (likely from a previous run): Uninstalling first'
54+
);
55+
uninstall();
56+
}
57+
58+
console.warn(
59+
"Installing globally, since we haven't discovered a way to specify an install path"
60+
);
61+
assert(!isInstalled(packageName), 'Expected the package to not be installed');
62+
assert(
63+
!fs.existsSync(installPath),
64+
`Expected no install directory to exist: ${installPath}`
65+
);
66+
execute('sudo', ['dnf', 'install', '-y', filepath]);
67+
68+
assert(isInstalled(packageName), 'Expected the package to be installed');
69+
assert(
70+
fs.existsSync(installPath),
71+
`Expected an install directory to exist: ${installPath}`
72+
);
73+
74+
// Check that the executable will run without being quarantined or similar
75+
execute('xvfb-run', [appPath, '--version']);
76+
77+
return {
78+
appPath: installPath,
79+
uninstall,
80+
};
81+
}

0 commit comments

Comments
 (0)