summaryrefslogtreecommitdiffstats
path: root/doctor_tests/installer/common/set_fenix.sh
blob: a660af79b7fe3ca688a5d14957d3427d3d164eb1 (plain)
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
#!/usr/bin/env bash

##############################################################################
# Copyright (c) 2018 Nokia Corporation and others.
#
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Apache License, Version 2.0
# which accompanies this distribution, and is available at
# http://www.apache.org/licenses/LICENSE-2.0
##############################################################################

# Config files
echo "[DEFAULT]" > fenix.conf
echo "[DEFAULT]" > fenix-api.conf
echo "port = 12347" >> fenix.conf
echo "port = 12347" >> fenix-api.conf
grep -m1 "^transport" /var/lib/config-data/puppet-generated/nova/etc/nova/nova.conf >> fenix.conf
grep -m1 "^transport" /var/lib/config-data/puppet-generated/nova/etc/nova/nova.conf >> fenix-api.conf
echo "[database]" >> fenix.conf
MYSQLIP=`grep -m1 "^connection=mysql" /var/lib/config-data/puppet-generated/nova/etc/nova/nova.conf | sed -e "s/.*@//;s/\/.*//"`
echo "connection=mysql+pymysql://fenix:fenix@$MYSQLIP/fenix?read_default_group=tripleo&read_default_file=/etc/my.cnf.d/tripleo.cnf" >> fenix.conf

# Mysql pw
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}'`

# Fenix DB
[ `mysql -uroot -p$MYSQLPW -e "SELECT host, user FROM mysql.user;" | grep fenix | wc -l` -eq 0 ] && {
    mysql -uroot -p$MYSQLPW -hlocalhost -e "CREATE USER 'fenix'@'localhost' IDENTIFIED BY 'fenix';"
    mysql -uroot -p$MYSQLPW -hlocalhost -e "GRANT ALL PRIVILEGES ON fenix.* TO 'fenix'@'' identified by 'fenix';FLUSH PRIVILEGES;"
}
mysql -ufenix -pfenix -hlocalhost -e "DROP DATABASE IF EXISTS fenix;"
mysql -ufenix -pfenix -hlocalhost -e "CREATE DATABASE fenix CHARACTER SET utf8;"

# Remove previous container
for img in `docker image list | grep "^fenix" | awk '{print $1}'`; do
    for dock in `docker ps --all -f "ancestor=$img" | grep "$img" | awk '{print $1}'`; do
        docker stop $dock; docker rm $dock;
    done;
    docker image rm $img;
done

# Build Fenix container and run it
chmod 700 run
docker build --build-arg OPENSTACK=master --build-arg BRANCH=master --network host /home/heat-admin -t fenix | tail -1
docker run --network host -d --name fenix -p 12347:12347 -ti fenix
if [ $? -eq 0 ]; then
    echo "Fenix start: OK"
else
    echo "Fenix start: FAILED"
fi
# To debug check log from fenix container
# docker exec -ti fenix tail -f /var/log/fenix-engine.log