Bug fix for the ImagePullBackOff error in qat test
[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_device=$( for i in 0434 0435 37c8 6f54 19e2; \
14                 do lspci -d 8086:$i -m; done |\
15                 grep -i "Quick*" | head -n 1 | cut -d " " -f 5 )
16 #Checking if the QAT device is on the node
17 if [ -z "$qat_device" ]; then
18     echo "False. This test case cannot run. Qat device unavailable."
19     QAT_ENABLED=False
20     exit 0
21 else
22     echo "True. Can run QAT on this device."
23     QAT_ENABLED=True
24 fi
25
26 pod_name=pod-case-01
27 rm -f $HOME/$pod_name.yaml
28 kubectl delete pod $pod_name --ignore-not-found=true --now --wait
29 allocated_node_resource=$(kubectl describe node | grep "qat.intel.com" | tail -n1 |awk '{print $(NF)}')
30 echo "The allocated resource of the node is: " $allocated_node_resource
31 cat << POD > $HOME/$pod_name.yaml
32 kind: Pod
33 apiVersion: v1
34 metadata:
35   name: pod-case-01
36 spec:
37   containers:
38   - name: pod-case-01
39     image: integratedcloudnative/openssl-qat-engine:devel
40     imagePullPolicy: IfNotPresent
41     volumeMounts:
42             - mountPath: /dev
43               name: dev-mount
44             - mountPath: /etc/c6xxvf_dev0.conf
45               name: dev0
46     command: [ "/bin/bash", "-c", "--" ]
47     args: [ "while true; do sleep 300000; done;" ]
48     resources:
49       requests:
50         qat.intel.com/cy2_dc2: '1'
51       limits:
52         qat.intel.com/cy2_dc2: '1'
53   volumes:
54   - name: dev-mount
55     hostPath:
56         path: /dev
57   - name: dev0
58     hostPath:
59         path: /etc/c6xxvf_dev0.conf
60 POD
61 kubectl create -f $HOME/$pod_name.yaml --validate=false
62     for pod in $pod_name; do
63         status_phase=""
64         while [[ $status_phase != "Running" ]]; do
65             new_phase=$(kubectl get pods $pod | awk 'NR==2{print $3}')
66             if [[ $new_phase != $status_phase ]]; then
67                 echo "$(date +%H:%M:%S) - $pod : $new_phase"
68                 status_phase=$new_phase
69             fi
70             if [[ $new_phase == "Running" ]]; then
71                 echo "Pod is up and running.."
72             fi
73             if [[ $new_phase == "Err"* ]]; then
74                 exit 1
75             fi
76         done
77     done
78
79 allocated_node_resource=$(kubectl describe node | grep "qat.intel.com" | tail -n1 |awk '{print $(NF)}')
80 echo "The allocated resource of the node is: " $allocated_node_resource
81 adf_ctl restart
82 systemctl restart qat_service
83 kubectl exec -it pod-case-01 -- openssl engine -c -t qat
84
85 kubectl delete pod $pod_name --now
86 echo "Test complete."