Refactor "utils.parse_ini_file" testing
[yardstick.git] / yardstick / resources / scripts / install / ovs_deploy.bash
1 #!/bin/bash
2 #
3 # Copyright (c) 2016-2017 Intel Corporation
4 #
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
8 #
9 #      http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16
17 set -e
18
19 INSTALL_OVS_BIN="/usr/src"
20 cd $INSTALL_OVS_BIN
21
22 if [[ $EUID -ne 0 ]]; then
23   echo "Must be root to run $0"
24   exit 1;
25 fi
26
27 download_zip()
28 {
29   url=$1
30   download_type=$2
31   if [ -n "${download_type}" ]; then
32     echo "Download ${download_type} zip"
33   fi
34   # rm goes into calling code
35   echo "${url}"
36   if [ ! -e "${url##*/}" ]; then
37     wget "${url}"
38   fi
39   tar xvf "${url##*/}"
40 }
41
42 dpdk_build()
43 {
44   echo "Build DPDK libraries"
45   pushd .
46   if [[ $DPDK_VERSION != "" ]]; then
47     export DPDK_DIR=$INSTALL_OVS_BIN/dpdk-stable-$DPDK_VERSION
48     export RTE_TARGET=x86_64-native-linuxapp-gcc
49     export DPDK_BUILD=$DPDK_DIR/$RTE_TARGET
50     rm -rf "$DPDK_DIR"
51     DPDK_DOWNLOAD="http://fast.dpdk.org/rel/dpdk-$DPDK_VERSION.tar.xz"
52     download_zip "${DPDK_DOWNLOAD}" "DPDK"
53     cd dpdk-stable-"$DPDK_VERSION"
54     make config T=$RTE_TARGET
55     make install -j $(nproc) T=$RTE_TARGET
56   fi
57   popd
58 }
59
60 ovs()
61 {
62   echo "Build and install OVS with DPDK"
63   pushd .
64   if [[ $OVS_VERSION != "" ]]; then
65     rm -rf openswitch-"$OVS_VERSION"
66     OVS_DOWNLOAD="http://openvswitch.org/releases/openvswitch-$OVS_VERSION.tar.gz"
67     download_zip "${OVS_DOWNLOAD}" "OVS"
68     cd openvswitch-"$OVS_VERSION"
69     export OVS_DIR=/usr/src/openvswitch-$OVS_VERSION
70     ./boot.sh
71     if [[ $DPDK_VERSION != "" ]]; then
72       ./configure --with-dpdk="$DPDK_BUILD"
73     else
74       ./configure
75     fi
76     make install -j $(nproc)
77   fi
78   popd
79 }
80
81 main()
82 {
83   dpdk_build
84   ovs
85 }
86
87 for i in "$@"
88 do
89   case $i in
90     -o=*|--ovs=*)
91       OVS_VERSION="${i#*=}"
92     ;;
93     -d=*|--dpdk=*)
94       DPDK_VERSION="${i#*=}"
95     ;;
96     -p=*|--proxy=*)
97       export http_proxy="${i#*=}"
98       export https_proxy="${i#*=}"
99     ;;
100     -h|--help)
101       echo "CommandLine options:"
102       echo "===================="
103       echo "1. ovs_dpdk install mode:"
104       echo "./ovs_install.sh --ovs=<2.7.0> --dpdk=<supported dpdk versoin for given ovs> -p=<proxy>"
105       echo
106       exit
107     ;;
108     *)
109     ;;
110   esac
111 done
112
113 main