Merge pull request #2679 from baude/issue2677

podman logs on created container should exit
This commit is contained in:
OpenShift Merge Robot
2019-03-18 09:22:07 -07:00
committed by GitHub
2 changed files with 16 additions and 1 deletions

View File

@ -3,6 +3,7 @@ package libpod
import ( import (
"fmt" "fmt"
"io/ioutil" "io/ioutil"
"os"
"strings" "strings"
"sync" "sync"
"time" "time"
@ -54,6 +55,10 @@ func (r *Runtime) Log(containers []*Container, options *LogOptions, logChannel c
func (c *Container) ReadLog(options *LogOptions, logChannel chan *LogLine) error { func (c *Container) ReadLog(options *LogOptions, logChannel chan *LogLine) error {
t, tailLog, err := getLogFile(c.LogPath(), options) t, tailLog, err := getLogFile(c.LogPath(), options)
if err != nil { if err != nil {
// If the log file does not exist, this is not fatal.
if os.IsNotExist(errors.Cause(err)) {
return nil
}
return errors.Wrapf(err, "unable to read log file %s for %s ", c.ID(), c.LogPath()) return errors.Wrapf(err, "unable to read log file %s for %s ", c.ID(), c.LogPath())
} }
options.WaitGroup.Add(1) options.WaitGroup.Add(1)
@ -111,7 +116,7 @@ func getLogFile(path string, options *LogOptions) (*tail.Tail, []*LogLine, error
Whence: whence, Whence: whence,
} }
t, err := tail.TailFile(path, tail.Config{Poll: true, Follow: options.Follow, Location: &seek, Logger: tail.DiscardingLogger}) t, err := tail.TailFile(path, tail.Config{MustExist: true, Poll: true, Follow: options.Follow, Location: &seek, Logger: tail.DiscardingLogger})
return t, logTail, err return t, logTail, err
} }

View File

@ -132,4 +132,14 @@ var _ = Describe("Podman logs", func() {
Expect(len(output)).To(Equal(6)) Expect(len(output)).To(Equal(6))
Expect(strings.Contains(output[0], cid1[:12]) || strings.Contains(output[0], cid2[:12])).To(BeTrue()) Expect(strings.Contains(output[0], cid1[:12]) || strings.Contains(output[0], cid2[:12])).To(BeTrue())
}) })
It("podman logs on a created container should result in 0 exit code", func() {
session := podmanTest.Podman([]string{"create", "-dt", "--name", "log", ALPINE})
session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(BeZero())
results := podmanTest.Podman([]string{"logs", "log"})
results.WaitWithDefaultTimeout()
Expect(results.ExitCode()).To(BeZero())
})
}) })