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