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
0f22c1c772.  I have fixed the regression
and added a test to prevent future occurance.

Fixes: #27491

Signed-off-by: Brent Baude <bbaude@redhat.com>
This commit is contained in:
Brent Baude
2025-11-10 14:47:54 -06:00
parent 1afe2ce6d3
commit 57052a8cc7
3 changed files with 32 additions and 18 deletions

View File

@@ -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(""))