Deprecated of docker ps since and before options for v1.12
Deprecated note https://github.com/docker/docker/blob/master/docs/deprecated.md#docker-ps-before-and-since-options Signed-off-by: Wen Cheng Ma <wenchma@cn.ibm.com>
This commit is contained in:
parent
7fd53f7c71
commit
91b7157064
4 changed files with 2 additions and 120 deletions
|
@ -26,8 +26,6 @@ func (cli *DockerCli) CmdPs(args ...string) error {
|
|||
all = cmd.Bool([]string{"a", "-all"}, false, "Show all containers (default shows just running)")
|
||||
noTrunc = cmd.Bool([]string{"-no-trunc"}, false, "Don't truncate output")
|
||||
nLatest = cmd.Bool([]string{"l", "-latest"}, false, "Show the latest created container (includes all states)")
|
||||
since = cmd.String([]string{"#-since"}, "", "Show containers created since Id or Name (includes all states)")
|
||||
before = cmd.String([]string{"#-before"}, "", "Only show containers created before Id or Name")
|
||||
last = cmd.Int([]string{"n"}, -1, "Show n last created containers (includes all states)")
|
||||
format = cmd.String([]string{"-format"}, "", "Pretty-print containers using a Go template")
|
||||
flFilter = opts.NewListOpts(nil)
|
||||
|
@ -52,8 +50,6 @@ func (cli *DockerCli) CmdPs(args ...string) error {
|
|||
options := types.ContainerListOptions{
|
||||
All: *all,
|
||||
Limit: *last,
|
||||
Since: *since,
|
||||
Before: *before,
|
||||
Size: *size,
|
||||
Filter: psFilterArgs,
|
||||
}
|
||||
|
|
|
@ -174,8 +174,6 @@ func (daemon *Daemon) foldFilter(config *types.ContainerListOptions) (*listConte
|
|||
}
|
||||
|
||||
var beforeContFilter, sinceContFilter *container.Container
|
||||
// FIXME remove this for 1.12 as --since and --before are deprecated
|
||||
var beforeContainer, sinceContainer *container.Container
|
||||
|
||||
err = psFilters.WalkValues("before", func(value string) error {
|
||||
beforeContFilter, err = daemon.GetContainer(value)
|
||||
|
@ -213,29 +211,11 @@ func (daemon *Daemon) foldFilter(config *types.ContainerListOptions) (*listConte
|
|||
})
|
||||
}
|
||||
|
||||
// FIXME remove this for 1.12 as --since and --before are deprecated
|
||||
if config.Before != "" {
|
||||
beforeContainer, err = daemon.GetContainer(config.Before)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
// FIXME remove this for 1.12 as --since and --before are deprecated
|
||||
if config.Since != "" {
|
||||
sinceContainer, err = daemon.GetContainer(config.Since)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
return &listContext{
|
||||
filters: psFilters,
|
||||
ancestorFilter: ancestorFilter,
|
||||
images: imagesFilter,
|
||||
exitAllowed: filtExited,
|
||||
beforeContainer: beforeContainer,
|
||||
sinceContainer: sinceContainer,
|
||||
beforeFilter: beforeContFilter,
|
||||
sinceFilter: sinceContFilter,
|
||||
ContainerListOptions: config,
|
||||
|
@ -263,8 +243,7 @@ func includeContainerInList(container *container.Container, ctx *listContext) it
|
|||
}
|
||||
|
||||
// Do not include container if it's stopped and we're not filters
|
||||
// FIXME remove the ctx.beforContainer and ctx.sinceContainer part of the condition for 1.12 as --since and --before are deprecated
|
||||
if !container.Running && !ctx.All && ctx.Limit <= 0 && ctx.beforeContainer == nil && ctx.sinceContainer == nil {
|
||||
if !container.Running && !ctx.All && ctx.Limit <= 0 {
|
||||
return excludeContainer
|
||||
}
|
||||
|
||||
|
@ -288,21 +267,6 @@ func includeContainerInList(container *container.Container, ctx *listContext) it
|
|||
return excludeContainer
|
||||
}
|
||||
|
||||
// FIXME remove this for 1.12 as --since and --before are deprecated
|
||||
if ctx.beforeContainer != nil {
|
||||
if container.ID == ctx.beforeContainer.ID {
|
||||
ctx.beforeContainer = nil
|
||||
}
|
||||
return excludeContainer
|
||||
}
|
||||
|
||||
// FIXME remove this for 1.12 as --since and --before are deprecated
|
||||
if ctx.sinceContainer != nil {
|
||||
if container.ID == ctx.sinceContainer.ID {
|
||||
return stopIteration
|
||||
}
|
||||
}
|
||||
|
||||
// Stop iteration when the index is over the limit
|
||||
if ctx.Limit > 0 && ctx.idx == ctx.Limit {
|
||||
return stopIteration
|
||||
|
|
|
@ -48,7 +48,7 @@ defining it at container creation (`POST /containers/create`).
|
|||
|
||||
**Deprecated In Release: [v1.10.0](https://github.com/docker/docker/releases/tag/v1.10.0)**
|
||||
|
||||
**Target For Removal In Release: v1.12**
|
||||
**Removed In Release: v1.12**
|
||||
|
||||
The `docker ps --before` and `docker ps --since` options are deprecated.
|
||||
Use `docker ps --filter=before=...` and `docker ps --filter=since=...` instead.
|
||||
|
|
|
@ -117,86 +117,8 @@ func (s *DockerSuite) TestPsListContainersBase(c *check.C) {
|
|||
|
||||
}
|
||||
|
||||
// FIXME remove this for 1.12 as --since and --before are deprecated
|
||||
func (s *DockerSuite) TestPsListContainersDeprecatedSinceAndBefore(c *check.C) {
|
||||
out, _ := runSleepingContainer(c, "-d")
|
||||
firstID := strings.TrimSpace(out)
|
||||
|
||||
out, _ = runSleepingContainer(c, "-d")
|
||||
secondID := strings.TrimSpace(out)
|
||||
|
||||
// not long running
|
||||
out, _ = dockerCmd(c, "run", "-d", "busybox", "true")
|
||||
thirdID := strings.TrimSpace(out)
|
||||
|
||||
out, _ = runSleepingContainer(c, "-d")
|
||||
fourthID := strings.TrimSpace(out)
|
||||
|
||||
// make sure the second is running
|
||||
c.Assert(waitRun(secondID), checker.IsNil)
|
||||
|
||||
// make sure third one is not running
|
||||
dockerCmd(c, "wait", thirdID)
|
||||
|
||||
// make sure the forth is running
|
||||
c.Assert(waitRun(fourthID), checker.IsNil)
|
||||
|
||||
// since
|
||||
out, _ = dockerCmd(c, "ps", "--since="+firstID, "-a")
|
||||
expected := []string{fourthID, thirdID, secondID}
|
||||
c.Assert(assertContainerList(out, expected), checker.Equals, true, check.Commentf("SINCE & ALL: Container list is not in the correct order: %v \n%s", expected, out))
|
||||
|
||||
out, _ = dockerCmd(c, "ps", "--since="+firstID)
|
||||
c.Assert(assertContainerList(out, expected), checker.Equals, true, check.Commentf("SINCE: Container list is not in the correct order: %v \n%s", expected, out))
|
||||
|
||||
// before
|
||||
out, _ = dockerCmd(c, "ps", "--before="+thirdID, "-a")
|
||||
expected = []string{secondID, firstID}
|
||||
c.Assert(assertContainerList(out, expected), checker.Equals, true, check.Commentf("BEFORE & ALL: Container list is not in the correct order: %v \n%s", expected, out))
|
||||
|
||||
out, _ = dockerCmd(c, "ps", "--before="+thirdID)
|
||||
c.Assert(assertContainerList(out, expected), checker.Equals, true, check.Commentf("BEFORE: Container list is not in the correct order: %v \n%s", expected, out))
|
||||
|
||||
// since & before
|
||||
out, _ = dockerCmd(c, "ps", "--since="+firstID, "--before="+fourthID, "-a")
|
||||
expected = []string{thirdID, secondID}
|
||||
c.Assert(assertContainerList(out, expected), checker.Equals, true, check.Commentf("SINCE, BEFORE & ALL: Container list is not in the correct order: %v \n%s", expected, out))
|
||||
|
||||
out, _ = dockerCmd(c, "ps", "--since="+firstID, "--before="+fourthID)
|
||||
c.Assert(assertContainerList(out, expected), checker.Equals, true, check.Commentf("SINCE, BEFORE: Container list is not in the correct order: %v \n%s", expected, out))
|
||||
|
||||
// since & limit
|
||||
out, _ = dockerCmd(c, "ps", "--since="+firstID, "-n=2", "-a")
|
||||
expected = []string{fourthID, thirdID}
|
||||
c.Assert(assertContainerList(out, expected), checker.Equals, true, check.Commentf("SINCE, LIMIT & ALL: Container list is not in the correct order: %v \n%s", expected, out))
|
||||
|
||||
out, _ = dockerCmd(c, "ps", "--since="+firstID, "-n=2")
|
||||
c.Assert(assertContainerList(out, expected), checker.Equals, true, check.Commentf("SINCE, LIMIT: Container list is not in the correct order: %v \n%s", expected, out))
|
||||
|
||||
// before & limit
|
||||
out, _ = dockerCmd(c, "ps", "--before="+fourthID, "-n=1", "-a")
|
||||
expected = []string{thirdID}
|
||||
c.Assert(assertContainerList(out, expected), checker.Equals, true, check.Commentf("BEFORE, LIMIT & ALL: Container list is not in the correct order: %v \n%s", expected, out))
|
||||
|
||||
out, _ = dockerCmd(c, "ps", "--before="+fourthID, "-n=1")
|
||||
c.Assert(assertContainerList(out, expected), checker.Equals, true, check.Commentf("BEFORE, LIMIT: Container list is not in the correct order: %v \n%s", expected, out))
|
||||
|
||||
// since & before & limit
|
||||
out, _ = dockerCmd(c, "ps", "--since="+firstID, "--before="+fourthID, "-n=1", "-a")
|
||||
expected = []string{thirdID}
|
||||
c.Assert(assertContainerList(out, expected), checker.Equals, true, check.Commentf("SINCE, BEFORE, LIMIT & ALL: Container list is not in the correct order: %v \n%s", expected, out))
|
||||
|
||||
}
|
||||
|
||||
func assertContainerList(out string, expected []string) bool {
|
||||
lines := strings.Split(strings.Trim(out, "\n "), "\n")
|
||||
// FIXME remove this for 1.12 as --since and --before are deprecated
|
||||
// This is here to remove potential Warning: lines (printed out with deprecated flags)
|
||||
for i := 0; i < 2; i++ {
|
||||
if strings.Contains(lines[0], "Warning:") {
|
||||
lines = lines[1:]
|
||||
}
|
||||
}
|
||||
|
||||
if len(lines)-1 != len(expected) {
|
||||
return false
|
||||
|
|
Loading…
Reference in a new issue