github.com/dmaizel/tests@v0.0.0-20210728163746-cae6a2d9cee8/integration/kubernetes/k8s-cpu-ns.bats (about) 1 #!/usr/bin/env bats 2 # 3 # Copyright (c) 2018 Intel Corporation 4 # 5 # SPDX-License-Identifier: Apache-2.0 6 # 7 8 load "${BATS_TEST_DIRNAME}/../../.ci/lib.sh" 9 load "${BATS_TEST_DIRNAME}/tests_common.sh" 10 fc_limitations="https://github.com/kata-containers/documentation/issues/351" 11 12 setup() { 13 [ "${KATA_HYPERVISOR}" == "firecracker" ] && skip "test not working see: ${fc_limitations}" 14 15 export KUBECONFIG="${KUBECONFIG:-$HOME/.kube/config}" 16 pod_name="constraints-cpu-test" 17 container_name="first-cpu-container" 18 sharessyspath="/sys/fs/cgroup/cpu/cpu.shares" 19 quotasyspath="/sys/fs/cgroup/cpu/cpu.cfs_quota_us" 20 periodsyspath="/sys/fs/cgroup/cpu/cpu.cfs_period_us" 21 total_cpus=2 22 total_requests=512 23 total_cpu_container=1 24 25 get_pod_config_dir 26 } 27 28 @test "Check CPU constraints" { 29 [ "${KATA_HYPERVISOR}" == "firecracker" ] && skip "test not working see: ${fc_limitations}" 30 31 # Create the pod 32 kubectl create -f "${pod_config_dir}/pod-cpu.yaml" 33 34 # Check pod creation 35 kubectl wait --for=condition=Ready --timeout=$timeout pod "$pod_name" 36 37 retries="10" 38 39 num_cpus_cmd='grep -e "^processor" /proc/cpuinfo |wc -l' 40 # Check the total of cpus 41 for _ in $(seq 1 "$retries"); do 42 # Get number of cpus 43 total_cpus_container=$(kubectl exec pod/"$pod_name" -c "$container_name" \ 44 -- sh -c "$num_cpus_cmd") 45 # Verify number of cpus 46 [ "$total_cpus_container" -le "$total_cpus" ] 47 [ "$total_cpus_container" -eq "$total_cpus" ] && break 48 sleep 1 49 done 50 [ "$total_cpus_container" -eq "$total_cpus" ] 51 52 # Check the total of requests 53 total_requests_container=$(kubectl exec $pod_name -c $container_name \ 54 -- sh -c "cat $sharessyspath") 55 56 [ "$total_requests_container" -eq "$total_requests" ] 57 58 # Check the cpus inside the container 59 60 total_cpu_quota=$(kubectl exec $pod_name -c $container_name \ 61 -- sh -c "cat $quotasyspath") 62 63 total_cpu_period=$(kubectl exec $pod_name -c $container_name \ 64 -- sh -c "cat $periodsyspath") 65 66 division_quota_period=$(echo $((total_cpu_quota/total_cpu_period))) 67 68 [ "$division_quota_period" -eq "$total_cpu_container" ] 69 } 70 71 teardown() { 72 [ "${KATA_HYPERVISOR}" == "firecracker" ] && skip "test not working see: ${fc_limitations}" 73 74 # Debugging information 75 kubectl describe "pod/$pod_name" 76 77 kubectl delete pod "$pod_name" 78 }