From f2971b8b8396d2ceb3ee7970c60557a911a502a7 Mon Sep 17 00:00:00 2001 From: Alex Karpov Date: Thu, 4 Jul 2024 14:51:02 +0300 Subject: [PATCH] NAS-128951: If you edit VM to use Custom CPU, then try to switch back to host passthrough it gives error --- .../vm-edit-form.component.spec.ts | 37 +++++++++++++++++++ .../vm/vm-edit-form/vm-edit-form.component.ts | 4 ++ 2 files changed, 41 insertions(+) diff --git a/src/app/pages/vm/vm-edit-form/vm-edit-form.component.spec.ts b/src/app/pages/vm/vm-edit-form/vm-edit-form.component.spec.ts index c57618eefa8..980baaaf3ee 100644 --- a/src/app/pages/vm/vm-edit-form/vm-edit-form.component.spec.ts +++ b/src/app/pages/vm/vm-edit-form/vm-edit-form.component.spec.ts @@ -207,6 +207,43 @@ describe('VmEditFormComponent', () => { expect(spectator.inject(IxSlideInRef).close).toHaveBeenCalled(); }); + it('sends cpu_model as null when CPU Mode is not Custom', async () => { + await form.fillForm({ + Name: 'Edited', + Description: 'New description', + 'Memory Size': '258 mb', + 'CPU Model': 'EPYC', + 'CPU Mode': 'Host Passthrough', + 'Minimum Memory Size': '257 mb', + }); + + const saveButton = await loader.getHarness(MatButtonHarness.with({ text: 'Save' })); + await saveButton.click(); + + expect(spectator.inject(WebSocketService).call).toHaveBeenCalledWith('vm.update', [4, { + autostart: true, + bootloader: VmBootloader.Uefi, + cores: 2, + cpu_mode: VmCpuMode.HostPassthrough, + cpu_model: null, + cpuset: '0-3,8-11', + description: 'New description', + ensure_display_device: true, + hide_from_msr: false, + hyperv_enlightenments: false, + memory: 258, + min_memory: 257, + name: 'Edited', + nodeset: '0-1', + pin_vcpus: false, + shutdown_timeout: 90, + threads: 3, + time: VmTime.Local, + vcpus: 1, + }]); + expect(spectator.inject(IxSlideInRef).close).toHaveBeenCalled(); + }); + it('updates GPU devices when form is edited and saved', async () => { await form.fillForm({ GPUs: ['Intel Arc'], diff --git a/src/app/pages/vm/vm-edit-form/vm-edit-form.component.ts b/src/app/pages/vm/vm-edit-form/vm-edit-form.component.ts index 082c5991788..188b62bfda8 100644 --- a/src/app/pages/vm/vm-edit-form/vm-edit-form.component.ts +++ b/src/app/pages/vm/vm-edit-form/vm-edit-form.component.ts @@ -132,6 +132,10 @@ export class VmEditFormComponent implements OnInit { }; delete vmPayload.gpus; + if (this.form.controls.cpu_mode.value !== VmCpuMode.Custom) { + vmPayload.cpu_model = null; + } + const gpusIds = this.form.value.gpus; const pciIdsRequests$ = gpusIds.map((gpu) => {