Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@
"default": "RHEL 10",
"description": "Image to download"
},
"macadam.factory.machine.force-download": {
"type": "boolean",
"scope": "VmProviderConnectionFactory",
"default": false,
"description": "Force download image, do not get from cache",
"when": "!macadam.localImage"
},
"macadam.factory.machine.image-path": {
"type": "string",
"format": "file",
Expand Down
14 changes: 14 additions & 0 deletions src/extension.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,20 @@ describe('activate', () => {
expect(utils.pullImageFromRedHatRegistry).toHaveBeenCalled();
});

test('RHEL image is pulled when download is forced, not considering if image is cached', async () => {
vi.mocked(ImageCache.prototype.getPath).mockReturnValue(
resolve('/', 'path', 'to', 'storage', 'images', 'rhel10'),
);
await create({
'macadam.factory.machine.image': 'RHEL 10',
'macadam.factory.machine.force-download': true,
});
// cache is not checked
expect(fs.existsSync).not.toHaveBeenCalled();
// image is pulled
expect(utils.pullImageFromRedHatRegistry).toHaveBeenCalled();
});

test('RHEL image is not pulled when image is cached', async () => {
vi.mocked(ImageCache.prototype.getPath).mockReturnValue(
resolve('/', 'path', 'to', 'storage', 'images', 'rhel10'),
Expand Down
8 changes: 7 additions & 1 deletion src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -496,9 +496,15 @@ async function createVM(
telemetryRecords.imagePath = 'custom';
}

// force-download
const forceDownload = params['macadam.factory.machine.force-download'] ?? false;
if (typeof forceDownload !== 'boolean') {
throw new Error('force-download must be a boolean');
}

if (image) {
const cachedImagePath = imageCache.getPath(image);
if (existsSync(cachedImagePath)) {
if (!forceDownload && existsSync(cachedImagePath)) {
imagePath = cachedImagePath;
telemetryRecords.imagePath = 'cached';
logger?.log(`Using image cached in ${cachedImagePath}\n`);
Expand Down