Skip to content

Commit

Permalink
fix(MongoBinaryDownloadUrl::getRhelVersionString): refactor to better…
Browse files Browse the repository at this point in the history
… compare versions

this also fixes the comparison for non-8 aarch64 versions (like 9)

fixes #726
  • Loading branch information
hasezoey committed Jan 6, 2023
1 parent ad71f21 commit 6a38d17
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -310,34 +310,44 @@ export class MongoBinaryDownloadUrl implements MongoBinaryDownloadUrlOpts {
getRhelVersionString(os: LinuxOS): string {
let name = 'rhel';
const { release } = os;
const releaseAsSemver = semver.coerce(release); // coerce "8" to "8.0.0" and "8.2" to "8.2.0", makes comparing easier than "parseInt" or "parseFloat"

if (release) {
if (releaseAsSemver) {
if (this.arch === 'aarch64') {
if (!/^8/.test(release)) {
// there are no versions for aarch64 before rhel 8.2 (or currently after)
if (semver.lt(releaseAsSemver, '8.2.0')) {
throw new KnownVersionIncompatibilityError(
`Rhel ${release}`,
this.version,
'>=4.4.2',
'ARM64(aarch64) support for rhel is only for rhel82 or higher'
);
}
if (semver.satisfies(this.version, '<4.4.2')) {
// there are no versions for aarch64 before mongodb 4.4.2
// Note: version 4.4.2 and 4.4.3 are NOT listed at the list, but are existing; list: https://www.mongodb.com/download-center/community/releases/archive
if (semver.lt(this.version, '4.4.2')) {
throw new KnownVersionIncompatibilityError(`Rhel ${release}`, this.version, '>=4.4.2');
}

// rhel aarch64 support is only for rhel 8 and only for 82
if (!semver.eq(releaseAsSemver, '8.2.0')) {
log(`a different rhel version than 8.2 is used: "${release}", using 82 release`);
}

// rhel aarch64 support is only for rhel 8.2 (and no version after explicitly)
name += '82';
} else if (/^8/.test(release)) {
} else if (semver.satisfies(releaseAsSemver, '^8.0.0')) {
name += '80';
} else if (/^7/.test(release)) {
} else if (semver.satisfies(releaseAsSemver, '^7.0.0')) {
name += '70';
} else if (/^6/.test(release)) {
} else if (semver.satisfies(releaseAsSemver, '^6.0.0')) {
name += '62';
} else if (/^5/.test(release)) {
} else if (semver.satisfies(releaseAsSemver, '^5.0.0')) {
name += '55';
} else {
console.warn(`Unhandled RHEL version: "${release}"("${this.arch}")`);
}
} else {
console.warn(`Couldnt coerce RHEL version "${release}"`);
}
// fallback if name has not been modified yet
if (name === 'rhel') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -855,7 +855,7 @@ describe('MongoBinaryDownloadUrl', () => {
);
});

it('rhel 8 & 4.4.2 arm64', async () => {
it('rhel 8.2 & 4.4.2 arm64', async () => {
const du = new MongoBinaryDownloadUrl({
platform: 'linux',
arch: 'arm64',
Expand All @@ -871,7 +871,7 @@ describe('MongoBinaryDownloadUrl', () => {
);
});

it('rhel 8 & 5.0.0 arm64', async () => {
it('rhel 8.2 & 5.0.0 arm64', async () => {
const du = new MongoBinaryDownloadUrl({
platform: 'linux',
arch: 'arm64',
Expand All @@ -887,6 +887,22 @@ describe('MongoBinaryDownloadUrl', () => {
);
});

it('rhel 9 & 5.0.0 arm64', async () => {
const du = new MongoBinaryDownloadUrl({
platform: 'linux',
arch: 'arm64',
version: '5.0.0',
os: {
os: 'linux',
dist: 'rhel',
release: '9',
},
});
expect(await du.getDownloadUrl()).toBe(
'https://fastdl.mongodb.org/linux/mongodb-linux-aarch64-rhel82-5.0.0.tgz'
);
});

it('should Error when ARM64 and rhel below 8 [KnownVersionIncompatibilityError]', async () => {
const du = new MongoBinaryDownloadUrl({
platform: 'linux',
Expand Down Expand Up @@ -951,6 +967,27 @@ describe('MongoBinaryDownloadUrl', () => {
expect(consoleWarnSpy).toHaveBeenCalledTimes(1);
expect(consoleWarnSpy).toHaveBeenCalledWith('Unhandled RHEL version: "0"("x86_64")');
});

it('should warn when a RHEL release could not be coerced', async () => {
const consoleWarnSpy = jest.spyOn(console, 'warn').mockImplementationOnce(() => void 0);

const du = new MongoBinaryDownloadUrl({
platform: 'linux',
arch: 'x86_64',
version: '5.0.0',
os: {
os: 'linux',
dist: 'rhel',
release: 'a',
},
});
expect(await du.getDownloadUrl()).toBe(
'https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel70-5.0.0.tgz'
);

expect(consoleWarnSpy).toHaveBeenCalledTimes(1);
expect(consoleWarnSpy).toHaveBeenCalledWith('Couldnt coerce RHEL version "a"');
});
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ exports[`MongoBinaryDownloadUrl getDownloadUrl() for linux for rhel should Error
ARM64(aarch64) support for rhel is only for rhel82 or higher"
`;

exports[`MongoBinaryDownloadUrl getDownloadUrl() for linux for rhel should Error when ARM64 and version below 4.4.2 is requested [KnownVersionIncompatibilityError] 1`] = `"Requested Version \\"4.4.0\\" is not available for \\"Rhel 8\\"! Available Versions: \\">=4.4.2\\""`;
exports[`MongoBinaryDownloadUrl getDownloadUrl() for linux for rhel should Error when ARM64 and version below 4.4.2 is requested [KnownVersionIncompatibilityError] 1`] = `
"Requested Version \\"4.4.0\\" is not available for \\"Rhel 8\\"! Available Versions: \\">=4.4.2\\"
ARM64(aarch64) support for rhel is only for rhel82 or higher"
`;

exports[`MongoBinaryDownloadUrl getDownloadUrl() should throw an error if platform is unknown (getArchiveName) 1`] = `"Unknown Platform: \\"unknown\\""`;

Expand Down

0 comments on commit 6a38d17

Please sign in to comment.