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

Edited compat handling code for containers/json status and added python tests #10610

Merged
merged 1 commit into from
Jun 23, 2021
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
18 changes: 18 additions & 0 deletions pkg/api/handlers/compat/containers.go
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,24 @@ func LibpodToContainerJSON(l *libpod.Container, sz bool) (*types.ContainerJSON,
state.Status = define.ContainerStateCreated.String()
}

state.Health = &types.Health{
Status: inspect.State.Healthcheck.Status,
FailingStreak: inspect.State.Healthcheck.FailingStreak,
}

log := inspect.State.Healthcheck.Log

for _, item := range log {
res := &types.HealthcheckResult{}
s, _ := time.Parse(time.RFC3339Nano, item.Start)
e, _ := time.Parse(time.RFC3339Nano, item.End)
res.Start = s
res.End = e
res.ExitCode = item.ExitCode
res.Output = item.Output
state.Health.Log = append(state.Health.Log, res)
}

formatCapabilities(inspect.HostConfig.CapDrop)
formatCapabilities(inspect.HostConfig.CapAdd)

Expand Down
23 changes: 23 additions & 0 deletions test/apiv2/python/rest_api/test_v2_0_0_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ def test_list(self):
obj = r.json()
self.assertEqual(len(obj), 1)

def test_list_filters(self):
r = requests.get(self.podman_url + "/v1.40/containers/json?filters%3D%7B%22status%22%3A%5B%22running%22%5D%7D")
self.assertEqual(r.status_code, 200, r.text)
payload = r.json()
containerAmnt = len(payload)
self.assertGreater(containerAmnt, 0)

def test_list_all(self):
r = requests.get(self.uri("/containers/json?all=true"))
self.assertEqual(r.status_code, 200, r.text)
Expand All @@ -25,6 +32,22 @@ def test_inspect(self):
self.assertId(r.content)
_ = parse(r.json()["Created"])

r = requests.post(
self.podman_url + "/v1.40/containers/create?name=topcontainer",
json={"Cmd": ["top"], "Image": "alpine:latest"},
)
self.assertEqual(r.status_code, 201, r.text)
payload = r.json()
container_id = payload["Id"]
self.assertIsNotNone(container_id)

r = requests.get(self.podman_url + f"/v1.40/containers/{payload['Id']}/json")
cdoern marked this conversation as resolved.
Show resolved Hide resolved
self.assertEqual(r.status_code, 200, r.text)
self.assertId(r.content)
out = r.json()
state = out["State"]["Health"]
self.assertIsInstance(state, dict)

def test_stats(self):
r = requests.get(self.uri(self.resolve_container("/containers/{}/stats?stream=false")))
self.assertIn(r.status_code, (200, 409), r.text)
Expand Down