From 2ceceabe79a5fb76d42725dc6b559f3039b86eed Mon Sep 17 00:00:00 2001 From: root Date: Mon, 28 Nov 2016 03:33:03 -0800 Subject: [PATCH] Add unittest script. --- unittest.sh | 163 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 163 insertions(+) create mode 100755 unittest.sh diff --git a/unittest.sh b/unittest.sh new file mode 100755 index 0000000..6b58b39 --- /dev/null +++ b/unittest.sh @@ -0,0 +1,163 @@ +#!/bin/bash + +# SYNOPSIS: +# +# +# +# +# +# +# +# + + +#globals +alias neadm="docker run -i -t --rm --network host nexenta/nedge-neadm /opt/neadm/neadm" +chmod 755 /root/c0/nesetup.json +BROKER_INTERFACE=`cat /root/c0/nesetup.json | grep broker | awk '{print $2}' | sed 's/"//g'` +SERVER_INTERFACE=`cat /root/c0/nesetup.json | grep server | awk '{print $2}' | sed 's/"//g'` +DISKLIST=`cat /root/c0/nesetup.json | grep /dev | awk '{print $2}' | sed 's/"//g'` + +#This function checks following things +# 1. Host operating system +# 2. nedge-core version +# 3. NIC speed for the interfaces mentioned in nesetup.json +check_system_status(){ + +#Operating system chheck + ID=$(awk '/DISTRIB_RELEASE=/' /etc/*-release | sed 's/DISTRIB_RELEASE=//' | tr '[:upper:]' '[:lower:]') + OS=$(awk '/DISTRIB_ID=/' /etc/*-release | sed 's/DISTRIB_ID=//' | tr '[:upper:]' '[:lower:]') + + echo -e "\e[1;32mChecking system status..." + + if [ "$OS" = "ubuntu" ] && [ "$ID" = "16.04" ] + then + echo -e "\e[1;32mOperating System: Ubuntu 16.04.1 LTS[OK]\e[0m" + + elif [ "$OS" = "centos" ] && [ "$ID" = "7.2" ] + then + echo -e "\e[1;32mOperating System: CentOS7.2\e[0m" + + else + echo -e "\e[1;31mYou need Ubuntu 16.04 or CentOS 7.2 platform for nedgedev[WARNING]\e[0m" + fi + +#check nedge-core version + VERSION=`docker exec -it nedge-data-s3 dpkg -l | grep -i nedge | awk '{print $3}'` + echo -e "\e[1;32mNedge-Core version: $VERSION" + +#check NIC speed for the broker_interface and server_interface mentioned in nesetup.json + BROKER_INTERFACE_SPEED=`ethtool $BROKER_INTERFACE | grep Speed | awk '{print $2}'` + SERVER_INTERFACE_SPEED=`ethtool $SERVER_INTERFACE | grep Speed | awk '{print $2}'` + echo -e "\e[1;32mbroker_interface speed: $BROKER_INTERFACE_SPEED" + echo -e "\e[1;32mserver_interface speed: $SERVER_INTERFACE_SPEED" +} + +#Check Total memory of the host +check_ram_size(){ + MEMSIZE=`free -g | head -2 | awk '{print $2}' | tail -1` + if [ $MEMSIZE -lt 16 ] + then + echo -e "\e[1;31mTotal Memory: $MEMSIZE GB\e[0m" + echo -e "\e[1;31mMinimum RAM requirement: 16GB[WARNING]\e[0m" + else + echo -e "\e[1;32mTotal Memory: $MEMSIZE GB\e[0m" + fi +} + +#Check Total Disk space of the raw disks mentioned in nesetup.json +check_disk_space(){ + SIZE=0 + for disk in $DISKLIST + do + CAPACITY=`fdisk -l | grep $disk | awk '{print $3,$4}' | head -1 | sed 's/,//g'` + DISKSIZE=($CAPACITY) + SIZE=$(($SIZE + $DISKSIZE)) + if [ ${DISKSIZE[0]} -lt 40 ] + then + echo -e "\e[1;31mThe recommended disk size: minimum 40GB[WARNING]" + echo -e "\e[1;31m"$disk " " $CAPACIT + else + echo -e "\e[1;32m"$disk " " $CAPACITY + fi + done + echo -e "\e[1;32mTotal Disk Space: $SIZE GB" +} + +#check if the network interface is ipv6 +is_nic_ipv6_check(){ + ip -6 addr | grep $BROKER_INTERFACE > /dev/null + EXIT_STATUS=`echo $?` + if [ $EXIT_STATUS -ne 0 ] + then + echo "The broker interface mentioned in /root/c0/nesetup.json: not an IPV6 address.[ERROR]" + fi + + ip -6 addr | grep $SERVER_INTERFACE > /dev/null + EXIT_STATUS=`echo $?` + if [ $EXIT_STATUS -ne 0 ] + then + echo "The server interface mentioned in /root/c0/nesetup.json: not an IPV6 address.[ERROR]" + fi +} + +#MTU size check for the broker_interface and server_interface +#mentioned in nesetup.json +mtu_size(){ + + FRAME_SIZE=`ip link show dev $BROKER_INTERFACE | grep mtu | awk '{print $5}'` + if [ $FRAME_SIZE -ne 9000 ] + then + echo -e "\e[1;31The required frame size[MTU] for broker_interface: 9000.[ERROR]" + else + echo -e "\e[1;32mbroker_interface NIC MTU: 9000[OK]" + fi + + FRAME_SIZE=`ip link show dev $SERVER_INTERFACE | grep mtu | awk '{print $5}'` + if [ $FRAME_SIZE -ne 9000 ] + then + echo -e "\e[1;31The required frame size[MTU] for server_interface: 9000.[ERROR]" + else + echo -e "\e[1;32mserver_interface NIC MTU: 9000[OK]" + fi +} + +#check if the neadm cluster is ONLINE now +neadm_status(){ + NEADM_STATUS=`docker run -i -t --rm --network host nexenta/nedge-neadm /opt/neadm/neadm system status | tail -1 | awk '{print $9}' | sed -r "s/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]//g"` + + if [ "${NEADM_STATUS}" == 'ONLINE' ]; + then + echo -e "\e[1;32mneadm system status: ONLINE[OK]\e[0m" + else + echo -e "\e[1;31mThe neadm system: NOT ONLINE[WARNING]\e[0m" + fi +} + +#check neadm services are running such as docker ccowgw auditserv ccowserv logger networkWorker restWorke +neadm_services(){ + + echo -e "\e[1;32mChecking nedge services...\e[0m" + for PROCESS in docker ccowgw auditserv ccowserv logger networkWorker restWorker + do + CHECK=$0 + OUTPUT=$(ps aux | grep -v grep | grep -v $CHECK | grep $PROCESS) + if [ "${#OUTPUT}" -gt 0 ] + then + printf "\e[1;32m%-26s running[OK]\n\e[0m" ${PROCESS}: + else + printf "\e[1;32m%-26s service:NOT running[WARNING]\n\e[0m" ${PROCESS}: + fi + done +} +main(){ + + check_system_status + check_ram_size + check_disk_space + is_nic_ipv6_check + mtu_size + neadm_status + neadm_services +} +main "$@"