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="python-python-tackerclient_0.0.1~dev48-1_all.deb"
27 JSONRPC="python-jsonrpclib_0.1.7-1_all.deb"
28 SERVER="python-tacker_2014.2.0~dev177-1_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
81 # Function builds Tacker server from github
82 function buildTackerServer () {
83 if [[ -e "${MYDIR}/${SERVER}" ]]; then
84 echo "$SERVER exists."
89 git clone -b 'SFC_brahmaputra' https://github.com/trozet/tacker.git $MYREPO
92 diff -ruN a/setup.cfg b/setup.cfg
93 --- a/setup.cfg 2016-02-08 10:54:37.416525934 +0100
94 +++ b/setup.cfg 2016-02-08 10:55:29.293428896 +0100
101 etc/tacker/api-paste.ini
102 etc/tacker/policy.json
103 etc/tacker/tacker.conf
104 etc/tacker/rootwrap.conf
107 etc/tacker/rootwrap.d/servicevm.filters
108 - etc/init.d = etc/init.d/tacker-server
109 + /etc/init.d = etc/init.d/tacker-server
114 dpkg --purge python-tacker
115 python setup.py --command-packages=stdeb.command bdist_deb
118 # Function corrects and installs the Tacker-server debian package
119 function blessPackage () {
120 DEBFILE="${MYDIR}/${MYREPO}/deb_dist/${SERVER}"
121 TMPDIR=$(mktemp -d /tmp/deb.XXXXXX) || exit 1
122 OUTPUT=$(basename "$DEBFILE")
123 if [[ -e "${MYDIR}/${OUTPUT}" ]]; then
124 echo "$OUTPUT exists."
128 dpkg-deb -x "$DEBFILE" "$TMPDIR"
129 dpkg-deb --control "$DEBFILE" "${TMPDIR}/DEBIAN"
132 diff -ruN a/DEBIAN/control b/DEBIAN/control
133 --- a/DEBIAN/control 2016-02-08 10:06:18.000000000 +0000
134 +++ b/DEBIAN/control 2016-02-08 10:45:09.501373675 +0000
137 Maintainer: OpenStack <openstack-dev@lists.openstack.org>
139 -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
140 +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
143 Description: OpenStack servicevm/device manager
146 echo "Patching deb..."
147 dpkg -b "$TMPDIR" "${MYDIR}/${OUTPUT}"
149 dpkg -i "${MYDIR}/${OUTPUT}"
152 # Function deploys Tacker-server (installs missing mandatory files: upstart, default)
153 function deployTackerServer () {
154 rm -rf /etc/default/tacker-server
155 cat > /etc/default/tacker-server <<EOFTD
157 PIDFILE=/var/run/tacker/tacker-server.pid
158 LOGFILE=/var/log/tacker/tacker-server.log
159 PATH="\${PATH:+\$PATH:}/usr/sbin:/sbin"
160 TMPDIR=/var/lib/tacker/tmp
162 rm -rf /etc/init/tacker.conf
163 cat > /etc/init/tacker.conf <<EOFSC
164 # tacker-server - Provides the Tacker servicevm/device manager service
165 description "Openstack Tacker Server"
166 author "Ferenc Cserepkei <ferenc.cserepkei@ericsson.com>"
168 start on runlevel [2345]
169 stop on runlevel [!2345]
173 limit nofile 65535 65535
178 # stop job from continuing if no config file found for daemon
179 [ ! -f /etc/default/tacker-server ] && { stop; exit 0; }
180 [ ! -f /etc/tacker/tacker.conf ] && { stop; exit 0; }
182 # source the config file
183 . /etc/default/tacker-server
185 # stop job from continuing if admin has not enabled service in
187 [ -z "\$ENABLED" ] && { stop; exit 0; }
189 mkdir -p /var/run/tacker
190 mkdir -p /var/log/tacker
191 echo "Starting tacker server"
195 echo "Stopping tacker server"
198 exec /usr/bin/python /usr/bin/tacker-server --log-file=/var/log/tacker/tacker-server.log -v -d --config-file=/etc/tacker/tacker.conf
202 # Function installs python-tackerclient from github
203 function deployTackerClient() {
204 if [[ -e "${MYDIR}/${CLIENT}" ]]; then
205 echo "$CLIENT exists."
210 dpkg --purge python-tackerclient
211 git clone -b 'SFC_refactor' https://github.com/trozet/python-tackerclient.git $CLIREPO
213 python setup.py --command-packages=stdeb.command bdist_deb
219 # Function removes the cloned git repositories
220 function remove_repo () {
221 if [[ -d "${MYDIR}/${1}" ]]; then
226 # Funcion copies and installs built artifact on all remaining cluster nodes
227 function populate_client() {
228 wget -O deb http://archive.ubuntu.com/ubuntu/pool/universe/s/sshpass/sshpass_1.05-1_amd64.deb &&\
232 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}" )
233 myaddr=$(ifconfig br-fw-admin | sed -n '/inet addr/s/.*addr.\([^ ]*\) .*/\1/p')
234 for anode in $clusternodes ; do
235 if [ "$anode" != "$myaddr" ] ; then
236 echo "Installing $CLIENT on $anode"
237 scp ${SSH_OPTIONS[@]} $CLIENT $anode:$CLIENT
238 ssh ${SSH_OPTIONS[@]} $anode dpkg -i $CLIENT
239 ssh ${SSH_OPTIONS[@]} $anode rm $CLIENT
244 # Function orchestrate the Tacker service
245 function orchestarte () {
246 rm -rf /etc/puppet/modules/tacker
247 pushd /etc/puppet/modules
248 git clone https://github.com/trozet/puppet-tacker.git tacker
249 rm -rf /etc/puppet/modules/tacker/.git
254 # Port(s) Protocol ServiceDetails Source
255 # 8805-8872 tcp,udp Unassigned IANA
258 auth_uri=$(crudini --get '/etc/heat/heat.conf' 'keystone_authtoken' 'auth_uri')
259 identity_uri=$(crudini --get '/etc/heat/heat.conf' 'keystone_authtoken' 'identity_uri')
260 mgmt_addr=$(ifconfig br-mgmt | sed -n '/inet addr/s/.*addr.\([^ ]*\) .*/\1/p')
261 pub_addr=$(ifconfig br-ex-lnx | sed -n '/inet addr/s/.*addr.\([^ ]*\) .*/\1/p')
262 rabbit_host=$(crudini --get '/etc/heat/heat.conf' 'oslo_messaging_rabbit' 'rabbit_hosts'| cut -d ':' -f 1)
263 rabbit_password=$(crudini --get '/etc/heat/heat.conf' 'oslo_messaging_rabbit' 'rabbit_password')
264 sql_host=$(hiera database_vip)
265 database_connection="mysql://tacker:tacker@${sql_host}/tacker"
266 admin_url="http://${mgmt_addr}:${bind_port}"
267 public_url="http://${pub_addr}:${bind_port}"
268 heat_api_vip=$(crudini --get '/etc/heat/heat.conf' 'heat_api' 'bind_host')
269 allowed_hosts="[ '${sql_host}', '${HOSTNAME%%.domain.tld}', 'localhost', '127.0.0.1', '%' ]"
270 heat_uri="http://${heat_api_vip}:8004/v1"
272 service_tenant='services'
276 cat > configure_tacker.pp << EOF
277 class mysql::config {}
278 include mysql::config
279 class mysql::server {}
280 include mysql::server
283 package_ensure => 'absent',
284 client_package_ensure => 'absent',
285 bind_port => '${bind_port}',
286 keystone_password => '${myPassword}',
287 keystone_tenant => '${service_tenant}',
288 auth_uri => '${auth_uri}',
289 identity_uri => '${identity_uri}',
290 database_connection => '${database_connection}',
291 rabbit_host => '${rabbit_host}',
292 rabbit_password => '${rabbit_password}',
293 heat_uri => '${heat_uri}',
294 opendaylight_host => '${mgmt_addr}',
295 opendaylight_port => '${odl_port}',
298 class { 'tacker::db::mysql':
299 password => '${myPassword}',
304 collate => 'utf8_general_ci',
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='tacker'
328 export OS_AUTH_URL='${auth_uri}'
329 export OS_DEFAULT_DOMAIN='default'
330 export OS_AUTH_STRATEGY='keystone'
331 export OS_REGION_NAME='RegionOne'
336 # Funcion copies and installs built environment settings on all remaining cluster nodes
337 function populate_rc() {
338 wget -O deb http://archive.ubuntu.com/ubuntu/pool/universe/s/sshpass/sshpass_1.05-1_amd64.deb &&\
342 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}" )
343 myaddr=$(ifconfig br-fw-admin | sed -n '/inet addr/s/.*addr.\([^ ]*\) .*/\1/p')
344 for anode in $clusternodes ; do
345 if [ "$anode" != "$myaddr" ] ; then
346 echo "Populating seetings to $anode"
347 scp ${SSH_OPTIONS[@]} tackerc $anode:tackerc
362 remove_repo "$MYREPO"
363 remove_repo "$DEPREPO"
364 remove_repo "$CLIREPO"
366 echo "Built: ${MYDIR}/${OUTPUT}"
367 echo "Built: ${MYDIR}/${CLIENT}"
368 echo "Built: ${MYDIR}/${JSONRPC}"
369 echo "tackerc - mandatory environmental parameters file created"