mirror of https://github.com/containers/podman.git
Merge pull request #8093 from rhatdan/wait
Fix handling and documentation of podman wait --interval
This commit is contained in:
commit
9060af9719
|
|
@ -23,7 +23,7 @@ var (
|
||||||
Short: "Block on one or more containers",
|
Short: "Block on one or more containers",
|
||||||
Long: waitDescription,
|
Long: waitDescription,
|
||||||
RunE: wait,
|
RunE: wait,
|
||||||
Example: `podman wait --interval 5000 ctrID
|
Example: `podman wait --interval 5s ctrID
|
||||||
podman wait ctrID1 ctrID2`,
|
podman wait ctrID1 ctrID2`,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -32,7 +32,7 @@ var (
|
||||||
Short: waitCommand.Short,
|
Short: waitCommand.Short,
|
||||||
Long: waitCommand.Long,
|
Long: waitCommand.Long,
|
||||||
RunE: waitCommand.RunE,
|
RunE: waitCommand.RunE,
|
||||||
Example: `podman container wait --interval 5000 ctrID
|
Example: `podman container wait --interval 5s ctrID
|
||||||
podman container wait ctrID1 ctrID2`,
|
podman container wait ctrID1 ctrID2`,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
@ -40,10 +40,11 @@ var (
|
||||||
var (
|
var (
|
||||||
waitOptions = entities.WaitOptions{}
|
waitOptions = entities.WaitOptions{}
|
||||||
waitCondition string
|
waitCondition string
|
||||||
|
waitInterval string
|
||||||
)
|
)
|
||||||
|
|
||||||
func waitFlags(flags *pflag.FlagSet) {
|
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")
|
flags.StringVar(&waitCondition, "condition", "stopped", "Condition to wait on")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -70,8 +71,11 @@ func wait(cmd *cobra.Command, args []string) error {
|
||||||
err error
|
err error
|
||||||
errs utils.OutputErrors
|
errs utils.OutputErrors
|
||||||
)
|
)
|
||||||
if waitOptions.Interval == 0 {
|
if waitOptions.Interval, err = time.ParseDuration(waitInterval); err != nil {
|
||||||
return errors.New("interval must be greater then 0")
|
var err1 error
|
||||||
|
if waitOptions.Interval, err1 = time.ParseDuration(waitInterval + "ms"); err1 != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if !waitOptions.Latest && len(args) == 0 {
|
if !waitOptions.Latest && len(args) == 0 {
|
||||||
|
|
|
||||||
|
|
@ -23,8 +23,8 @@ Condition to wait on (default "stopped")
|
||||||
|
|
||||||
Print usage statement
|
Print usage statement
|
||||||
|
|
||||||
**--interval**, **-i**=*microseconds*
|
**--interval**, **-i**=*duration*
|
||||||
Microseconds to wait before polling for completion
|
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**
|
**--latest**, **-l**
|
||||||
|
|
||||||
|
|
@ -42,6 +42,9 @@ $ podman wait mywebserver
|
||||||
$ podman wait --latest
|
$ podman wait --latest
|
||||||
0
|
0
|
||||||
|
|
||||||
|
$ podman wait --interval 2s
|
||||||
|
0
|
||||||
|
|
||||||
$ podman wait 860a4b23
|
$ podman wait 860a4b23
|
||||||
1
|
1
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -46,6 +46,7 @@ var _ = Describe("Podman wait", func() {
|
||||||
Expect(session.ExitCode()).To(Equal(0))
|
Expect(session.ExitCode()).To(Equal(0))
|
||||||
session = podmanTest.Podman([]string{"wait", cid})
|
session = podmanTest.Podman([]string{"wait", cid})
|
||||||
session.Wait()
|
session.Wait()
|
||||||
|
Expect(session.ExitCode()).To(Equal(0))
|
||||||
})
|
})
|
||||||
|
|
||||||
It("podman wait on a sleeping container", func() {
|
It("podman wait on a sleeping container", func() {
|
||||||
|
|
@ -55,22 +56,60 @@ var _ = Describe("Podman wait", func() {
|
||||||
Expect(session.ExitCode()).To(Equal(0))
|
Expect(session.ExitCode()).To(Equal(0))
|
||||||
session = podmanTest.Podman([]string{"wait", cid})
|
session = podmanTest.Podman([]string{"wait", cid})
|
||||||
session.Wait(20)
|
session.Wait(20)
|
||||||
|
Expect(session.ExitCode()).To(Equal(0))
|
||||||
})
|
})
|
||||||
|
|
||||||
It("podman wait on latest container", func() {
|
It("podman wait on latest container", func() {
|
||||||
session := podmanTest.Podman([]string{"run", "-d", ALPINE, "sleep", "1"})
|
session := podmanTest.Podman([]string{"run", "-d", ALPINE, "sleep", "1"})
|
||||||
session.Wait(20)
|
session.Wait(20)
|
||||||
Expect(session.ExitCode()).To(Equal(0))
|
Expect(session.ExitCode()).To(Equal(0))
|
||||||
|
if IsRemote() {
|
||||||
|
session = podmanTest.Podman([]string{"wait", session.OutputToString()})
|
||||||
|
} else {
|
||||||
session = podmanTest.Podman([]string{"wait", "-l"})
|
session = podmanTest.Podman([]string{"wait", "-l"})
|
||||||
session.Wait(20)
|
}
|
||||||
|
session.WaitWithDefaultTimeout()
|
||||||
|
Expect(session.ExitCode()).To(Equal(0))
|
||||||
})
|
})
|
||||||
|
|
||||||
It("podman container wait on latest container", func() {
|
It("podman container wait on latest container", func() {
|
||||||
session := podmanTest.Podman([]string{"container", "run", "-d", ALPINE, "sleep", "1"})
|
session := podmanTest.Podman([]string{"container", "run", "-d", ALPINE, "sleep", "1"})
|
||||||
session.Wait(20)
|
session.Wait(20)
|
||||||
Expect(session.ExitCode()).To(Equal(0))
|
Expect(session.ExitCode()).To(Equal(0))
|
||||||
|
if IsRemote() {
|
||||||
|
session = podmanTest.Podman([]string{"container", "wait", session.OutputToString()})
|
||||||
|
} else {
|
||||||
session = podmanTest.Podman([]string{"container", "wait", "-l"})
|
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)
|
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() {
|
It("podman wait on three containers", func() {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue