From 287c15d429c1dd104c3451012ccce9e37d50da45 Mon Sep 17 00:00:00 2001 From: Charlie Drage Date: Wed, 6 Mar 2024 03:55:22 -0500 Subject: [PATCH] chore: fix linux setup loop (#6262) chore: fix linux setup loop When using podman machine on Linux, it is OPTIONAL as Podman by default is installed natively. We were incorrectly showing the notification in an endless loop thinking that Podman was setup (podman machine was missing). This PR, in updateMachines function: * Does not notify if podman machine errors out when retrieving the json (rare, but it happens) * If zero podman machines are found, do not show the update * Do not update the provider status to "installed" (would override the "ready" status before), since Linux supports podman natively. --- extensions/podman/src/extension.spec.ts | 26 ++++++++++++++ extensions/podman/src/extension.ts | 45 +++++++++++++++---------- 2 files changed, 54 insertions(+), 17 deletions(-) diff --git a/extensions/podman/src/extension.spec.ts b/extensions/podman/src/extension.spec.ts index 8ca6997f4d8..407d0ec1c96 100644 --- a/extensions/podman/src/extension.spec.ts +++ b/extensions/podman/src/extension.spec.ts @@ -1088,3 +1088,29 @@ test('checkDisguisedPodmanSocket: runs updateWarnings when called not on Linux', await checkDisguisedPodmanSocket(provider); expect(updateWarningsMock).toBeCalled(); }); + +test('Even with getJSONMachineList erroring, do not show setup notification on Linux', async () => { + vi.mocked(isLinux).mockReturnValue(true); + vi.spyOn(extensionApi.process, 'exec').mockRejectedValue({ + name: 'name', + message: 'description', + stderr: 'error', + }); + await expect(extension.updateMachines(provider)).rejects.toThrow('description'); + expect(extensionApi.window.showNotification).not.toBeCalled(); +}); + +test('If machine list is empty, do not show setup notification on Linux', async () => { + vi.mocked(isLinux).mockReturnValue(true); + const spyExecPromise = vi.spyOn(extensionApi.process, 'exec'); + spyExecPromise.mockResolvedValue({ stdout: '[]' } as extensionApi.RunResult); + await extension.updateMachines(provider); + expect(extensionApi.window.showNotification).not.toBeCalled(); +}); + +test('if there are no machines, make sure checkDefaultMachine is not being ran inside updateMachines', async () => { + const spyCheckDefaultMachine = vi.spyOn(extension, 'checkDefaultMachine'); + vi.spyOn(extensionApi.process, 'exec').mockResolvedValue({ stdout: '[]' } as extensionApi.RunResult); + await extension.updateMachines(provider); + expect(spyCheckDefaultMachine).not.toBeCalled(); +}); diff --git a/extensions/podman/src/extension.ts b/extensions/podman/src/extension.ts index 083ec46fa8e..422178de3ff 100644 --- a/extensions/podman/src/extension.ts +++ b/extensions/podman/src/extension.ts @@ -125,7 +125,9 @@ export async function updateMachines(provider: extensionApi.Provider): Promise 0, 'onboarding'); - if (shouldNotifySetup && machines.length === 0) { + + // Only show the notification on macOS and Windows + // as Podman is already installed on Linux and machine is OPTIONAL. + if (shouldNotifySetup && machines.length === 0 && !isLinux()) { // push setup notification notificationDisposable = extensionApi.window.showNotification(setupPodmanNotification); shouldNotifySetup = false; @@ -260,29 +265,35 @@ export async function updateMachines(provider: extensionApi.Provider): Promise machine.Running); - const atLeastOneMachineStarting = machines.some(machine => machine.Starting); - // if a machine is running it's started else it is ready - if (atLeastOneMachineRunning) { - provider.updateStatus('ready'); - } else if (atLeastOneMachineStarting) { - // update to starting - provider.updateStatus('starting'); } else { - // needs to start a machine - provider.updateStatus('configured'); + const atLeastOneMachineRunning = machines.some(machine => machine.Running); + const atLeastOneMachineStarting = machines.some(machine => machine.Starting); + // if a machine is running it's started else it is ready + if (atLeastOneMachineRunning) { + provider.updateStatus('ready'); + } else if (atLeastOneMachineStarting) { + // update to starting + provider.updateStatus('starting'); + } else { + // needs to start a machine + provider.updateStatus('configured'); + } } } // Finally, we check to see if the machine that is running is set by default or not on the CLI // this will create a dialog that will ask the user if they wish to set the running machine as default. - await checkDefaultMachine(machines); + // this should only run if we have multiple machines + if (machines.length > 1) { + await checkDefaultMachine(machines); + } } export async function checkDefaultMachine(machines: MachineJSON[]): Promise {