Skip to content

Commit e0e3895

Browse files
committed
Fix regression in podman machine ssh
While doing the provider obfuscation, I injected a regression where podman ssh machine failed. The regression was added in 0f22c1c. I have fixed the regression and added a test to prevent future occurance. Fixes: #27491 Signed-off-by: Brent Baude <bbaude@redhat.com>
1 parent f23367f commit e0e3895

File tree

3 files changed

+33
-19
lines changed

3 files changed

+33
-19
lines changed

cmd/podman/machine/list.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ func toHumanFormat(vms []*machine.ListResponse, defaultCon *config.Connection) [
190190
isDefault := false
191191
// check port, in case we somehow have machines with the same name in different providers
192192
if defaultCon != nil {
193-
isDefault = vm.Name == defaultCon.Name && strings.Contains(defaultCon.URI, strconv.Itoa((vm.Port)))
193+
isDefault = vm.Name == defaultCon.Name && strings.Contains(defaultCon.URI, strconv.Itoa(vm.Port))
194194
}
195195
if isDefault {
196196
response.Name = vm.Name + "*"

cmd/podman/machine/ssh.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,14 +64,15 @@ func ssh(_ *cobra.Command, args []string) error {
6464
// it implies podman cannot read its machine files, which is bad
6565
mc, vmProvider, err = shim.VMExists(args[0])
6666
if err != nil {
67-
return err
68-
}
69-
if errors.Is(err, &define.ErrVMDoesNotExist{}) {
70-
vmName = args[0]
71-
} else {
67+
var vmNotExistsErr *define.ErrVMDoesNotExist
68+
if !errors.As(err, &vmNotExistsErr) {
69+
return err
70+
}
7271
sshOpts.Args = append(sshOpts.Args, args[0])
72+
} else {
73+
vmName = args[0]
74+
exists = true
7375
}
74-
exists = true
7576
}
7677

7778
// If len is greater than 1, it means we might have been

pkg/machine/e2e/ssh_test.go

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -34,25 +34,38 @@ var _ = Describe("podman machine ssh", func() {
3434

3535
It("ssh to running machine and check os-type", func() {
3636
wsl := testProvider.VMType() == define.WSLVirt
37-
name := randomString()
37+
38+
// setting this name instead of randomized because we want to test when the
39+
// machine name is and is not provided. That's what the loop below is for
40+
41+
name := "podman-machine-default"
3842
i := new(initMachine)
39-
session, err := mb.setName(name).setCmd(i.withImage(mb.imagePath).withNow()).run()
43+
session, err := mb.setName(name).setCmd(i.withImage(mb.imagePath).withNow().withUpdateConnection(ptrBool(true))).run()
4044
Expect(err).ToNot(HaveOccurred())
4145
Expect(session).To(Exit(0))
4246

47+
// pass 1
4348
ssh := &sshMachine{}
44-
sshSession, err := mb.setName(name).setCmd(ssh.withSSHCommand([]string{"cat", "/etc/os-release"})).run()
45-
Expect(err).ToNot(HaveOccurred())
46-
Expect(sshSession).To(Exit(0))
47-
48-
if wsl {
49-
Expect(sshSession.outputToString()).To(ContainSubstring("Fedora Linux"))
50-
} else {
51-
Expect(sshSession.outputToString()).To(ContainSubstring("Fedora CoreOS"))
49+
// pass 2
50+
bm := basicMachine{}
51+
var mcs []machineCommand
52+
// check with the machine name
53+
mcs = append(mcs, ssh.withSSHCommand([]string{"cat", "/etc/os-release"}))
54+
// check without the machine name
55+
mcs = append(mcs, bm.withPodmanCommand([]string{"machine", "ssh", "cat", "/etc/os-release"}))
56+
for _, mc := range mcs {
57+
sshSession, err := mb.setCmd(mc).run()
58+
Expect(err).ToNot(HaveOccurred())
59+
Expect(sshSession).To(Exit(0))
60+
61+
if wsl {
62+
Expect(sshSession.outputToString()).To(ContainSubstring("Fedora Linux"))
63+
} else {
64+
Expect(sshSession.outputToString()).To(ContainSubstring("Fedora CoreOS"))
65+
}
5266
}
53-
5467
// keep exit code
55-
sshSession, err = mb.setName(name).setCmd(ssh.withSSHCommand([]string{"false"})).run()
68+
sshSession, err := mb.setName(name).setCmd(ssh.withSSHCommand([]string{"false"})).run()
5669
Expect(err).ToNot(HaveOccurred())
5770
Expect(sshSession).To(Exit(1))
5871
Expect(sshSession.outputToString()).To(Equal(""))

0 commit comments

Comments
 (0)