-
Notifications
You must be signed in to change notification settings - Fork 13
/
functions
173 lines (147 loc) · 5.09 KB
/
functions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
#!/usr/bin/env bash
# Copyright 2014 Midokura SARL
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# functions - Common functions used by MidoStack components
function check_git_branch() {
local git_dir=$1
local expected=$2
cd $git_dir
local cur_branch=$(git branch | grep ^*| awk '{print $2}')
if [ "$cur_branch" != "$expected" ]; then
echo "branch($cur_branch) in $git_dir doesn't match the expected one($expected) specified for midostack. "
echo "Be sure to checkout the right branch for $git_dir."
exit 1
fi
cd - > /dev/null
}
function check_devstack_branch() {
MIDO_DIR=$(pwd)
DEVSTACK_DIR="$MIDO_DIR/devstack"
if [ ! -d $DEVSTACK_DIR ] ; then
return 0
fi
check_git_branch $DEVSTACK_DIR $MIDOSTACK_OPENSTACK_BRANCH
}
function check_openstack_branch() {
if [ ! -d /opt/stack ] ; then
# Devstack should checkout the code of right branch
return 0
fi
# check branch for major openstack components. nova, glance, keystone, neutron
for repo in /opt/stack/{nova,glance,keystone,neutron}; do
if [ -d $repo ] ; then
check_git_branch $repo $MIDOSTACK_OPENSTACK_BRANCH
fi
done
}
function check_midonet_branch() {
if [ ! -d /opt/stack/midonet/midonet ] ; then
# Midostack should checkout the code of right branch
return 0
fi
check_git_branch /opt/stack/midonet/midonet $MIDONET_GIT_BRANCH
}
function pull_devstack() {
MIDO_DIR=$(pwd)
DEVSTACK_DIR="$MIDO_DIR/devstack"
if [ -d $DEVSTACK_DIR ]; then
if [ -d $DEVSTACK_DIR/.git ] ; then
echo pulling devstack...
cd $DEVSTACK_DIR
git pull
git log --oneline -n 5
cd -
else
echo "Failed to pull devstack: $DEVSTACK_DIR is not a git directory"
exit 1
fi
else
# Clone devstack if missing
git clone http://github.com/openstack-dev/devstack devstack -b $MIDOSTACK_OPENSTACK_BRANCH
fi
}
function get_ubuntu_codename() {
lsb_release -c | cut -f 2
}
#
# Midonet build related functions.
# CWD should be the top directory of "midonet" repo
#
function build_midonet() {
if [ -z "$1" ]; then
echo "Midonet src directory not passed in."
exit 1
fi
local midonet_src_dir=$1
# Because some source code has unnicode characters
LC_ALL=en_US.UTF-8
# Use sudo to clean up stuff that previous :midolman:runWithSudo might
# have created and chown .gradle dirs
cd $midonet_src_dir && sudo ./gradlew clean
sudo chown $(whoami) .gradle/ ~/.gradle -R
cd $midonet_src_dir && ./gradlew assemble
if [ $? -gt 0 ]; then
echo "Exiting. MidoNet build failed."
exit 1
fi
LC_ALL=C
}
function install_midonet() {
if [ -z "$1" ]; then
echo "Midonet src directory not passed in."
exit 1
fi
local midonet_src_dir=$1
# install jar to midolman's build dir
cd $midonet_src_dir && ./gradlew :midolman:installApp
# Change MIDO_HOME (used by mm-ctl / mm-dpctl) to point at deps dir
MIDO_HOME=$midonet_src_dir/midodeps
rm -rf $MIDO_HOME ; mkdir -p $MIDO_HOME
# Jars have been created in earlier build step, put them all in one deps dir
MIDOLMAN_BUILD_TARGET_DIR="$midonet_src_dir/midolman/build/install/midolman/lib"
cp $MIDOLMAN_BUILD_TARGET_DIR/midolman-*.jar $MIDO_HOME/midolman.jar
cp $MIDOLMAN_BUILD_TARGET_DIR/midonet-jdk-bootstrap-*.jar $MIDO_HOME/midonet-jdk-bootstrap.jar
cp -r $MIDOLMAN_BUILD_TARGET_DIR $MIDO_HOME/dep
# Place our executables in /usr/local/bin
LOCAL_BIN_DIR=/usr/local/bin
sudo cp $MIDO_DIR/scripts/binproxy $LOCAL_BIN_DIR/mm-ctl
sudo cp $MIDO_DIR/scripts/binproxy $LOCAL_BIN_DIR/mm-dpctl
sudo chmod +x $LOCAL_BIN_DIR/mm-ctl $LOCAL_BIN_DIR/mm-dpctl
# Create the midolman's conf dir in case it doesn't exist
# Midolman will fail to run otherwise
if [ ! -d $MIDOLMAN_CONF_DIR ]; then
sudo mkdir -p $MIDOLMAN_CONF_DIR
fi
# These config files are needed - create if not present
if [ ! -f $MIDOLMAN_CONF_DIR/logback-dpctl.xml ]; then
sudo cp $midonet_src_dir/midolman/conf/logback-dpctl.xml $MIDOLMAN_CONF_DIR/
fi
if [ ! -f $MIDOLMAN_CONF_DIR/midolman.conf ]; then
sudo cp $midonet_src_dir/midolman/conf/midolman.conf $MIDOLMAN_CONF_DIR/
fi
}
function is_icehouse {
if [ "$MIDOSTACK_OPENSTACK_BRANCH" == "stable/icehouse" ] ; then
return 0
else
return 1
fi
}
function is_juno {
if [ "$MIDOSTACK_OPENSTACK_BRANCH" == "stable/juno" ] ; then
return 0
else
return 1
fi
}