Skip to content

Commit

Permalink
Merge pull request #12684 from mheon/remap_states
Browse files Browse the repository at this point in the history
Revamp Libpod state strings for Docker compat
  • Loading branch information
openshift-merge-robot authored Jan 18, 2022
2 parents d0eb24b + 141de86 commit d6b0720
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 18 deletions.
5 changes: 2 additions & 3 deletions cmd/podman/containers/ps.go
Original file line number Diff line number Diff line change
Expand Up @@ -358,13 +358,12 @@ func (l psReporter) State() string {
case "running":
t := units.HumanDuration(time.Since(time.Unix(l.StartedAt, 0)))
state = "Up " + t + " ago"
case "configured":
state = "Created"
case "exited", "stopped":
t := units.HumanDuration(time.Since(time.Unix(l.ExitedAt, 0)))
state = fmt.Sprintf("Exited (%d) %s ago", l.ExitCode, t)
default:
state = l.ListContainer.State
// Need to capitalize the first letter to match Docker.
state = strings.Title(l.ListContainer.State)
}
return state
}
Expand Down
15 changes: 11 additions & 4 deletions libpod/define/containerstate.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,23 @@ const (
ContainerStateStopping ContainerStatus = iota
)

// ContainerStatus returns a string representation for users
// of a container state
// ContainerStatus returns a string representation for users of a container
// state. All results should match Docker's versions (from `docker ps`) as
// closely as possible, given the different set of states we support.
func (t ContainerStatus) String() string {
switch t {
case ContainerStateUnknown:
return "unknown"
case ContainerStateConfigured:
return "configured"
case ContainerStateCreated:
// The naming here is confusing, but it's necessary for Docker
// compatibility - their Created state is our Configured state.
return "created"
case ContainerStateCreated:
// Docker does not have an equivalent to this state, so give it
// a clear name. Most of the time this is a purely transitory
// state between Configured and Running so we don't expect to
// see it much anyways.
return "initialized"
case ContainerStateRunning:
return "running"
case ContainerStateStopped:
Expand Down
4 changes: 2 additions & 2 deletions test/apiv2/20-containers.at
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ podman create -t -i --name myctr $IMAGE ls
# Check configuration before initializing
t GET libpod/containers/myctr/json 200 \
.Id~[0-9a-f]\\{64\\} \
.State.Status="configured" \
.State.Status="created" \
.State.Pid=0 \
.ResolvConfPath="" \
.HostnamePath="" \
Expand All @@ -172,7 +172,7 @@ t POST libpod/containers/myctr/init 204
# Check configuration after initializing
t GET libpod/containers/myctr/json 200 \
.Id~[0-9a-f]\\{64\\} \
.State.Status="created" \
.State.Status="initialized" \
.State.Pid~[0-9]\\{1\,8\\} \
.ResolvConfPath=$userdata_path/resolv.conf \
.HostnamePath=$userdata_path/hostname \
Expand Down
10 changes: 5 additions & 5 deletions test/e2e/init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ var _ = Describe("Podman init", func() {
result.WaitWithDefaultTimeout()
Expect(result).Should(Exit(0))
conData := result.InspectContainerToJSON()
Expect(conData[0].State.Status).To(Equal("created"))
Expect(conData[0].State.Status).To(Equal("initialized"))
})

It("podman init single container by name", func() {
Expand All @@ -72,7 +72,7 @@ var _ = Describe("Podman init", func() {
result.WaitWithDefaultTimeout()
Expect(result).Should(Exit(0))
conData := result.InspectContainerToJSON()
Expect(conData[0].State.Status).To(Equal("created"))
Expect(conData[0].State.Status).To(Equal("initialized"))
})

It("podman init latest container", func() {
Expand All @@ -87,7 +87,7 @@ var _ = Describe("Podman init", func() {
result.WaitWithDefaultTimeout()
Expect(result).Should(Exit(0))
conData := result.InspectContainerToJSON()
Expect(conData[0].State.Status).To(Equal("created"))
Expect(conData[0].State.Status).To(Equal("initialized"))
})

It("podman init all three containers, one running", func() {
Expand All @@ -107,12 +107,12 @@ var _ = Describe("Podman init", func() {
result.WaitWithDefaultTimeout()
Expect(result).Should(Exit(0))
conData := result.InspectContainerToJSON()
Expect(conData[0].State.Status).To(Equal("created"))
Expect(conData[0].State.Status).To(Equal("initialized"))
result2 := podmanTest.Podman([]string{"inspect", "test2"})
result2.WaitWithDefaultTimeout()
Expect(result2).Should(Exit(0))
conData2 := result2.InspectContainerToJSON()
Expect(conData2[0].State.Status).To(Equal("created"))
Expect(conData2[0].State.Status).To(Equal("initialized"))
result3 := podmanTest.Podman([]string{"inspect", "test3"})
result3.WaitWithDefaultTimeout()
Expect(result3).Should(Exit(0))
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/pod_pause_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ var _ = Describe("Podman pod pause", func() {
podmanTest *PodmanTestIntegration
)

pausedState := "paused"
pausedState := "Paused"

BeforeEach(func() {
SkipIfRootlessCgroupsV1("Pause is not supported in cgroups v1")
Expand Down
2 changes: 1 addition & 1 deletion test/system/040-ps.bats
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ EOF
run_podman ps --external
is "${#lines[@]}" "3" "podman ps -a --external sees buildah containers"
is "${lines[1]}" \
"[0-9a-f]\{12\} \+$IMAGE *buildah .* seconds ago .* storage .* ${PODMAN_TEST_IMAGE_NAME}-working-container" \
"[0-9a-f]\{12\} \+$IMAGE *buildah .* seconds ago .* Storage .* ${PODMAN_TEST_IMAGE_NAME}-working-container" \
"podman ps --external"

# 'rm -a' should be a NOP
Expand Down
2 changes: 1 addition & 1 deletion test/system/080-pause.bats
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ load helpers
is "$output" "paused" "podman inspect .State.Status"
sleep 3
run_podman ps -a --format '{{.ID}} {{.Names}} {{.Status}}'
is "$output" "${cid:0:12} $cname paused" "podman ps on paused container"
is "$output" "${cid:0:12} $cname Paused" "podman ps on paused container"
run_podman unpause $cname
run_podman ps -a --format '{{.ID}} {{.Names}} {{.Status}}'
is "$output" "${cid:0:12} $cname Up .*" "podman ps on resumed container"
Expand Down
2 changes: 1 addition & 1 deletion test/upgrade/test-upgrade.bats
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ EOF
@test "inspect - all container status" {
tests="
running | running | 0
created | configured | 0
created | created | 0
done | exited | 0
failed | exited | 17
"
Expand Down

0 comments on commit d6b0720

Please sign in to comment.