mirror of
https://github.com/containers/podman.git
synced 2025-11-29 01:28:22 +08:00
Merge pull request #27503 from baude/issue27491
Fix regression in podman machine ssh
This commit is contained in:
@@ -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 + "*"
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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(""))
|
||||
|
||||
Reference in New Issue
Block a user