mirror of
https://github.com/containers/podman.git
synced 2025-06-26 21:07:02 +08:00
Make podman ps fast
Like Ricky Bobby, we want to go fast. Signed-off-by: baude <bbaude@redhat.com>
This commit is contained in:
@ -315,8 +315,14 @@ func (s *PodmanSession) OutputToString() string {
|
||||
// OutputToStringArray returns the output as a []string
|
||||
// where each array item is a line split by newline
|
||||
func (s *PodmanSession) OutputToStringArray() []string {
|
||||
var results []string
|
||||
output := fmt.Sprintf("%s", s.Out.Contents())
|
||||
return strings.Split(output, "\n")
|
||||
for _, line := range strings.Split(output, "\n") {
|
||||
if line != "" {
|
||||
results = append(results, line)
|
||||
}
|
||||
}
|
||||
return results
|
||||
}
|
||||
|
||||
// ErrorGrepString takes session stderr output and behaves like grep. it returns a bool
|
||||
|
@ -42,7 +42,7 @@ var _ = Describe("Podman logs", func() {
|
||||
results := podmanTest.Podman([]string{"logs", cid})
|
||||
results.WaitWithDefaultTimeout()
|
||||
Expect(results.ExitCode()).To(Equal(0))
|
||||
Expect(len(results.OutputToStringArray())).To(Equal(4))
|
||||
Expect(len(results.OutputToStringArray())).To(Equal(3))
|
||||
})
|
||||
|
||||
It("podman logs tail two lines", func() {
|
||||
@ -55,7 +55,7 @@ var _ = Describe("Podman logs", func() {
|
||||
results := podmanTest.Podman([]string{"logs", "--tail", "2", cid})
|
||||
results.WaitWithDefaultTimeout()
|
||||
Expect(results.ExitCode()).To(Equal(0))
|
||||
Expect(len(results.OutputToStringArray())).To(Equal(3))
|
||||
Expect(len(results.OutputToStringArray())).To(Equal(2))
|
||||
})
|
||||
|
||||
It("podman logs tail 99 lines", func() {
|
||||
@ -68,7 +68,7 @@ var _ = Describe("Podman logs", func() {
|
||||
results := podmanTest.Podman([]string{"logs", "--tail", "99", cid})
|
||||
results.WaitWithDefaultTimeout()
|
||||
Expect(results.ExitCode()).To(Equal(0))
|
||||
Expect(len(results.OutputToStringArray())).To(Equal(4))
|
||||
Expect(len(results.OutputToStringArray())).To(Equal(3))
|
||||
})
|
||||
|
||||
It("podman logs tail 2 lines with timestamps", func() {
|
||||
@ -81,7 +81,7 @@ var _ = Describe("Podman logs", func() {
|
||||
results := podmanTest.Podman([]string{"logs", "--tail", "2", "-t", cid})
|
||||
results.WaitWithDefaultTimeout()
|
||||
Expect(results.ExitCode()).To(Equal(0))
|
||||
Expect(len(results.OutputToStringArray())).To(Equal(3))
|
||||
Expect(len(results.OutputToStringArray())).To(Equal(2))
|
||||
})
|
||||
|
||||
It("podman logs latest with since time", func() {
|
||||
@ -94,7 +94,7 @@ var _ = Describe("Podman logs", func() {
|
||||
results := podmanTest.Podman([]string{"logs", "--since", "2017-08-07T10:10:09.056611202-04:00", cid})
|
||||
results.WaitWithDefaultTimeout()
|
||||
Expect(results.ExitCode()).To(Equal(0))
|
||||
Expect(len(results.OutputToStringArray())).To(Equal(4))
|
||||
Expect(len(results.OutputToStringArray())).To(Equal(3))
|
||||
})
|
||||
|
||||
It("podman logs latest with since duration", func() {
|
||||
@ -107,6 +107,6 @@ var _ = Describe("Podman logs", func() {
|
||||
results := podmanTest.Podman([]string{"logs", "--since", "10m", cid})
|
||||
results.WaitWithDefaultTimeout()
|
||||
Expect(results.ExitCode()).To(Equal(0))
|
||||
Expect(len(results.OutputToStringArray())).To(Equal(4))
|
||||
Expect(len(results.OutputToStringArray())).To(Equal(3))
|
||||
})
|
||||
})
|
||||
|
@ -77,6 +77,6 @@ var _ = Describe("Podman pod create", func() {
|
||||
|
||||
check := podmanTest.Podman([]string{"pod", "ps", "-q"})
|
||||
check.WaitWithDefaultTimeout()
|
||||
Expect(len(check.OutputToStringArray())).To(Equal(1))
|
||||
Expect(len(check.OutputToStringArray())).To(Equal(0))
|
||||
})
|
||||
})
|
||||
|
@ -155,7 +155,7 @@ var _ = Describe("Podman pod create", func() {
|
||||
check.WaitWithDefaultTimeout()
|
||||
Expect(check.ExitCode()).To(Equal(0))
|
||||
PIDs := check.OutputToStringArray()
|
||||
Expect(len(PIDs)).To(Equal(4))
|
||||
Expect(len(PIDs)).To(Equal(3))
|
||||
|
||||
ctrPID, _ := strconv.Atoi(PIDs[1])
|
||||
infraPID, _ := strconv.Atoi(PIDs[2])
|
||||
|
@ -109,7 +109,7 @@ var _ = Describe("Podman top", func() {
|
||||
result := podmanTest.Podman([]string{"pod", "top", podid})
|
||||
result.WaitWithDefaultTimeout()
|
||||
Expect(result.ExitCode()).To(Equal(0))
|
||||
Expect(len(result.OutputToStringArray())).To(Equal(4))
|
||||
Expect(len(result.OutputToStringArray())).To(Equal(3))
|
||||
})
|
||||
|
||||
It("podman pod top on pod with containers in different namespace", func() {
|
||||
@ -127,6 +127,6 @@ var _ = Describe("Podman top", func() {
|
||||
result := podmanTest.Podman([]string{"pod", "top", podid})
|
||||
result.WaitWithDefaultTimeout()
|
||||
Expect(result.ExitCode()).To(Equal(0))
|
||||
Expect(len(result.OutputToStringArray())).To(Equal(4))
|
||||
Expect(len(result.OutputToStringArray())).To(Equal(3))
|
||||
})
|
||||
})
|
||||
|
@ -50,7 +50,7 @@ ENTRYPOINT ["grep", "Alpine", "/etc/os-release"]
|
||||
session := podmanTest.Podman([]string{"run", "foobar.com/entrypoint:latest"})
|
||||
session.WaitWithDefaultTimeout()
|
||||
Expect(session.ExitCode()).To(Equal(0))
|
||||
Expect(len(session.OutputToStringArray())).To(Equal(3))
|
||||
Expect(len(session.OutputToStringArray())).To(Equal(2))
|
||||
})
|
||||
|
||||
It("podman run entrypoint with cmd", func() {
|
||||
@ -62,7 +62,7 @@ ENTRYPOINT ["grep", "Alpine", "/etc/os-release"]
|
||||
session := podmanTest.Podman([]string{"run", "foobar.com/entrypoint:latest"})
|
||||
session.WaitWithDefaultTimeout()
|
||||
Expect(session.ExitCode()).To(Equal(0))
|
||||
Expect(len(session.OutputToStringArray())).To(Equal(5))
|
||||
Expect(len(session.OutputToStringArray())).To(Equal(4))
|
||||
})
|
||||
|
||||
It("podman run entrypoint with user cmd overrides image cmd", func() {
|
||||
@ -74,7 +74,7 @@ ENTRYPOINT ["grep", "Alpine", "/etc/os-release"]
|
||||
session := podmanTest.Podman([]string{"run", "foobar.com/entrypoint:latest", "-i"})
|
||||
session.WaitWithDefaultTimeout()
|
||||
Expect(session.ExitCode()).To(Equal(0))
|
||||
Expect(len(session.OutputToStringArray())).To(Equal(6))
|
||||
Expect(len(session.OutputToStringArray())).To(Equal(5))
|
||||
})
|
||||
|
||||
It("podman run entrypoint with user cmd no image cmd", func() {
|
||||
@ -85,7 +85,7 @@ ENTRYPOINT ["grep", "Alpine", "/etc/os-release"]
|
||||
session := podmanTest.Podman([]string{"run", "foobar.com/entrypoint:latest", "-i"})
|
||||
session.WaitWithDefaultTimeout()
|
||||
Expect(session.ExitCode()).To(Equal(0))
|
||||
Expect(len(session.OutputToStringArray())).To(Equal(6))
|
||||
Expect(len(session.OutputToStringArray())).To(Equal(5))
|
||||
})
|
||||
|
||||
It("podman run user entrypoint overrides image entrypoint and image cmd", func() {
|
||||
|
@ -75,7 +75,7 @@ var _ = Describe("Podman privileged container tests", func() {
|
||||
session := podmanTest.Podman([]string{"run", "-t", "busybox", "ls", "-l", "/dev"})
|
||||
session.WaitWithDefaultTimeout()
|
||||
Expect(session.ExitCode()).To(Equal(0))
|
||||
Expect(len(session.OutputToStringArray())).To(Equal(18))
|
||||
Expect(len(session.OutputToStringArray())).To(Equal(17))
|
||||
})
|
||||
|
||||
It("podman privileged should inherit host devices", func() {
|
||||
|
@ -34,6 +34,6 @@ var _ = Describe("Podman version", func() {
|
||||
session := podmanTest.Podman([]string{"version"})
|
||||
session.WaitWithDefaultTimeout()
|
||||
Expect(session.ExitCode()).To(Equal(0))
|
||||
Expect(len(session.OutputToStringArray())).To(BeNumerically(">", 3))
|
||||
Expect(len(session.OutputToStringArray())).To(BeNumerically(">", 2))
|
||||
})
|
||||
})
|
||||
|
Reference in New Issue
Block a user