From c65d1c02b968d0f828a38cd3b15d93d71876bd43 Mon Sep 17 00:00:00 2001 From: Toshiki Sonoda Date: Wed, 18 Oct 2023 14:44:27 +0900 Subject: [PATCH] test/apiv2/20-containers.at: fix NanoCPUs tests on cgroups v1 * rootful: NanoCpus needs to set more than 10000000 on cgroups v1. * rootless: Resource limits that include NanoCPUs are not supported and ignored. Signed-off-by: Toshiki Sonoda --- test/apiv2/20-containers.at | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/test/apiv2/20-containers.at b/test/apiv2/20-containers.at index 31d1b48e4a..0723a8a860 100644 --- a/test/apiv2/20-containers.at +++ b/test/apiv2/20-containers.at @@ -470,11 +470,29 @@ t POST containers/prune?filters='{"network":["anynetwork"]}' 500 \ .cause="network is an invalid filter" # Test CPU limit (NanoCPUs) -t POST containers/create Image=$IMAGE HostConfig='{"NanoCpus":500000}' 201 \ - .Id~[0-9a-f]\\{64\\} +nanoCpu=500000 +if have_cgroupsv2; then + t POST containers/create Image=$IMAGE HostConfig='{"NanoCpus":500000}' 201 \ + .Id~[0-9a-f]\\{64\\} +else + if root; then + # cgroupsv1 rootful : NanoCpus needs to set more than 10000000 + t POST containers/create Image=$IMAGE HostConfig='{"NanoCpus":500000}' 500 \ + .cause="CPU cfs quota cannot be less than 1ms (i.e. 1000)" + t POST containers/create Image=$IMAGE HostConfig='{"NanoCpus":10000000}' 201 \ + .Id~[0-9a-f]\\{64\\} + nanoCpu=10000000 + else + # cgroupsv1 rootless : Resource limits that include NanoCPUs are not supported and ignored + t POST containers/create Image=$IMAGE HostConfig='{"NanoCpus":500000}' 201 \ + .Id~[0-9a-f]\\{64\\} + nanoCpu=0 + fi +fi + cid=$(jq -r '.Id' <<<"$output") t GET containers/$cid/json 200 \ - .HostConfig.NanoCpus=500000 + .HostConfig.NanoCpus=$nanoCpu t DELETE containers/$cid?v=true 204