Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add unittest script. #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
163 changes: 163 additions & 0 deletions unittest.sh
Original file line number Diff line number Diff line change
@@ -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
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ccowgws3 not ccowgw

do
CHECK=$0
OUTPUT=$(ps aux | grep -v grep | grep -v $CHECK | grep $PROCESS)
Copy link

@kschoche kschoche Dec 2, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally you parse output of source /opt/nedge/env.sh && /opt/nedge/nmf/nefadm status | grep online for (rest network ccowserv docker ccowgws3)
This obviously must run from inside each container.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

source is not working inside container. I am not sure if it is a bug.

root@data01-ab:# docker exec -it nedge-data-s3 ls /opt/nedge/env.sh -lrt
-rw-r--r-- 1 root root 1598 Nov 26 01:05 /opt/nedge/env.sh
root@data01-ab:
# docker exec -it nedge-data-s3 source /opt/nedge/env.sh
rpc error: code = 13 desc = invalid header field value "oci runtime error: exec failed: container_linux.go:247: starting container process caused "exec: \"source\": executable file not found in $PATH"\n"
root@data01-ab:~#

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 "$@"