diff --git a/cmd/ignite/run/start.go b/cmd/ignite/run/start.go index 4f09ab23f..4219e83fb 100644 --- a/cmd/ignite/run/start.go +++ b/cmd/ignite/run/start.go @@ -49,6 +49,15 @@ func Start(so *StartOptions, fs *flag.FlagSet) error { return fmt.Errorf("VM %q is already running", so.vm.GetUID()) } + // Stopped VMs don't contain the runtime and network information. Set the + // default runtime and network from the providers if empty. + if so.vm.Status.Runtime.Name == "" { + so.vm.Status.Runtime.Name = providers.RuntimeName + } + if so.vm.Status.Network.Plugin == "" { + so.vm.Status.Network.Plugin = providers.NetworkPluginName + } + // In case the runtime and network-plugin are specified explicitly at // start, set the runtime and network-plugin on the VM. This overrides the // global config and config on the VM object, if any. diff --git a/e2e/vm_lifecycle_test.go b/e2e/vm_lifecycle_test.go index bdf502e5c..90a716405 100644 --- a/e2e/vm_lifecycle_test.go +++ b/e2e/vm_lifecycle_test.go @@ -171,3 +171,33 @@ func TestVMStartNonDefaultProvider(t *testing.T) { gotInspect := strings.TrimSpace(string(inspectOut)) assert.Equal(t, gotInspect, wantInspect, fmt.Sprintf("unexpected VM properties:\n\t(WNT): %q\n\t(GOT): %q", wantInspect, gotInspect)) } + +func TestVMStopStartDefaultProviders(t *testing.T) { + assert.Assert(t, e2eHome != "", "IGNITE_E2E_HOME should be set") + + vmName := "e2e-test-vm-stop-start-default-providers" + + igniteCmd := util.NewCommand(t, igniteBin) + + // Clean-up the following VM. + defer igniteCmd.New(). + With("rm", "-f", vmName). + Run() + + // Run the VM. + igniteCmd.New(). + With("run"). + With(util.DefaultVMImage). + With("--name=" + vmName). + Run() + + // Stop the VM. + igniteCmd.New(). + With("stop", vmName). + Run() + + // Start the VM. + igniteCmd.New(). + With("start", vmName). + Run() +}