Support Fenix as admin tool
[doctor.git] / doctor_tests / installer / common / set_fenix.sh
1 #!/usr/bin/env bash
2
3 ##############################################################################
4 # Copyright (c) 2018 Nokia Corporation and others.
5 #
6 # All rights reserved. This program and the accompanying materials
7 # are made available under the terms of the Apache License, Version 2.0
8 # which accompanies this distribution, and is available at
9 # http://www.apache.org/licenses/LICENSE-2.0
10 ##############################################################################
11
12 # Config files
13 echo "[DEFAULT]" > fenix.conf
14 echo "[DEFAULT]" > fenix-api.conf
15 echo "port = 12347" >> fenix.conf
16 echo "port = 12347" >> fenix-api.conf
17 grep -m1 "^transport" /var/lib/config-data/puppet-generated/nova/etc/nova/nova.conf >> fenix.conf
18 grep -m1 "^transport" /var/lib/config-data/puppet-generated/nova/etc/nova/nova.conf >> fenix-api.conf
19 echo "[database]" >> fenix.conf
20 MYSQLIP=`grep -m1 "^connection=mysql" /var/lib/config-data/puppet-generated/nova/etc/nova/nova.conf | sed -e "s/.*@//;s/\/.*//"`
21 echo "connection=mysql+pymysql://fenix:fenix@$MYSQLIP/fenix?read_default_group=tripleo&read_default_file=/etc/my.cnf.d/tripleo.cnf" >> fenix.conf
22
23 # Mysql pw
24 MYSQLPW=`cat /var/lib/config-data/mysql/etc/puppet/hieradata/service_configs.json | grep mysql | grep root_password | awk -F": " '{print $2}' | awk -F"\"" '{print $2}'`
25
26 # Fenix DB
27 [ `mysql -uroot -p$MYSQLPW -e "SELECT host, user FROM mysql.user;" | grep fenix | wc -l` -eq 0 ] && {
28     mysql -uroot -p$MYSQLPW -hlocalhost -e "CREATE USER 'fenix'@'localhost' IDENTIFIED BY 'fenix';"
29     mysql -uroot -p$MYSQLPW -hlocalhost -e "GRANT ALL PRIVILEGES ON fenix.* TO 'fenix'@'' identified by 'fenix';FLUSH PRIVILEGES;"
30 }
31 mysql -ufenix -pfenix -hlocalhost -e "DROP DATABASE IF EXISTS fenix;"
32 mysql -ufenix -pfenix -hlocalhost -e "CREATE DATABASE fenix CHARACTER SET utf8;"
33
34 # Remove previous container
35 for img in `docker image list | grep "^fenix" | awk '{print $1}'`; do
36     for dock in `docker ps --all -f "ancestor=$img" | grep "$img" | awk '{print $1}'`; do
37         docker stop $dock; docker rm $dock;
38     done;
39     docker image rm $img;
40 done
41
42 # Build Fenix container and run it
43 chmod 700 run
44 docker build --build-arg OPENSTACK=master --build-arg BRANCH=master --network host /home/heat-admin -t fenix | tail -1
45 docker run --network host -d --name fenix -p 12347:12347 -ti fenix
46 if [ $? -eq 0 ]; then
47     echo "Fenix start: OK"
48 else
49     echo "Fenix start: FAILED"
50 fi
51 # To debug check log from fenix container
52 # docker exec -ti fenix tail -f /var/log/fenix-engine.log