diff --git a/cmd/podman/machine/list.go b/cmd/podman/machine/list.go index b25ff0530b..d8b77c34d2 100644 --- a/cmd/podman/machine/list.go +++ b/cmd/podman/machine/list.go @@ -190,7 +190,7 @@ func toHumanFormat(vms []*machine.ListResponse, defaultCon *config.Connection) [ isDefault := false // check port, in case we somehow have machines with the same name in different providers if defaultCon != nil { - isDefault = vm.Name == defaultCon.Name && strings.Contains(defaultCon.URI, strconv.Itoa((vm.Port))) + isDefault = vm.Name == defaultCon.Name && strings.Contains(defaultCon.URI, strconv.Itoa(vm.Port)) } if isDefault { response.Name = vm.Name + "*" diff --git a/cmd/podman/machine/ssh.go b/cmd/podman/machine/ssh.go index eed77b1339..68cfa9b001 100644 --- a/cmd/podman/machine/ssh.go +++ b/cmd/podman/machine/ssh.go @@ -60,14 +60,15 @@ func ssh(_ *cobra.Command, args []string) error { // it implies podman cannot read its machine files, which is bad mc, vmProvider, err = shim.VMExists(args[0]) if err != nil { - return err - } - if errors.Is(err, &define.ErrVMDoesNotExist{}) { - vmName = args[0] - } else { + var vmNotExistsErr *define.ErrVMDoesNotExist + if !errors.As(err, &vmNotExistsErr) { + return err + } sshOpts.Args = append(sshOpts.Args, args[0]) + } else { + vmName = args[0] + exists = true } - exists = true } // If len is greater than 1, it means we might have been diff --git a/pkg/machine/e2e/ssh_test.go b/pkg/machine/e2e/ssh_test.go index 9190dfaa03..cec00cf6fa 100644 --- a/pkg/machine/e2e/ssh_test.go +++ b/pkg/machine/e2e/ssh_test.go @@ -33,25 +33,38 @@ var _ = Describe("podman machine ssh", func() { It("ssh to running machine and check os-type", func() { wsl := testProvider.VMType() == define.WSLVirt - name := randomString() + + // setting this name instead of randomized because we want to test when the + // machine name is and is not provided. That's what the loop below is for + + name := "podman-machine-default" i := new(initMachine) - session, err := mb.setName(name).setCmd(i.withImage(mb.imagePath).withNow()).run() + session, err := mb.setName(name).setCmd(i.withImage(mb.imagePath).withNow().withUpdateConnection(ptrBool(true))).run() Expect(err).ToNot(HaveOccurred()) Expect(session).To(Exit(0)) + // pass 1 ssh := &sshMachine{} - sshSession, err := mb.setName(name).setCmd(ssh.withSSHCommand([]string{"cat", "/etc/os-release"})).run() - Expect(err).ToNot(HaveOccurred()) - Expect(sshSession).To(Exit(0)) + // pass 2 + bm := basicMachine{} + var mcs []machineCommand + // check with the machine name + mcs = append(mcs, ssh.withSSHCommand([]string{"cat", "/etc/os-release"})) + // check without the machine name + mcs = append(mcs, bm.withPodmanCommand([]string{"machine", "ssh", "cat", "/etc/os-release"})) + for _, mc := range mcs { + sshSession, err := mb.setCmd(mc).run() + Expect(err).ToNot(HaveOccurred()) + Expect(sshSession).To(Exit(0)) - if wsl { - Expect(sshSession.outputToString()).To(ContainSubstring("Fedora Linux")) - } else { - Expect(sshSession.outputToString()).To(ContainSubstring("Fedora CoreOS")) + if wsl { + Expect(sshSession.outputToString()).To(ContainSubstring("Fedora Linux")) + } else { + Expect(sshSession.outputToString()).To(ContainSubstring("Fedora CoreOS")) + } } - // keep exit code - sshSession, err = mb.setName(name).setCmd(ssh.withSSHCommand([]string{"false"})).run() + sshSession, err := mb.setName(name).setCmd(ssh.withSSHCommand([]string{"false"})).run() Expect(err).ToNot(HaveOccurred()) Expect(sshSession).To(Exit(1)) Expect(sshSession.outputToString()).To(Equal(""))