5 # POC Script to build/install/deploy/orchestrate Tacker on an OPNFV Brhamaputra Fuel cluster
6 # Script assuming it runs on the openstack primary controller (where is opendaylight
7 # present) and there is a fuel master on 10.20.0.2 and can be reached with default
10 # author: Ferenc Cserepkei <ferenc.cserepkei@ericsson.com>
12 # (c) 2016 Telefonaktiebolaget L. M. ERICSSON
14 # All rights reserved. This program and the accompanying materials
15 # are made available under the terms of the Apache License, Version 2.0
16 # which accompanies this distribution, and is available at
17 # http://www.apache.org/licenses/LICENSE-2.0
21 SSH_OPTIONS=(-o StrictHostKeyChecking=no -o GlobalKnownHostsFile=/dev/null -o UserKnownHostsFile=/dev/null -o LogLevel=error)
23 MYDIR=$(dirname $(readlink -f "$0"))
24 MYREPO="tacker-server"
25 CLIREPO="tacker-client"
28 CLIENT="python-python-tackerclient_0.0.1~dev48-1_all.deb"
29 JSONRPC="python-jsonrpclib_0.1.7-1_all.deb"
30 SERVER="python-tacker_2014.2.0~dev176-1_all.deb"
32 # Function checks whether crudini is available, if not - installs
33 function chkCrudini () {
34 if [[ ! -f '/usr/bin/crudini' ]]; then
35 wget -N http://mirrors.kernel.org/ubuntu/pool/universe/p/python-iniparse/python-iniparse_0.4-2.1build1_all.deb
36 wget -N http://archive.ubuntu.com/ubuntu/pool/universe/c/crudini/crudini_0.3-1_amd64.deb
37 dpkg -i python-iniparse_0.4-2.1build1_all.deb crudini_0.3-1_amd64.deb crudini_0.3-1_amd64.deb
41 # Function checks whether a python egg is available, if not, installs
44 IPPACK=$(python - <<'____EOF'
46 from os.path import join
47 for package in pip.get_installed_distributions():
48 print(package.location)
49 print(join(package.location, *package._get_metadata("top_level.txt")))
52 echo "$IPPACK" | grep -q "$PKG"
58 # Function setting up the build/deploy environment
59 function envSetup () {
61 apt-get install -y git python-pip python-all debhelper crudini
66 # Function installs jsonrpclib from github
67 function deployJsonrpclib () {
68 if [[ -e "${MYDIR}/${JSONRPC}" ]]; then
69 echo "$JSONRPC exists."
74 git clone https://github.com/joshmarshall/jsonrpclib.git $DEPREPO
76 dpkg --purge python-jsonrpclib
77 python setup.py --command-packages=stdeb.command bdist_deb
83 # Function builds Tacker server from github
84 function buildTackerServer () {
85 if [[ -e "${MYDIR}/${SERVER}" ]]; then
86 echo "$SERVER exists."
91 git clone -b 'SFC_brahmaputra' https://github.com/trozet/tacker.git $MYREPO
94 diff -ruN a/setup.cfg b/setup.cfg
95 --- a/setup.cfg 2016-02-08 10:54:37.416525934 +0100
96 +++ b/setup.cfg 2016-02-08 10:55:29.293428896 +0100
103 etc/tacker/api-paste.ini
104 etc/tacker/policy.json
105 etc/tacker/tacker.conf
106 etc/tacker/rootwrap.conf
109 etc/tacker/rootwrap.d/servicevm.filters
110 - etc/init.d = etc/init.d/tacker-server
111 + /etc/init.d = etc/init.d/tacker-server
116 dpkg --purge python-tacker
117 python setup.py --command-packages=stdeb.command bdist_deb
120 # Function corrects and installs the Tacker-server debian package
121 function blessPackage () {
122 DEBFILE="${MYDIR}/${MYREPO}/deb_dist/${SERVER}"
123 TMPDIR=$(mktemp -d /tmp/deb.XXXXXX) || exit 1
124 OUTPUT=$(basename "$DEBFILE")
125 if [[ -e "${MYDIR}/${OUTPUT}" ]]; then
126 echo "$OUTPUT exists."
130 dpkg-deb -x "$DEBFILE" "$TMPDIR"
131 dpkg-deb --control "$DEBFILE" "${TMPDIR}/DEBIAN"
134 diff -ruN a/DEBIAN/control b/DEBIAN/control
135 --- a/DEBIAN/control 2016-02-08 10:06:18.000000000 +0000
136 +++ b/DEBIAN/control 2016-02-08 10:45:09.501373675 +0000
139 Maintainer: OpenStack <openstack-dev@lists.openstack.org>
141 -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
142 +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
145 Description: OpenStack servicevm/device manager
148 echo "Patching deb..."
149 dpkg -b "$TMPDIR" "${MYDIR}/${OUTPUT}"
151 dpkg -i "${MYDIR}/${OUTPUT}"
154 # Function deploys Tacker-server (installs missing mandatory files: upstart, default)
155 function deployTackerServer () {
156 rm -rf /etc/default/tacker-server
157 cat > /etc/default/tacker-server <<EOFTD
159 PIDFILE=/var/run/tacker/tacker-server.pid
160 LOGFILE=/var/log/tacker/tacker-server.log
161 PATH="\${PATH:+\$PATH:}/usr/sbin:/sbin"
162 TMPDIR=/var/lib/tacker/tmp
164 rm -rf /etc/init/tacker.conf
165 cat > /etc/init/tacker.conf <<EOFSC
166 # tacker-server - Provides the Tacker servicevm/device manager service
167 description "Openstack Tacker Server"
168 author "Ferenc Cserepkei <ferenc.cserepkei@ericsson.com>"
170 start on runlevel [2345]
171 stop on runlevel [!2345]
175 limit nofile 65535 65535
180 # stop job from continuing if no config file found for daemon
181 [ ! -f /etc/default/tacker-server ] && { stop; exit 0; }
182 [ ! -f /etc/tacker/tacker.conf ] && { stop; exit 0; }
184 # source the config file
185 . /etc/default/tacker-server
187 # stop job from continuing if admin has not enabled service in
189 [ -z "\$ENABLED" ] && { stop; exit 0; }
191 mkdir -p /var/run/tacker
192 mkdir -p /var/log/tacker
193 echo "Starting tacker server"
197 echo "Stopping tacker server"
200 exec /usr/bin/python /usr/bin/tacker-server --log-file=/var/log/tacker/tacker-server.log -v -d --config-file=/etc/tacker/tacker.conf
204 # Function installs python-tackerclient from github
205 function deployTackerClient() {
206 if [[ -e "${MYDIR}/${CLIENT}" ]]; then
207 echo "$CLIENT exists."
212 dpkg --purge python-tackerclient
213 git clone -b 'SFC_refactor' https://github.com/trozet/python-tackerclient.git $CLIREPO
215 # patch -p 1 <<EOFCSC
216 #--- a/setup.cfg 2016-02-09 08:51:48.424937110 +0000
217 #+++ b/setup.cfg 2016-02-09 08:52:17.084938135 +0000
220 #-name = python-tackerclient
221 #+name = tackerclient
222 # summary = CLI and Client Library for OpenStack Networking
226 python setup.py --command-packages=stdeb.command bdist_deb
232 # Function removes the cloned git repositories
233 function remove_repo () {
234 if [[ -d "${MYDIR}/${1}" ]]; then
239 # Funcion copies and installs built artifact on all remaining cluster nodes
240 function populate_client() {
241 wget -O deb http://archive.ubuntu.com/ubuntu/pool/universe/s/sshpass/sshpass_1.05-1_amd64.deb &&\
245 sshpass -p "r00tme" scp ${SSH_OPTIONS[@]} root@10.20.0.2:.ssh/id_rsa ${HOME}/.ssh/id_rsa
246 clusternodes=$(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}" )
247 myaddr=$(ifconfig br-fw-admin | sed -n '/inet addr/s/.*addr.\([^ ]*\) .*/\1/p')
248 for anode in $clusternodes ; do
249 if [ "$anode" != "$myaddr" ] ; then
250 echo "installing $CLIENT on $anode"
251 scp ${SSH_OPTIONS[@]} $CLIENT $anode:$CLIENT
252 ssh ${SSH_OPTIONS[@]} $anode dpkg -i $CLIENT
253 ssh ${SSH_OPTIONS[@]} $anode rm $CLIENT
258 # Function orchestrate the Tacker service
259 function orchestarte () {
260 rm -rf /etc/puppet/modules/tacker
261 pushd /etc/puppet/modules
262 git clone https://github.com/trozet/puppet-tacker.git tacker
263 rm -rf /etc/puppet/modules/tacker/.git
267 auth_uri=$(crudini --get '/etc/heat/heat.conf' 'keystone_authtoken' 'auth_uri')
268 identity_uri=$(crudini --get '/etc/heat/heat.conf' 'keystone_authtoken' 'identity_uri')
269 database_connection="mysql://tacker:tacker@$(hiera database_vip)/tacker"
270 rabbit_host=$(crudini --get '/etc/heat/heat.conf' 'oslo_messaging_rabbit' 'rabbit_hosts'| cut -d ':' -f 1)
271 rabbit_password=$(crudini --get '/etc/heat/heat.conf' 'oslo_messaging_rabbit' 'rabbit_password')
272 sql_host=$(hiera database_vip)
273 admin_url="http://$(hiera management_vip):8888/"
274 public_url="http://$(hiera public_vip):8888/"
275 heat_api_vip=$(crudini --get '/etc/heat/heat.conf' 'heat_api' 'bind_host')
276 mgmt_addr=$(ifconfig br-mgmt | sed -n '/inet addr/s/.*addr.\([^ ]*\) .*/\1/p')
277 allowed_hosts="[ '${HOSTNAME}', 'localhost', '127.0.0.1', '%' ]"
278 heat_uri="http://${heat_api_vip}:8004/v1"
280 service_tenant='services'
284 cat > configure_tacker.pp << EOF
285 class mysql::config {}
286 include mysql::config
287 class mysql::server {}
288 include mysql::server
291 package_ensure => 'absent',
292 client_package_ensure => 'absent',
293 bind_host => '${mgmt_addr}',
294 keystone_password => '${myPassword}',
295 keystone_tenant => '${service_tenant}',
296 auth_uri => '${auth_uri}',
297 identity_uri => '${identity_uri}',
298 database_connection => '${database_connection}',
299 rabbit_host => '${rabbit_host}',
300 rabbit_password => '${rabbit_password}',
301 heat_uri => '${heat_uri}',
302 opendaylight_host => '${mgmt_addr}',
303 opendaylight_port => '${odl_port}',
306 class { 'tacker::db::mysql':
307 password => '${myPassword}',
308 host => '${sql_host}',
309 allowed_hosts => ${allowed_hosts},
312 class { 'tacker::keystone::auth':
313 password => '${myPassword}',
314 tenant => '${service_tenant}',
315 admin_url => '${admin_url}',
316 internal_url => '${admin_url}',
317 public_url => '${public_url}',
318 region => '${myRegion}',
322 puppet apply configure_tacker.pp
324 cat > tackerc <<EOFRC
327 export OS_NO_CACHE='true'
328 export OS_TENANT_NAME='${service_tenant}'
329 export OS_PROJECT_NAME='${service_tenant}''
330 export OS_USERNAME='tacker'
331 export OS_PASSWORD='tacker'
332 export OS_AUTH_URL='${auth_uri}'
333 export OS_DEFAULT_DOMAIN='default'
334 export OS_AUTH_STRATEGY='keystone'
335 export OS_REGION_NAME='RegionOne'
340 # Funcion copies and installs built environment settings on all remaining cluster nodes
341 function populate_rc() {
342 wget -O deb http://archive.ubuntu.com/ubuntu/pool/universe/s/sshpass/sshpass_1.05-1_amd64.deb &&\
346 sshpass -p "r00tme" scp ${SSH_OPTIONS[@]} root@10.20.0.2:.ssh/id_rsa ${HOME}/.ssh/id_rsa
347 clusternodes=$(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}" )
348 myaddr=$(ifconfig br-fw-admin | sed -n '/inet addr/s/.*addr.\([^ ]*\) .*/\1/p')
349 for anode in $clusternodes ; do
350 if [ "$anode" != "$myaddr" ] ; then
351 echo "populating seetings to $anode"
352 scp ${SSH_OPTIONS[@]} tackerc $anode:tackerc
367 remove_repo "$MYREPO"
368 remove_repo "$DEPREPO"
369 remove_repo "$CLIREPO"
371 echo "Built: ${MYDIR}/${OUTPUT}"
372 echo "Built: ${MYDIR}/${CLIENT}"
373 echo "Built: ${MYDIR}/${JSONRPC}"
374 echo "tackerc - mandatory environmental parameters file created"