Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix handling and documentation of podman wait --interval #8093

Merged
merged 1 commit into from
Oct 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions cmd/podman/containers/wait.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ var (
Short: "Block on one or more containers",
Long: waitDescription,
RunE: wait,
Example: `podman wait --interval 5000 ctrID
Example: `podman wait --interval 5s ctrID
podman wait ctrID1 ctrID2`,
}

Expand All @@ -32,18 +32,19 @@ var (
Short: waitCommand.Short,
Long: waitCommand.Long,
RunE: waitCommand.RunE,
Example: `podman container wait --interval 5000 ctrID
Example: `podman container wait --interval 5s ctrID
podman container wait ctrID1 ctrID2`,
}
)

var (
waitOptions = entities.WaitOptions{}
waitCondition string
waitInterval string
)

func waitFlags(flags *pflag.FlagSet) {
flags.DurationVarP(&waitOptions.Interval, "interval", "i", time.Duration(250), "Milliseconds to wait before polling for completion")
flags.StringVarP(&waitInterval, "interval", "i", "250ns", "Time Interval to wait before polling for completion")
flags.StringVar(&waitCondition, "condition", "stopped", "Condition to wait on")
}

Expand All @@ -70,8 +71,11 @@ func wait(cmd *cobra.Command, args []string) error {
err error
errs utils.OutputErrors
)
if waitOptions.Interval == 0 {
return errors.New("interval must be greater then 0")
if waitOptions.Interval, err = time.ParseDuration(waitInterval); err != nil {
var err1 error
if waitOptions.Interval, err1 = time.ParseDuration(waitInterval + "ms"); err1 != nil {
return err
}
}

if !waitOptions.Latest && len(args) == 0 {
Expand Down
7 changes: 5 additions & 2 deletions docs/source/markdown/podman-wait.1.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ Condition to wait on (default "stopped")

Print usage statement

**--interval**, **-i**=*microseconds*
Microseconds to wait before polling for completion
**--interval**, **-i**=*duration*
Time interval to wait before polling for completion. A duration string is a sequence of decimal numbers, each with optional fraction and a unit suffix, such as "300ms", "-1.5h" or "2h45m". Valid time units are "ns", "us" (or "µs"), "ms", "s", "m", "h". Time unit defaults to "ms".

**--latest**, **-l**

Expand All @@ -42,6 +42,9 @@ $ podman wait mywebserver
$ podman wait --latest
0

$ podman wait --interval 2s
0

$ podman wait 860a4b23
1

Expand Down
45 changes: 42 additions & 3 deletions test/e2e/wait_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ var _ = Describe("Podman wait", func() {
Expect(session.ExitCode()).To(Equal(0))
session = podmanTest.Podman([]string{"wait", cid})
session.Wait()
Expect(session.ExitCode()).To(Equal(0))
})

It("podman wait on a sleeping container", func() {
Expand All @@ -55,22 +56,60 @@ var _ = Describe("Podman wait", func() {
Expect(session.ExitCode()).To(Equal(0))
session = podmanTest.Podman([]string{"wait", cid})
session.Wait(20)
Expect(session.ExitCode()).To(Equal(0))
})

It("podman wait on latest container", func() {
session := podmanTest.Podman([]string{"run", "-d", ALPINE, "sleep", "1"})
session.Wait(20)
Expect(session.ExitCode()).To(Equal(0))
session = podmanTest.Podman([]string{"wait", "-l"})
session.Wait(20)
if IsRemote() {
session = podmanTest.Podman([]string{"wait", session.OutputToString()})
} else {
session = podmanTest.Podman([]string{"wait", "-l"})
}
session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(Equal(0))
})

It("podman container wait on latest container", func() {
session := podmanTest.Podman([]string{"container", "run", "-d", ALPINE, "sleep", "1"})
session.Wait(20)
Expect(session.ExitCode()).To(Equal(0))
session = podmanTest.Podman([]string{"container", "wait", "-l"})
if IsRemote() {
session = podmanTest.Podman([]string{"container", "wait", session.OutputToString()})
} else {
session = podmanTest.Podman([]string{"container", "wait", "-l"})
}
session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(Equal(0))
})

It("podman container wait on latest container with --interval flag", func() {
session := podmanTest.Podman([]string{"container", "run", "-d", ALPINE, "sleep", "1"})
session.Wait(20)
Expect(session.ExitCode()).To(Equal(0))
session = podmanTest.Podman([]string{"container", "wait", "-i", "5000", session.OutputToString()})
session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(Equal(0))
})

It("podman container wait on latest container with --interval flag", func() {
session := podmanTest.Podman([]string{"container", "run", "-d", ALPINE, "sleep", "1"})
session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(Equal(0))
session = podmanTest.Podman([]string{"container", "wait", "--interval", "1s", session.OutputToString()})
session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(Equal(0))
})

It("podman container wait on container with bogus --interval", func() {
session := podmanTest.Podman([]string{"container", "run", "-d", ALPINE, "sleep", "1"})
session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(Equal(0))
session = podmanTest.Podman([]string{"container", "wait", "--interval", "100days", session.OutputToString()})
session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(Equal(125))
})

It("podman wait on three containers", func() {
Expand Down