10a2f05a4a7925aaad37c3475c6b969e1f62ebd5
[ovsnfv.git] / build / BuildAndTestOVS.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
22
23 usage() {
24     echo "$0 -a <kernel major> -d -g <OVS TAG> -h\
25              -i <kernel minor> -p <patch url> -t -u <OVS URL> -v <verbose\
26     -a <kernel major> -- Specify major release if special kernel is required\
27     The default kernel is Centos 7.2 kernel after upgrade.\
28     -d <dpdk>         -- Specify dpdk build.\
29                     The default is to build ovs for linux kernel data path.\
30     -g <OVS TAG>      -- OVS release tag or branch to build such as 2.4.\
31                     The default is master.\
32     -h print this message\
33     -i <kernel minor> -- Specify minor release if special kernel is required.\
34                     The default kernel is Centos 7.2 kernel after upgrade.\
35     -p <patch url>    -- Specify url to patches if required for ovs rpm.\
36     -t                -- Test rpm.\
37     -u <OVS URL>      -- path to OVS repo if using fork for patch.\
38                     The default is https://github.com/openvswitch/ovs.git\
39     -v                -- Set verbose mode."
40 }
41
42 while getopts "a:dg:hi:p:tu:v" opt; do
43     case "$opt" in
44         a)
45             kernel_major=${OPTARG}
46             ;;
47         d)
48             DPDK="yes"
49             ;;
50         g)
51             TAG=${OPTARG}
52             ;;
53         h)
54             usage
55             exit 1
56             ;;
57         i)
58             kernel_minor=${OPTARG}
59             ;;
60         p)
61             OVS_PATCH=${OPTARG}
62             ;;
63         t)
64             TESTRPM="yes"
65             ;;
66         u)
67             OVS_REPO_URL=${OPTARG}
68             ;;
69         v)
70             verbose="yes"
71             ;;
72     esac
73 done
74
75 if [ -z $TAG ]; then
76     TAG=master
77 fi
78
79 if [ -z $OVS_REPO_URL ]; then
80     OVS_REPO_URL=https://github.com/openvswitch/ovs.git
81 fi
82
83 if [ ! -z $kernel_major ] && [ ! -z $kernel_minor ]; then
84     kernel_version=$kernel_major.$kernel_minor
85     echo ===================
86     echo Will install kernel version: major is $kernel_major and minor is $kernel_minor
87     echo ===================
88 else
89     echo Will use default kernel in ovs test vm
90 fi
91
92 if [ ! -z $DPDK ]; then
93     setbuilddpdk="-d"
94 fi
95
96 if [ -z ${WORKSPACE+1} ]; then
97     # We are not being run by Jenkins.
98     export WORKSPACE=$HOME/opnfv/ovsnfv
99     mkdir -p opnfv
100     cd opnfv
101     git clone https://git.opnfv.org/ovsnfv
102 fi
103
104 export BUILD_BASE=$WORKSPACE/build
105
106
107
108 if [ ! -d $BUILD_BASE ]
109 then
110     mkdir -p $BUILD_BASE
111 fi
112
113 if [ ! -f $BUILD_BASE/config ]; then
114     touch $BUILD_BASE/config
115 fi
116
117 export PATH=$PATH:$WORKSPACE/ci:$BUILD_BASE
118 source $BUILD_BASE/config
119
120 cd $BUILD_BASE
121 export TOPDIR=$BUILD_BASE
122
123 # build variables
124
125 export TMP_RELEASE_DIR=$TOPDIR/release
126 export CACHE_DIR=$TOPDIR/cache
127 export TMPDIR=$TOPDIR/scratch
128 export RPMDIR=$TOPDIR/rpmbuild
129
130
131 mkdir -p $RPMDIR/RPMS
132 mkdir -p $RPMDIR/SOURCES
133 mkdir -p $RPMDIR/SPECS
134 mkdir -p $RPMDIR/SRPMS
135
136
137 if [ ! -z $TESTRPM ]; then
138     # Spawn VM to do the testing.
139     if [ ! -z $kernel_version ]; then
140         instack_ovs.sh -a $kernel_major -g $TAG -i $kernel_minor -p $OVS_PATCH -t -u $OVS_REPO_URL
141     else
142         instack_ovs.sh $setbuilddpdk -g $TAG -p $OVS_PATCH -t -u $OVS_REPO_URL
143     fi
144 else
145     # Run build locally.
146     build_ovs_rpm.sh $setbuilddpdk -g $TAG -p $OVS_PATCH -u $OVS_REPO_URL
147     cp $HOME/rpmbuild/RPMS/* $TMP_RELEASE_DIR
148 fi
149
150 exit 0