Introduce ability to accept command arguments to build with DPDK or Linux kernel.
[ovsnfv.git] / build / BuildAndTestOVS.sh
1 #!/bin/bash
2 ##############################################################################
3 # Copyright (c) 2016 Red Hat Inc. and others.
4 # therbert@redhat.com
5 # All rights reserved. This program and the accompanying materials
6 # are made available under the terms of the Apache License, Version 2.0
7 # which accompanies this distribution, and is available at
8 # http://www.apache.org/licenses/LICENSE-2.0
9 ##############################################################################
10 set -e
11
12 echo "==============================="
13 echo executing $0 $@
14
15 usage() {
16     echo "$0 -a <kernel major> -d -g <OVS TAG> -h\
17              -i <kernel minor> -p <patch url> -t -u <OVS URL> -v <verbose\
18     -a <kernel major> -- Specify major release if special kernel is required\
19     The default kernel is Centos 7.2 kernel after upgrade.\
20     -d <dpdk>         -- Specify dpdk build.\
21                     The default is to build ovs for linux kernel data path.\
22     -g <OVS TAG>      -- OVS release tag or branch to build such as 2.4.\
23                     The default is master.\
24     -h print this message\
25     -i <kernel minor> -- Specify minor release if special kernel is required.\
26                     The default kernel is Centos 7.2 kernel after upgrade.\
27     -p <patch url>    -- Specify url to patches if required for ovs rpm.\
28     -t                -- Test rpm.\
29     -u <OVS URL>      -- path to OVS repo if using fork for patch.\
30                     The default is https://github.com/openvswitch/ovs.git\
31     -v                -- Set verbose mode."
32 }
33
34 while getopts "a:dg:hi:p:tu:v" opt; do
35     case "$opt" in
36         a)
37             kernel_major=${OPTARG}
38             ;;
39         d)
40             DPDK="yes"
41             ;;
42         g)
43             TAG=${OPTARG}
44             ;;
45         h)
46             usage
47             exit 1
48             ;;
49         i)
50             kernel_minor=${OPTARG}
51             ;;
52         p)
53             OVS_PATCH=${OPTARG}
54             ;;
55         t)
56             TESTRPM="yes"
57             ;;
58         u)
59             OVS_REPO_URL=${OPTARG}
60             ;;
61         v)
62             verbose="yes"
63             ;;
64     esac
65 done
66
67 if [ -z $TAG ]; then
68     TAG=master
69 fi
70
71 if [ -z $OVS_REPO_URL ]; then
72     OVS_REPO_URL=https://github.com/openvswitch/ovs.git
73 fi
74
75 if [ ! -z $kernel_major ] && [ ! -z $kernel_minor ]; then
76     kernel_version=$kernel_major.$kernel_minor
77     echo ===================
78     echo Will install kernel version: major is $kernel_major and minor is $kernel_minor
79     echo ===================
80 else
81     echo Will use default kernel in ovs test vm
82 fi
83
84 if [ -z ${WORKSPACE+1} ]; then
85     # We are not being run by Jenkins.
86     export WORKSPACE=$HOME/opnfv/ovsnfv
87     mkdir -p opnfv
88     cd opnfv
89     git clone https://git.opnfv.org/ovsnfv
90 fi
91
92 export BUILD_BASE=$WORKSPACE/build
93
94
95
96 if [ ! -d $BUILD_BASE ]
97 then
98     mkdir -p $BUILD_BASE
99 fi
100
101 if [ ! -f $BUILD_BASE/config ]; then
102     touch $BUILD_BASE/config
103 fi
104
105 export PATH=$PATH:$WORKSPACE/ci:$BUILD_BASE
106 source $BUILD_BASE/config
107
108 cd $BUILD_BASE
109 export TOPDIR=$BUILD_BASE
110
111 # build variables
112
113 export TMP_RELEASE_DIR=$TOPDIR/release
114 export CACHE_DIR=$TOPDIR/cache
115 export TMPDIR=$TOPDIR/scratch
116 export RPMDIR=$TOPDIR/rpmbuild
117
118
119 mkdir -p $RPMDIR/RPMS
120 mkdir -p $RPMDIR/SOURCES
121 mkdir -p $RPMDIR/SPECS
122 mkdir -p $RPMDIR/SRPMS
123
124
125 if [ ! -z $TESTRPM ]; then
126     # Spawn VM to do the testing.
127     if [ ! -z $kernel_version ]; then
128         instack_ovs.sh -a $kernel_major -g $TAG -i $kernel_minor -p $OVS_PATCH -t -u $OVS_REPO_URL
129     else
130         instack_ovs.sh -g $TAG -p $OVS_PATCH -t -u $OVS_REPO_URL
131     fi
132 else
133     # Run build locally.
134     build_ovs_rpm.sh -d -g -p $OVS_PATCH -u $OVS_REPO_URL
135     cp $HOME/rpmbuild/RPMS/* $TMP_RELEASE_DIR
136 fi
137
138 echo "--------------------------------------------------"
139 echo "Build OVS RPM from upstream git $OVS_REPO_URL version $TAG"
140 if [ ! -z $OVS_PATCH ]; then
141     echo "Apply patches from: $OVS_PATCH"
142 fi
143 echo
144
145 exit 0