RPM: Apex: Refactor build scripts:
[ovsnfv.git] / build / test_ovs_rpm.sh
1 #!/bin/bash
2
3 # Copyright (c) 2016 Open Platform for NFV Project, Inc. and its contributors
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 echo "==============================="
20 echo "Requires sudo privileges"
21 echo executing $0 $@
22 echo executing on machine `uname -a`
23
24
25 usage() {
26     echo $0 [-d] [-k]
27     echo -d -- Test with DPDK
28     echo -k -- Load linux kernel module
29 }
30
31 function uninstallrpms() {
32     cleanrpms
33 }
34
35 while getopts "dg:hkp:u:v" opt; do
36     case "$opt" in
37         d)
38             DPDK="yes"
39             ;;
40         g)
41             TAG=${OPTARG}
42             ;;
43         h|\?)
44             usage
45             exit 1
46             ;;
47         k)
48             kmod="yes"
49             ;;
50         u)
51             OVS_REPO_URL=${OPTARG}
52             ;;
53         v)
54             verbose="yes"
55             ;;
56     esac
57 done
58
59 HOME=`pwd`
60 TOPDIR=$HOME
61 TMPDIR=$TOPDIR/ovsrpm
62
63 BUILDDIR=$HOME
64 source $BUILDDIR/functions.sh
65
66 if [ -d $TMPDIR ]
67 then
68     rm -rf $TMPDIR
69 fi
70
71 mkdir -p $TMPDIR
72
73 cd $TMPDIR
74
75 mkdir -p $HOME/rpmbuild/RPMS/x86_64
76 mkdir -p $HOME/rpmbuild/SOURCES
77 mkdir -p $HOME/rpmbuild/SPECS
78 mkdir -p $HOME/rpmbuild/SRPMS
79
80 RPMDIR=$HOME/rpmbuild
81 cp $HOME/*.rpm $RPMDIR/RPMS/x86_64
82
83 function stopovs() {
84     set +e
85     /bin/systemctl is-active openvswitch.service
86     if [ $? -eq 0 ]; then
87         sudo /bin/systemctl stop openvswitch.service
88     fi
89     set -e
90 }
91
92 echo "-----------------------------------"
93 echo "Clean old dpdk and ovs installations"
94 echo
95 stopovs
96 cleanrpms
97
98 if [ ! -z $DPDK ]; then
99     if [ -z $DPDK_VERSION ]; then
100         DPDK_VERSION=16.04.0
101     fi
102     echo "-----------------------------------"
103     echo "Install DPDK RPMs for version $DPDK_VERSION"
104     echo
105     sudo rpm -ivh $RPMDIR/RPMS/x86_64/dpdk-${DPDK_VERSION:0:1}*.rpm
106     sudo rpm -ivh $RPMDIR/RPMS/x86_64/dpdk-tools-${DPDK_VERSION:0:1}*.rpm
107     sudo rpm -ivh $RPMDIR/RPMS/x86_64/dpdk-examples-${DPDK_VERSION:0:1}*.rpm
108 fi
109
110 if [ ! -z $kmod ]; then
111     echo "-----------------------------------"
112     echo "Test installation of kmod RPM"
113     echo
114     sudo rpm -ivh $RPMDIR/RPMS/x86_64/openvswitch-kmod*.rpm
115 fi
116 echo "-----------------------------------"
117 echo "Test installation of user space RPM"
118 echo
119 sudo rpm -ivh $RPMDIR/RPMS/x86_64/openvswitch-2*.rpm
120
121 echo "-----------------------------------"
122 echo "Start openvswitch service."
123 echo
124 sudo service openvswitch start
125
126 sudo ovs-vsctl show
127 sudo ovs-vsctl add-br brtest
128 sudo ovs-ofctl dump-flows brtest
129 sudo ovs-vsctl del-br brtest
130 sudo service openvswitch stop
131 uninstallrpms
132
133 exit 0