Merge "Update single-node KUD installation variables"
[multicloud/k8s.git] / kud / tests / sriov.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 ethernet_adpator_version=$( lspci | grep "Ethernet Controller XL710" | head -n 1 | cut -d " " -f 8 )
14 if [ -z "$ethernet_adpator_version" ]; then
15     echo " Ethernet adapator version is not set. SRIOV test case cannot run on this machine"
16     exit 0
17 fi
18 #checking for the right hardware version of NIC on the machine
19 if [ $ethernet_adpator_version == "XL710" ]; then
20     echo "NIC card specs match. SRIOV option avaiable for this version."
21 else
22     echo -e "Failed. The version supplied does not match.\nTest cannot be executed."
23     exit 0
24 fi
25
26 pod_name=pod-case-01
27
28 function create_pod_yaml_with_single_VF {
29
30 cat << POD > $HOME/$pod_name-single.yaml
31 apiVersion: v1
32 kind: Pod
33 metadata:
34   name: pod-case-01
35   annotations:
36     k8s.v1.cni.cncf.io/networks: sriov-eno2
37 spec:
38   containers:
39   - name: test-pod
40     image: docker.io/centos/tools:latest
41     command:
42     - /sbin/init
43     resources:
44       requests:
45         intel.com/intel_sriov_700: '1'
46       limits:
47         intel.com/intel_sriov_700: '1'
48 POD
49 }
50
51 function create_pod_yaml_with_multiple_VF {
52
53 cat << POD > $HOME/$pod_name-multiple.yaml
54 apiVersion: v1
55 kind: Pod
56 metadata:
57   name: pod-case-01
58   annotations:
59     k8s.v1.cni.cncf.io/networks: sriov-eno2, sriov-eno2
60 spec:
61   containers:
62   - name: test-pod
63     image: docker.io/centos/tools:latest
64     command:
65     - /sbin/init
66     resources:
67       requests:
68         intel.com/intel_sriov_700: '2'
69       limits:
70         intel.com/intel_sriov_700: '2'
71 POD
72 }
73 create_pod_yaml_with_single_VF
74 create_pod_yaml_with_multiple_VF
75
76 for podType in ${POD_TYPE:-single multiple}; do
77
78     kubectl delete pod $pod_name --ignore-not-found=true --now --wait
79     allocated_node_resource=$(kubectl describe node | grep "intel.com/intel_sriov_700" | tail -n1 |awk '{print $(NF)}')
80
81     echo "The allocated resource of the node is: " $allocated_node_resource
82
83     kubectl create -f $HOME/$pod_name-$podType.yaml --validate=false
84
85         for pod in $pod_name; do
86             status_phase=""
87             while [[ $status_phase != "Running" ]]; do
88                 new_phase=$(kubectl get pods $pod | awk 'NR==2{print $3}')
89                 if [[ $new_phase != $status_phase ]]; then
90                     echo "$(date +%H:%M:%S) - $pod-$podType : $new_phase"
91                     status_phase=$new_phase
92                 fi
93                 if [[ $new_phase == "Running" ]]; then
94                     echo "Pod is up and running.."
95                 fi
96                 if [[ $new_phase == "Err"* ]]; then
97                     exit 1
98                 fi
99             done
100         done
101     allocated_node_resource=$(kubectl describe node | grep "intel.com/intel_sriov_700" | tail -n1 |awk '{print $(NF)}')
102
103     echo " The current resource allocation after the pod creation is: " $allocated_node_resource
104     kubectl delete pod $pod_name --now
105     echo "Test complete."
106
107 done