4 # POC Script to build/install/deploy/orchestrate Tacker on an OPNFV Brhamaputra Fuel cluster
5 # Script assuming it runs on the openstack primary controller (where is opendaylight
6 # present) and there is a fuel master on 10.20.0.2 and can be reached with default
9 # author: Ferenc Cserepkei <ferenc.cserepkei@ericsson.com>
11 # (c) 2016 Telefonaktiebolaget L. M. ERICSSON
13 # All rights reserved. This program and the accompanying materials are made available
14 # under the terms of the Apache License, Version 2.0 which accompanies this distribution,
15 # and is available at http://www.apache.org/licenses/LICENSE-2.0
19 SSH_OPTIONS=(-o StrictHostKeyChecking=no -o GlobalKnownHostsFile=/dev/null -o UserKnownHostsFile=/dev/null -o LogLevel=error)
21 MYDIR=$(dirname $(readlink -f "$0"))
22 MYREPO="tacker-server"
23 CLIREPO="tacker-client"
26 CLIENT=$(echo python-python-tackerclient_*_all.deb)
27 JSONRPC=$(echo python-jsonrpclib_*_all.deb)
28 SERVER=$(echo python-tacker_*_all.deb)
30 # Function checks whether crudini is available, if not - installs
31 function chkCrudini () {
32 if [[ ! -f '/usr/bin/crudini' ]]; then
33 wget -N http://mirrors.kernel.org/ubuntu/pool/universe/p/python-iniparse/python-iniparse_0.4-2.1build1_all.deb
34 wget -N http://archive.ubuntu.com/ubuntu/pool/universe/c/crudini/crudini_0.3-1_amd64.deb
35 dpkg -i python-iniparse_0.4-2.1build1_all.deb crudini_0.3-1_amd64.deb
39 # Function checks whether a python egg is available, if not, installs
42 IPPACK=$(python - <<'____EOF'
44 from os.path import join
45 for package in pip.get_installed_distributions():
46 print(package.location)
47 print(join(package.location, *package._get_metadata("top_level.txt")))
50 echo "$IPPACK" | grep -q "$PKG"
56 # Function setting up the build/deploy environment
57 function envSetup () {
59 apt-get install -y git python-pip python-all debhelper
64 # Function installs jsonrpclib from github
65 function deployJsonrpclib () {
66 if [[ -e "${MYDIR}/${JSONRPC}" ]]; then
67 echo "$JSONRPC exists."
72 git clone https://github.com/joshmarshall/jsonrpclib.git $DEPREPO
74 dpkg --purge python-jsonrpclib
75 python setup.py --command-packages=stdeb.command bdist_deb
77 JSONRPC=$(echo python-jsonrpclib_*_all.deb)
82 # Function builds Tacker server from github
83 function buildTackerServer () {
84 if [[ -e "${MYDIR}/${SERVER}" ]]; then
85 echo "$SERVER exists."
90 git clone -b 'SFC_brahmaputra' https://github.com/trozet/tacker.git $MYREPO
93 diff -ruN a/setup.cfg b/setup.cfg
94 --- a/setup.cfg 2016-02-08 10:54:37.416525934 +0100
95 +++ b/setup.cfg 2016-02-08 10:55:29.293428896 +0100
102 etc/tacker/api-paste.ini
103 etc/tacker/policy.json
104 etc/tacker/tacker.conf
105 etc/tacker/rootwrap.conf
108 etc/tacker/rootwrap.d/servicevm.filters
109 - etc/init.d = etc/init.d/tacker-server
110 + /etc/init.d = etc/init.d/tacker-server
115 dpkg --purge python-tacker
116 python setup.py --command-packages=stdeb.command bdist_deb
119 # Function corrects and installs the Tacker-server debian package
120 function blessPackage () {
121 pushd "${MYDIR}/${MYREPO}/deb_dist"
122 SERVER=$(echo python-tacker_*_all.deb)
124 DEBFILE="${MYDIR}/${MYREPO}/deb_dist/${SERVER}"
125 TMPDIR=$(mktemp -d /tmp/deb.XXXXXX) || exit 1
126 OUTPUT=$(basename "$DEBFILE")
127 if [[ -e "${MYDIR}/${OUTPUT}" ]]; then
128 echo "$OUTPUT exists."
132 dpkg-deb -x "$DEBFILE" "$TMPDIR"
133 dpkg-deb --control "$DEBFILE" "${TMPDIR}/DEBIAN"
136 diff -ruN a/DEBIAN/control b/DEBIAN/control
137 --- a/DEBIAN/control 2016-02-08 10:06:18.000000000 +0000
138 +++ b/DEBIAN/control 2016-02-08 10:45:09.501373675 +0000
141 Maintainer: OpenStack <openstack-dev@lists.openstack.org>
143 -Depends: python (>= 2.7), python (<< 2.8), python:any (>= 2.7.1-0ubuntu2), python-pbr, python-paste, python-pastedeploy, python-routes, python-anyjson, python-babel, python-eventlet, python-greenlet, python-httplib2, python-requests, python-iso8601, python-jsonrpclib, python-jinja2, python-kombu, python-netaddr, python-sqlalchemy (>= 1.0~), python-sqlalchemy (<< 1.1), python-webob, python-heatclient, python-keystoneclient, alembic, python-six, python-stevedore, python-oslo.config, python-oslo.messaging-, python-oslo.rootwrap, python-novaclient
144 +Depends: python (>= 2.7), python (<< 2.8), python:any (>= 2.7.1-0ubuntu2), python-pbr, python-paste, python-pastedeploy, python-routes, python-anyjson, python-babel, python-eventlet, python-greenlet, python-httplib2, python-requests, python-iso8601, python-jsonrpclib, python-jinja2, python-kombu, python-netaddr, python-sqlalchemy (>= 1.0~), python-sqlalchemy (<< 1.1), python-webob, python-heatclient, python-keystoneclient, alembic, python-six, python-stevedore, python-oslo.config, python-oslo.messaging, python-oslo.rootwrap, python-novaclient
147 Description: OpenStack servicevm/device manager
150 echo "Patching deb..."
151 dpkg -b "$TMPDIR" "${MYDIR}/${SERVER}"
153 dpkg -i "${MYDIR}/${SERVER}"
156 # Function deploys Tacker-server (installs missing mandatory files: upstart, default)
157 function deployTackerServer () {
158 rm -rf /etc/default/tacker-server
159 cat > /etc/default/tacker-server <<EOFTD
161 PIDFILE=/var/run/tacker/tacker-server.pid
162 LOGFILE=/var/log/tacker/tacker-server.log
163 PATH="\${PATH:+\$PATH:}/usr/sbin:/sbin"
164 TMPDIR=/var/lib/tacker/tmp
166 rm -rf /etc/init/tacker.conf
167 cat > /etc/init/tacker.conf <<EOFSC
168 # tacker-server - Provides the Tacker servicevm/device manager service
169 description "Openstack Tacker Server"
170 author "Ferenc Cserepkei <ferenc.cserepkei@ericsson.com>"
172 start on runlevel [2345]
173 stop on runlevel [!2345]
177 limit nofile 65535 65535
182 # stop job from continuing if no config file found for daemon
183 [ ! -f /etc/default/tacker-server ] && { stop; exit 0; }
184 [ ! -f /etc/tacker/tacker.conf ] && { stop; exit 0; }
186 # source the config file
187 . /etc/default/tacker-server
189 # stop job from continuing if admin has not enabled service in
191 [ -z "\$ENABLED" ] && { stop; exit 0; }
193 mkdir -p /var/run/tacker
194 mkdir -p /var/log/tacker
195 echo "Starting tacker server"
199 echo "Stopping tacker server"
202 exec /usr/bin/python /usr/bin/tacker-server --log-file=/var/log/tacker/tacker-server.log -v -d --config-file=/etc/tacker/tacker.conf
206 # Function installs python-tackerclient from github
207 function deployTackerClient() {
208 if [[ -e "${MYDIR}/${CLIENT}" ]]; then
209 echo "$CLIENT exists."
214 dpkg --purge python-tackerclient
215 git clone -b 'SFC_refactor' https://github.com/trozet/python-tackerclient.git $CLIREPO
217 python setup.py --command-packages=stdeb.command bdist_deb
219 CLIENT=$(echo python-python-tackerclient_*_all.deb)
221 dpkg -i "${MYDIR}/${CLIENT}"
224 # Function removes the cloned git repositories
225 function remove_repo () {
226 if [[ -d "${MYDIR}/${1}" ]]; then
231 # Funcion copies and installs built artifact on all remaining cluster nodes
232 function populate_client() {
233 wget -O deb http://archive.ubuntu.com/ubuntu/pool/universe/s/sshpass/sshpass_1.05-1_amd64.deb &&\
237 clusternodes=$(sshpass -p "r00tme" ssh ${SSH_OPTIONS[@]} root@10.20.0.2 fuel node | cut -d '|' -f 5 | grep -E -o "([0-9]{1,3}[\.]){3}[0-9]{1,3}" )
238 myaddr=$(ifconfig br-fw-admin | sed -n '/inet addr/s/.*addr.\([^ ]*\) .*/\1/p')
239 for anode in $clusternodes ; do
240 if [ "$anode" != "$myaddr" ] ; then
241 echo "Installing $CLIENT on $anode"
242 scp ${SSH_OPTIONS[@]} $CLIENT $anode:$CLIENT
243 ssh ${SSH_OPTIONS[@]} $anode dpkg -i $CLIENT
244 ssh ${SSH_OPTIONS[@]} $anode rm $CLIENT
249 # Function orchestrate the Tacker service
250 function orchestarte () {
251 rm -rf /etc/puppet/modules/tacker
252 pushd /etc/puppet/modules
253 git clone https://github.com/trozet/puppet-tacker.git tacker
254 rm -rf /etc/puppet/modules/tacker/.git
259 # Port(s) Protocol ServiceDetails Source
260 # 8805-8872 tcp,udp Unassigned IANA
263 auth_uri=$(crudini --get '/etc/heat/heat.conf' 'keystone_authtoken' 'auth_uri')
264 identity_uri=$(crudini --get '/etc/heat/heat.conf' 'keystone_authtoken' 'identity_uri')
265 mgmt_addr=$(ifconfig br-mgmt | sed -n '/inet addr/s/.*addr.\([^ ]*\) .*/\1/p')
266 pub_addr=$(ifconfig br-ex-lnx | sed -n '/inet addr/s/.*addr.\([^ ]*\) .*/\1/p')
267 rabbit_host=$(crudini --get '/etc/heat/heat.conf' 'oslo_messaging_rabbit' 'rabbit_hosts'| cut -d ':' -f 1)
268 rabbit_password=$(crudini --get '/etc/heat/heat.conf' 'oslo_messaging_rabbit' 'rabbit_password')
269 sql_host=$(hiera database_vip)
270 database_connection="mysql://tacker:tacker@${sql_host}/tacker"
271 admin_url="http://${mgmt_addr}:${bind_port}"
272 public_url="http://${pub_addr}:${bind_port}"
273 heat_api_vip=$(crudini --get '/etc/heat/heat.conf' 'heat_api' 'bind_host')
274 allowed_hosts="[ '${sql_host}', '${HOSTNAME%%.domain.tld}', 'localhost', '127.0.0.1', '%' ]"
275 heat_uri="http://${heat_api_vip}:8004/v1"
277 service_tenant='services'
281 cat > configure_tacker.pp << EOF
282 class mysql::config {}
283 include mysql::config
284 class mysql::server {}
285 include mysql::server
288 package_ensure => 'absent',
289 client_package_ensure => 'absent',
290 bind_port => '${bind_port}',
291 keystone_password => '${myPassword}',
292 keystone_tenant => '${service_tenant}',
293 auth_uri => '${auth_uri}',
294 identity_uri => '${identity_uri}',
295 database_connection => '${database_connection}',
296 rabbit_host => '${rabbit_host}',
297 rabbit_password => '${rabbit_password}',
298 heat_uri => '${heat_uri}',
299 opendaylight_host => '${mgmt_addr}',
300 opendaylight_port => '${odl_port}',
303 class { 'tacker::db::mysql':
304 password => '${myPassword}',
305 allowed_hosts => ${allowed_hosts},
308 class { 'tacker::keystone::auth':
309 password => '${myPassword}',
310 tenant => '${service_tenant}',
311 admin_url => '${admin_url}',
312 internal_url => '${admin_url}',
313 public_url => '${public_url}',
314 region => '${myRegion}',
318 puppet apply configure_tacker.pp
320 cat > tackerc <<EOFRC
323 export OS_NO_CACHE='true'
324 export OS_TENANT_NAME='${service_tenant}'
325 export OS_PROJECT_NAME='${service_tenant}'
326 export OS_USERNAME='tacker'
327 export OS_PASSWORD='${myPassword}'
328 export OS_AUTH_URL='${auth_uri}'
329 export OS_DEFAULT_DOMAIN='default'
330 export OS_AUTH_STRATEGY='keystone'
331 export OS_REGION_NAME='${myRegion}'
332 export TACKER_ENDPOINT_TYPE='internalURL'
337 # Funcion copies and installs built environment settings on all remaining cluster nodes
338 function populate_rc() {
339 wget -O deb http://archive.ubuntu.com/ubuntu/pool/universe/s/sshpass/sshpass_1.05-1_amd64.deb &&\
343 clusternodes=$(sshpass -p "r00tme" ssh ${SSH_OPTIONS[@]} root@10.20.0.2 fuel node | cut -d '|' -f 5 | grep -E -o "([0-9]{1,3}[\.]){3}[0-9]{1,3}" )
344 myaddr=$(ifconfig br-fw-admin | sed -n '/inet addr/s/.*addr.\([^ ]*\) .*/\1/p')
345 for anode in $clusternodes ; do
346 if [ "$anode" != "$myaddr" ] ; then
347 echo "Populating seetings to $anode"
348 scp ${SSH_OPTIONS[@]} tackerc $anode:tackerc
363 remove_repo "$MYREPO"
364 remove_repo "$DEPREPO"
365 remove_repo "$CLIREPO"
367 echo "Built: ${MYDIR}/${OUTPUT}"
368 echo "Built: ${MYDIR}/${CLIENT}"
369 echo "Built: ${MYDIR}/${JSONRPC}"
370 echo "tackerc - mandatory environmental parameters file created"