Skip to content

Commit 57052a8

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 1afe2ce commit 57052a8

File tree

3 files changed

+32
-18
lines changed

3 files changed

+32
-18
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
@@ -60,14 +60,15 @@ func ssh(_ *cobra.Command, args []string) error {
6060
// it implies podman cannot read its machine files, which is bad
6161
mc, vmProvider, err = shim.VMExists(args[0])
6262
if err != nil {
63-
return err
64-
}
65-
if errors.Is(err, &define.ErrVMDoesNotExist{}) {
66-
vmName = args[0]
67-
} else {
63+
var vmNotExistsErr *define.ErrVMDoesNotExist
64+
if !errors.As(err, &vmNotExistsErr) {
65+
return err
66+
}
6867
sshOpts.Args = append(sshOpts.Args, args[0])
68+
} else {
69+
vmName = args[0]
70+
exists = true
6971
}
70-
exists = true
7172
}
7273

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

pkg/machine/e2e/ssh_test.go

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

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

46+
// pass 1
4247
ssh := &sshMachine{}
43-
sshSession, err := mb.setName(name).setCmd(ssh.withSSHCommand([]string{"cat", "/etc/os-release"})).run()
44-
Expect(err).ToNot(HaveOccurred())
45-
Expect(sshSession).To(Exit(0))
48+
// pass 2
49+
bm := basicMachine{}
50+
var mcs []machineCommand
51+
// check with the machine name
52+
mcs = append(mcs, ssh.withSSHCommand([]string{"cat", "/etc/os-release"}))
53+
// check without the machine name
54+
mcs = append(mcs, bm.withPodmanCommand([]string{"machine", "ssh", "cat", "/etc/os-release"}))
55+
for _, mc := range mcs {
56+
sshSession, err := mb.setCmd(mc).run()
57+
Expect(err).ToNot(HaveOccurred())
58+
Expect(sshSession).To(Exit(0))
4659

47-
if wsl {
48-
Expect(sshSession.outputToString()).To(ContainSubstring("Fedora Linux"))
49-
} else {
50-
Expect(sshSession.outputToString()).To(ContainSubstring("Fedora CoreOS"))
60+
if wsl {
61+
Expect(sshSession.outputToString()).To(ContainSubstring("Fedora Linux"))
62+
} else {
63+
Expect(sshSession.outputToString()).To(ContainSubstring("Fedora CoreOS"))
64+
}
5165
}
52-
5366
// keep exit code
54-
sshSession, err = mb.setName(name).setCmd(ssh.withSSHCommand([]string{"false"})).run()
67+
sshSession, err := mb.setName(name).setCmd(ssh.withSSHCommand([]string{"false"})).run()
5568
Expect(err).ToNot(HaveOccurred())
5669
Expect(sshSession).To(Exit(1))
5770
Expect(sshSession.outputToString()).To(Equal(""))

0 commit comments

Comments
 (0)