Merge "Add X710 to iavf driver NICs"
[multicloud/k8s.git] / kud / tests / qat.sh
1 #!/bin/bash
2 # SPDX-license-identifier: Apache-2.0
3 ##############################################################################
4 # Copyright (c) 2018
5 # All rights reserved. This program and the accompanying materials
6 # are made available under the terms of the Apache License, Version 2.0
7 # which accompanies this distribution, and is available at
8 # http://www.apache.org/licenses/LICENSE-2.0
9 ##############################################################################
10
11 set -o pipefail
12
13 qat_capable_nodes=$(kubectl get nodes -o json | jq -r '.items[] | select(.status.capacity."qat.intel.com/cy2_dc2">="1") | .metadata.name')
14 if [ -z "$qat_capable_nodes" ]; then
15     echo "This test case cannot run. QAT device unavailable."
16     QAT_ENABLED=False
17     exit 0
18 else
19     echo "Can run QAT on this cluster."
20     QAT_ENABLED=True
21 fi
22
23 pod_name=pod-case-01
24 rm -f $HOME/$pod_name.yaml
25 kubectl delete pod $pod_name --ignore-not-found=true --now --wait
26 allocated_node_resource=$(kubectl describe node | grep "qat.intel.com" | tail -n1 |awk '{print $(NF)}')
27 echo "The allocated resource of the node is: " $allocated_node_resource
28 cat << POD > $HOME/$pod_name.yaml
29 kind: Pod
30 apiVersion: v1
31 metadata:
32   name: pod-case-01
33 spec:
34   containers:
35   - name: pod-case-01
36     image: integratedcloudnative/openssl-qat-engine:devel
37     imagePullPolicy: IfNotPresent
38     volumeMounts:
39             - mountPath: /dev
40               name: dev-mount
41             - mountPath: /etc/c6xxvf_dev0.conf
42               name: dev0
43     command: [ "/bin/bash", "-c", "--" ]
44     args: [ "while true; do sleep 300000; done;" ]
45     resources:
46       requests:
47         qat.intel.com/cy2_dc2: '1'
48       limits:
49         qat.intel.com/cy2_dc2: '1'
50   volumes:
51   - name: dev-mount
52     hostPath:
53         path: /dev
54   - name: dev0
55     hostPath:
56         path: /etc/c6xxvf_dev0.conf
57 POD
58 kubectl create -f $HOME/$pod_name.yaml --validate=false
59     for pod in $pod_name; do
60         status_phase=""
61         while [[ $status_phase != "Running" ]]; do
62             new_phase=$(kubectl get pods $pod | awk 'NR==2{print $3}')
63             if [[ $new_phase != $status_phase ]]; then
64                 echo "$(date +%H:%M:%S) - $pod : $new_phase"
65                 status_phase=$new_phase
66             fi
67             if [[ $new_phase == "Running" ]]; then
68                 echo "Pod is up and running.."
69             fi
70             if [[ $new_phase == "Err"* ]]; then
71                 exit 1
72             fi
73         done
74     done
75
76 allocated_node_resource=$(kubectl describe node | grep "qat.intel.com" | tail -n1 |awk '{print $(NF)}')
77 echo "The allocated resource of the node is: " $allocated_node_resource
78 kubectl exec pod-case-01 -- openssl engine -c -t qat
79
80 kubectl delete pod $pod_name --now
81 echo "Test complete."