Merge "Update profilehandler comments"
[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 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 "intel.com/intel_sriov_700" | tail -n1 |awk '{print $(NF)}')
30
31 echo "The allocated resource of the node is: " $allocated_node_resource
32 cat << POD > $HOME/$pod_name.yaml
33 apiVersion: v1
34 kind: Pod
35 metadata:
36   name: pod-case-01
37   annotations:
38     k8s.v1.cni.cncf.io/networks: sriov-eno2
39 spec:
40   containers:
41   - name: test-pod
42     image: docker.io/centos/tools:latest
43     command:
44     - /sbin/init
45     resources:
46       requests:
47         intel.com/intel_sriov_700: '1'
48       limits:
49         intel.com/intel_sriov_700: '1'
50 POD
51 kubectl create -f $HOME/$pod_name.yaml --validate=false
52     for pod in $pod_name; do
53         status_phase=""
54         while [[ $status_phase != "Running" ]]; do
55             new_phase=$(kubectl get pods $pod | awk 'NR==2{print $3}')
56             if [[ $new_phase != $status_phase ]]; then
57                 echo "$(date +%H:%M:%S) - $pod : $new_phase"
58                 status_phase=$new_phase
59             fi
60             if [[ $new_phase == "Running" ]]; then
61                 echo "Pod is up and running.."
62             fi
63             if [[ $new_phase == "Err"* ]]; then
64                 exit 1
65             fi
66         done
67     done
68 allocated_node_resource=$(kubectl describe node | grep "intel.com/intel_sriov_700" | tail -n1 |awk '{print $(NF)}')
69
70 echo " The current resource allocation after the pod creation is: " $allocated_node_resource
71 kubectl delete pod $pod_name --now
72 echo "Test complete."