-
Notifications
You must be signed in to change notification settings - Fork 11
/
generate-citrix-job.sh
executable file
·185 lines (155 loc) · 5.58 KB
/
generate-citrix-job.sh
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
174
175
176
177
178
179
180
181
182
183
184
185
#!/bin/bash
set -eu
function print_usage_and_die
{
cat >&2 << EOF
usage: $0 BRANCH_REF_NAME [-t SETUP_TYPE] [-u UBUNTU_DISTRO] [-m UBUNTU_INST_HTTP_HOSTNAME] [-n UBUNTU_INST_HTTP_DIRECTORY] [-x]
Generate a test script to the standard output
positional arguments:
BRANCH_REF_NAME Name of the ref/branch to be used.
SETUP_TYPE Type of setup, one of [nova-network, neutron] defaults to
nova-network.
UBUNTU_DISTRO The ubuntu distribution to use [precise, saucy, trusty]
defaults to not specifying, so use whatever is defined in
localrc/xenrc.
UBUNTU_INST_HTTP_HOSTNAME
Specify an ubuntu mirror to be used. Using the one specified
by .xenrc if not specified.
UBUNTU_INST_HTTP_DIRECTORY
Specify directory within ubuntu mirror to be used.
flags:
-x Create an externally usable script. If this flag is set, then
ubuntu repositories will not be overriden, and github will be
used.
An example run:
$0 build-1373962961
$@
EOF
exit 1
}
THIS_DIR=$(cd $(dirname "$0") && pwd)
. $THIS_DIR/lib/functions
TEMPLATE_NAME="$THIS_DIR/install-devstack-xen.sh"
INTERNAL_REPO_BASE="gold.eng.hq.xensource.com/git/internal/builds"
EXTERNAL_REPO_BASE="github.com/citrix-openstack-build"
BUILD_REFS="https://github.com/citrix-openstack-build/build-refs"
# Defaults for options
SETUP_TYPE="nova-network"
UBUNTU_DISTRO=""
INTERNAL="true"
REPO_BASE="$INTERNAL_REPO_BASE"
UBUNTU_INST_HTTP_HOSTNAME=""
UBUNTU_INST_HTTP_DIRECTORY=""
# Get positional arguments
set +u
BRANCH_REF_NAME="$1"
shift || print_usage_and_die "ERROR: Please specify a branch name"
set -u
BRANCH_REF_BASENAME=$(basename $BRANCH_REF_NAME)
# Number of options passed to this script
REMAINING_OPTIONS="$#"
# Get optional parameters
set +e
while getopts ":t:u:m:xn:" flag; do
REMAINING_OPTIONS=$(expr "$REMAINING_OPTIONS" - 1)
case "$flag" in
t)
SETUP_TYPE="$OPTARG"
if ! [ "$SETUP_TYPE" = "nova-network" -o "$SETUP_TYPE" = "neutron" ]; then
print_usage_and_die "ERROR: invalid value for SETUP_TYPE: $SETUP_TYPE"
fi
REMAINING_OPTIONS=$(expr "$REMAINING_OPTIONS" - 1)
;;
u)
UBUNTU_DISTRO="$OPTARG"
if ! [ "$UBUNTU_DISTRO" = "precise" -o "$UBUNTU_DISTRO" = "saucy" -o "$UBUNTU_DISTRO" = "trusty" ]; then
print_usage_and_die "ERROR: invalid value for UBUNTU_DISTRO: $UBUNTU_DISTRO"
fi
REMAINING_OPTIONS=$(expr "$REMAINING_OPTIONS" - 1)
;;
m)
UBUNTU_INST_HTTP_HOSTNAME="$OPTARG"
REMAINING_OPTIONS=$(expr "$REMAINING_OPTIONS" - 1)
;;
n)
UBUNTU_INST_HTTP_DIRECTORY="$OPTARG"
REMAINING_OPTIONS=$(expr "$REMAINING_OPTIONS" - 1)
;;
x)
INTERNAL="false"
REPO_BASE="$EXTERNAL_REPO_BASE"
;;
\?)
print_usage_and_die "Invalid option -$OPTARG"
;;
esac
done
set -e
# Make sure that all options processed
if [ "0" != "$REMAINING_OPTIONS" ]; then
print_usage_and_die "ERROR: some arguments were not recognised!"
fi
EXTENSION_POINT="^# Additional Localrc parameters here$"
EXTENSIONS=$(mktemp)
EXTENSION_LOCALCONF_POINT="^# Additional localconf parameters here$"
EXTENSIONS_LOCALCONF=$(mktemp)
# Set ubuntu install proxy for intenal script
if [ "true" = "$INTERNAL" ]; then
cat "$THIS_DIR/modifications/add-ubuntu-proxy-repos" >> $EXTENSIONS
fi
# Set custom repos
{
repo_url=${BUILD_REFS}/raw/master/${BRANCH_REF_BASENAME}
if curl -L --fail $repo_url 2>/dev/null; then
# The contents will have already been output to stdout from the curl command above
:
else
static_repos | while read repo_record; do
echo "$(var_name "$repo_record")=$(dst_repo "$repo_record")"
echo "$(branch_name "$repo_record")=$BRANCH_REF_NAME"
done
fi
cat << EOF
NOVA_ZIPBALL_URL="http://$REPO_BASE/nova/archive/$BRANCH_REF_NAME.zip"
NEUTRON_ZIPBALL_URL="http://$REPO_BASE/neutron/archive/$BRANCH_REF_NAME.zip"
EOF
} | sed -e "s,$INTERNAL_REPO_BASE,$REPO_BASE,g" >> "$EXTENSIONS"
function testing_trunk() {
echo "$BRANCH_REF_NAME" | grep -q "os-trunk-test"
}
function neutron_setup() {
[ "$SETUP_TYPE" = "neutron" ]
}
# Set FLAT_NETWORK_BRIDGE, but only if we are not testing trunk
if ! testing_trunk && ! neutron_setup ; then
echo "FLAT_NETWORK_BRIDGE=osvmnet" >> $EXTENSIONS
fi
# Configure neutron if needed
if [ "$SETUP_TYPE" == "neutron" ]; then
cat "$THIS_DIR/modifications/use-neutron" >> $EXTENSIONS
cat "$THIS_DIR/modifications/use-neutron-localconf" >> $EXTENSIONS_LOCALCONF
fi
# Configure VLAN Manager if needed
if [ "$SETUP_TYPE" == "nova-vlan" ]; then
cat "$THIS_DIR/modifications/use-vlan" >> $EXTENSIONS
fi
# Configure distribution
if [ -n "$UBUNTU_DISTRO" ]; then
echo "UBUNTU_INST_RELEASE=$UBUNTU_DISTRO" >> $EXTENSIONS
echo "UBUNTU_INST_TEMPLATE_NAME=devstack_$UBUNTU_DISTRO" >> $EXTENSIONS
fi
# Configure mirror
if [ -n "$UBUNTU_INST_HTTP_HOSTNAME" ]; then
echo "UBUNTU_INST_HTTP_HOSTNAME=$UBUNTU_INST_HTTP_HOSTNAME" >> $EXTENSIONS
fi
if [ -n "$UBUNTU_INST_HTTP_DIRECTORY" ]; then
echo "UBUNTU_INST_HTTP_DIRECTORY=$UBUNTU_INST_HTTP_DIRECTORY" >> $EXTENSIONS
fi
# Extend template
sed \
-e "/$EXTENSION_POINT/r $EXTENSIONS" \
-e "/$EXTENSION_LOCALCONF_POINT/r $EXTENSIONS_LOCALCONF" \
-e "s,^\(DEVSTACK_SRC=\).*,\1http://$REPO_BASE/devstack/archive/$BRANCH_REF_NAME.tar.gz,g" \
"$TEMPLATE_NAME"
rm -f "$EXTENSIONS"
rm -f "$EXTENSIONS_LOCALCONF"