|
| 1 | +#!/bin/bash |
| 2 | +#======================================================== |
| 3 | +# The script is designed to install ydk-py components |
| 4 | +# in Python3 development environment. |
| 5 | +# |
| 6 | +# NOTE-2! This script is designed for LINUX platform only |
| 7 | +#======================================================== |
| 8 | + |
| 9 | +function print_msg { |
| 10 | + echo -e "${MSG_COLOR}*** $(date): tests_py3.sh | $@ ${NOCOLOR}" |
| 11 | +} |
| 12 | + |
| 13 | +function run_cmd { |
| 14 | + local cmd=$@ |
| 15 | + print_msg "Running command: $cmd" |
| 16 | + $cmd |
| 17 | + local status=$? |
| 18 | + if [ $status -ne 0 ]; then |
| 19 | + MSG_COLOR=$RED |
| 20 | + print_msg "Exiting '$cmd' with status=$status" |
| 21 | + exit $status |
| 22 | + fi |
| 23 | + return $status |
| 24 | +} |
| 25 | + |
| 26 | +function test_python_installation { |
| 27 | + PYTHON_BIN=python3 |
| 28 | + PIP_BIN=pip3 |
| 29 | + |
| 30 | + print_msg "Checking installation of ${PYTHON_BIN}" |
| 31 | + ${PYTHON_BIN} -V |
| 32 | + status=$? |
| 33 | + if [ $status -ne 0 ]; then |
| 34 | + MSG_COLOR=$RED |
| 35 | + print_msg "Could not locate ${PYTHON_BIN}" |
| 36 | + exit $status |
| 37 | + fi |
| 38 | + print_msg "Checking installation of ${PIP_BIN}" |
| 39 | + ${PIP_BIN} -V |
| 40 | + status=$? |
| 41 | + if [ $status -ne 0 ]; then |
| 42 | + MSG_COLOR=$RED |
| 43 | + print_msg "Could not locate ${PIP_BIN}" |
| 44 | + exit $status |
| 45 | + fi |
| 46 | + print_msg "Python location: $(which ${PYTHON_BIN})" |
| 47 | + print_msg "Pip location: $(which ${PIP_BIN})" |
| 48 | +} |
| 49 | + |
| 50 | +function pip_check_install { |
| 51 | + if [[ ${os_info} == *"fedora"* ]]; then |
| 52 | + print_msg "Custom pip install of $@ for centos" |
| 53 | + sudo ${PIP_BIN} install --install-option="--install-purelib=/usr/lib64/python2.7/site-packages" --no-deps $@ |
| 54 | + return |
| 55 | + fi |
| 56 | + sudo ${PIP_BIN} install --no-deps $@ |
| 57 | +} |
| 58 | + |
| 59 | +# Terminal colors |
| 60 | +RED="\033[0;31m" |
| 61 | +NOCOLOR="\033[0m" |
| 62 | +YELLOW='\033[1;33m' |
| 63 | +MSG_COLOR=$YELLOW |
| 64 | + |
| 65 | +test_python_installation |
| 66 | + |
| 67 | +os_type=$(uname) |
| 68 | +if [[ ${os_type} == "Linux" ]] ; then |
| 69 | + os_info=$(cat /etc/*-release) |
| 70 | +else |
| 71 | + os_info=$(sw_vers) |
| 72 | +fi |
| 73 | + |
| 74 | +YDK_HOME=`pwd` |
| 75 | + |
| 76 | +if [[ $(uname) == "Linux" && ${os_info} == *"fedora"* ]] ; then |
| 77 | + export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$YDK_HOME/grpc/libs/opt:$YDK_HOME/protobuf-3.5.0/src/.libs:/usr/local/lib64 |
| 78 | + print_msg "LD_LIBRARY_PATH is set to: $LD_LIBRARY_PATH" |
| 79 | +fi |
| 80 | + |
| 81 | +print_msg "Installing YDK core package" |
| 82 | +cd core |
| 83 | +${PYTHON_BIN} setup.py sdist |
| 84 | +sudo ${PIP_BIN} install dist/ydk*.tar.gz |
| 85 | + |
| 86 | +print_msg "Testing YDK core installation" |
| 87 | +${PYTHON_BIN} -c "import ydk.types" |
| 88 | +status=$? |
| 89 | +if [ $status -ne 0 ]; then |
| 90 | + MSG_COLOR=$RED |
| 91 | + print_msg "Exiting with status=$status" |
| 92 | + exit $status |
| 93 | +fi |
| 94 | + |
| 95 | +print_msg "Installing YDK gNMI package" |
| 96 | +cd ../gnmi |
| 97 | +${PYTHON_BIN} setup.py sdist |
| 98 | +sudo ${PIP_BIN} install dist/ydk*.tar.gz |
| 99 | + |
| 100 | +print_msg "Testing YDK gNMI installation" |
| 101 | +${PYTHON_BIN} -c "import ydk.gnmi.providers" |
| 102 | +status=$? |
| 103 | +if [ $status -ne 0 ]; then |
| 104 | + MSG_COLOR=$RED |
| 105 | + print_msg "Exiting with status=$status" |
| 106 | + exit $status |
| 107 | +fi |
| 108 | + |
| 109 | +print_msg "Installing ietf bundle package" |
| 110 | +cd ../ietf |
| 111 | +${PYTHON_BIN} setup.py sdist |
| 112 | +pip_check_install dist/*.tar.gz |
| 113 | + |
| 114 | +print_msg "Installing openconfig bundle package" |
| 115 | +cd ../openconfig |
| 116 | +${PYTHON_BIN} setup.py sdist |
| 117 | +pip_check_install dist/*.tar.gz |
| 118 | + |
| 119 | +print_msg "Installing cisco-ios-xr bundle package" |
| 120 | +cd ../cisco-ios-xr |
| 121 | +${PYTHON_BIN} setup.py sdist |
| 122 | +pip_check_install dist/*.tar.gz |
| 123 | + |
| 124 | +print_msg "Installing cisco-ios-xe bundle package" |
| 125 | +cd ../cisco-ios-xe |
| 126 | +${PYTHON_BIN} setup.py sdist |
| 127 | +pip_check_install dist/*.tar.gz |
| 128 | + |
| 129 | +print_msg "Installing cisco-nx-os bundle package" |
| 130 | +cd ../cisco-nx-os |
| 131 | +${PYTHON_BIN} setup.py sdist |
| 132 | +pip_check_install dist/*.tar.gz |
| 133 | + |
| 134 | +print_msg "Running codec sample" |
| 135 | +cd ../core/samples |
| 136 | +${PYTHON_BIN} bgp_codec.py |
| 137 | + |
| 138 | +print_msg "Checking ${PYTHON_BIN} environment" |
| 139 | +run_cmd ${PIP_BIN} list --format=columns |
0 commit comments