This patch contains the scripts to remove hardcoded kernel version, 63/20563/4
authorkalyanreddy <reddyx.gundarapu@intel.com>
Wed, 7 Sep 2016 13:44:05 +0000 (19:14 +0530)
committerkalyanreddy <reddyx.gundarapu@intel.com>
Thu, 8 Sep 2016 09:51:26 +0000 (15:21 +0530)
host ip and cleaning of the host machine after execution of
cyclictest.

Change-Id: I92aaed5229fc3c572e74dcce03b2c984ae1bb111
Co-Authored-By: Shravani <shravani.p@tcs.com>
Signed-off-by: Gundarapu Kalyan Reddy <reddyx.gundarapu@intel.com>
ci/envs/guest-setup0.sh
ci/envs/host-setup0.sh
ci/envs/utils.sh [new file with mode: 0755]
ci/test_kvmfornfv.sh

index 4f9eaa4..301d34c 100755 (executable)
@@ -8,9 +8,15 @@
 ## http://www.apache.org/licenses/LICENSE-2.0
 ###############################################################################
 
+source utils.sh
 
+KERNEL_VERSION=$( getKernelVersion )
+if [ -z $KERNEL_VERSION ];then
+   echo "Kernel RPM not found"
+   exit 1
+fi
 rpmdir=${1:-"/root/workspace/rpm"}
-rpmpat="kernel-4.4*.rpm"
+rpmpat="kernel-${KERNEL_VERSION}*.rpm"
 guest_isolcpus=1
 
 # The script's caller should passing the rpm directory that is built out from
index 28c49b8..0778aae 100755 (executable)
@@ -9,10 +9,16 @@
 ## http://www.apache.org/licenses/LICENSE-2.0
 ###############################################################################
 
+source utils.sh
 source host-config
 
+KERNEL_VERSION=$( getKernelVersion )
+if [ -z $KERNEL_VERSION ];then
+   echo "Kernel RPM not found"
+   exit 1
+fi
 rpmdir=${1:-"/root/workspace/rpm/"}
-rpmpat="kernel-4.4*.rpm"
+rpmpat="kernel-${KERNEL_VERSION}*.rpm"
 
 config_grub () {
     key=$1
diff --git a/ci/envs/utils.sh b/ci/envs/utils.sh
new file mode 100755 (executable)
index 0000000..f582b5a
--- /dev/null
@@ -0,0 +1,23 @@
+#!/bin/bash
+###############################################################################
+#      This script is to fetch kernel version and host ip at run time.
+###############################################################################
+
+#To get the Kernel version from RPM generated(example:kernel-4.4.6_rt14_1607061504nfv-3.x86_64.rpm)
+function getKernelVersion {
+   rpm_dir="/root/workspace/rpm/"
+   if [ -d "$WORKSPACE" ];then
+      cd $WORKSPACE/build_output 2>/dev/null; kernelRPM=`ls kernel-[[:digit:]]* 2>/dev/null`
+      RPMVERSION=`echo ${kernelRPM}|awk -F '_' '{print $1}' | awk -F '-' '{print $NF}'`
+   elif [ -d "$rpm_dir" ];then
+      cd $rpm_dir 2>/dev/null; kernelRPM=`ls kernel-[[:digit:]]* 2>/dev/null`
+      RPMVERSION=`echo ${kernelRPM}|awk -F '_' '{print $1}' | awk -F '-' '{print $NF}'`
+   fi
+   echo ${RPMVERSION}
+}
+
+#Get the IP address from pod.yaml file (example ip : 10.2.117.23)
+function getHostIP {
+   HOST_IP=`grep 'ip' $WORKSPACE/tests/pod.yaml | awk -F ': ' '{print $NF}' | tail -1`
+   echo $HOST_IP
+}
index e507f37..fd29f6d 100755 (executable)
@@ -6,15 +6,30 @@
 ## and verifies the test results.
 ############################################################
 
+source $WORKSPACE/ci/envs/utils.sh
+HOST_IP=$( getHostIP )
+KERNEL_VERSION=$( getKernelVersion )
+if [ -z $KERNEL_VERSION ];then
+   echo "Kernel RPM not found in $WORKSPACE/build_output Directory"
+   exit 1
+fi
+
 docker_image_dir=$WORKSPACE/docker_image_build
 function env_clean {
-    container_id=`sudo docker ps -a | grep kvmfornfv |awk '{print $1}'`
+    container_id=`sudo docker ps -a | grep kvmfornfv |awk '{print $1}'|sed -e 's/\r//g'`
     sudo docker rm $container_id
-    sudo ssh root@10.2.117.23 "rm -rf /root/workspace/*"
-    sudo ssh root@10.2.117.23 "pid=\$(ps aux | grep 'qemu' | awk '{print \$2}' | head -1); echo \$pid |xargs kill"
+    sudo ssh root@$HOST_IP "rm -rf /root/workspace/*"
+    sudo ssh root@$HOST_IP "pid=\$(ps aux | grep 'qemu' | awk '{print \$2}' | head -1); echo \$pid |xargs kill"
     sudo rm -rf /tmp/kvmtest-*
 }
 
+function host_clean {
+    sudo ssh root@$HOST_IP "rpm=\$(rpm -qa | grep 'kernel-${KERNEL_VERSION}' | awk '{print \$1}'); rpm -ev \$rpm"
+    sudo ssh root@$HOST_IP "rm -rf /boot/initramfs-${KERNEL_VERSION}*.img"
+    sudo ssh root@$HOST_IP "grub2-mkconfig -o /boot/grub2/grub.cfg"
+    sudo ssh root@$HOST_IP "reboot"
+}
+
 #Cleaning up the test environment before running cyclictest through yardstick.
 env_clean
 
@@ -31,7 +46,7 @@ volume=/tmp/kvmtest-${time_stamp}
 mkdir -p $volume/{image,rpm,scripts}
 
 #copying required files to run yardstick cyclic testcase
-mv $WORKSPACE/build_output/kernel-4.4*.rpm $volume/rpm
+mv $WORKSPACE/build_output/kernel-${KERNEL_VERSION}*.rpm $volume/rpm
 cp -r $WORKSPACE/ci/envs/* $volume/scripts
 cp -r $WORKSPACE/tests/cyclictest-node-context.yaml $volume
 cp -r $WORKSPACE/tests/pod.yaml $volume
@@ -49,11 +64,17 @@ if [ -z "$result" ]; then
     echo `grep -o '"data":[^}]*' $volume/yardstick.out | awk -F '{' '{print $2}'`
     echo ""
     echo "####################################################"
+    #cleaning the environment after executing the test through yardstick.
     env_clean
+    #Cleaning the latest kernel changes on host after executing the test.
+    host_clean
     exit 0
 else
     echo "Testcase failed"
     echo `grep -o '"errors":[^,]*' ${volume}/yardstick.out | awk -F '"' '{print $4}'`
+    #cleaning the environment after executing the test through yardstick.
     env_clean
+    #Cleaning the latest kernel changes on host after executing the test.
+    host_clean
     exit 1
 fi