summaryrefslogtreecommitdiffstats
path: root/lcm/docker
diff options
context:
space:
mode:
authoryangyan <yangyanyj@chinamobile.com>2019-03-25 15:21:08 +0800
committeryangyan <yangyanyj@chinamobile.com>2019-03-25 15:21:19 +0800
commitfc22a341ea5db3b3a0bb3e152acbff7e20d3851b (patch)
tree06fdc863562a942a9b58b8739c6c1420353a294c /lcm/docker
parentd5398e82b6e5e6fe304442d9fe38dfaa48b19ba6 (diff)
change the way of create database
Change-Id: Ice0fd083c4b012e815d48b15abcd9cb9b944ef9b Issue-ID: VFC-1312 Signed-off-by: yangyan <yangyanyj@chinamobile.com>
Diffstat (limited to 'lcm/docker')
-rwxr-xr-xlcm/docker/instance_config.sh4
-rwxr-xr-xlcm/docker/instance_init.sh66
2 files changed, 69 insertions, 1 deletions
diff --git a/lcm/docker/instance_config.sh b/lcm/docker/instance_config.sh
index 48a157c4..93c6aa8b 100755
--- a/lcm/docker/instance_config.sh
+++ b/lcm/docker/instance_config.sh
@@ -21,9 +21,13 @@ sed -i "s/127.0.0.1:80/$MSB_IP:$MSB_PORT/" vfc/gvnfm/vnflcm/lcm/lcm/pub/config/c
MYSQL_IP=`echo $MYSQL_ADDR | cut -d: -f 1`
MYSQL_PORT=`echo $MYSQL_ADDR | cut -d: -f 2`
echo "MYSQL_ADDR=$MYSQL_ADDR"
+MYSQL_USER=`echo $MYSQL_AUTH | cut -d: -f 1`
+MYSQL_ROOT_PASSWORD=`echo $MYSQL_AUTH | cut -d: -f 2`
sed -i "s|DB_IP.*|DB_IP = '$MYSQL_IP'|" vfc/gvnfm/vnflcm/lcm/lcm/pub/config/config.py
sed -i "s|DB_PORT.*|DB_PORT = $MYSQL_PORT|" vfc/gvnfm/vnflcm/lcm/lcm/pub/config/config.py
sed -i "s|REDIS_HOST.*|REDIS_HOST = '$MYSQL_IP'|" vfc/gvnfm/vnflcm/lcm/lcm/pub/config/config.py
+sed -i "s|DB_USER.*|DB_USER = '$MYSQL_USER'|" vfc/gvnfm/vnflcm/lcm/lcm/pub/config/config.py
+sed -i "s|DB_PASSWD.*|DB_PASSWD = '$MYSQL_ROOT_PASSWORD'|" vfc/gvnfm/vnflcm/lcm/lcm/pub/config/config.py
cat vfc/gvnfm/vnflcm/lcm/lcm/pub/config/config.py
diff --git a/lcm/docker/instance_init.sh b/lcm/docker/instance_init.sh
index cfc9b0d5..46a3db07 100755
--- a/lcm/docker/instance_init.sh
+++ b/lcm/docker/instance_init.sh
@@ -1,2 +1,66 @@
#!/bin/bash
-echo "No service needs init."
+######
+# by vfc-db test
+#####
+# echo "No service needs init."
+#MYSQL_USER=$1
+######
+#by duan
+pip install PyMySQL==0.9.3
+if [ ! -f /service/vfc/gvnfm/vnflcm/lcm/resources/bin/logs/django.log ]; then
+ mkdir -p /service/vfc/gvnfm/vnflcm/lcm/resources/bin/logs/
+ touch /service/vfc/gvnfm/vnflcm/lcm/resources/bin/logs/django.log
+else
+ echo >/service/vfc/gvnfm/vnflcm/lcm/resources/bin/logs/django.log
+fi
+
+if [ ! -f /var/log/onap/vfc/gvnfm-vnflcm/runtime_lcm.log ]; then
+ mkdir -p /var/log/onap/vfc/gvnfm-vnflcm/
+ touch /var/log/onap/vfc/gvnfm-vnflcm/runtime_lcm.log
+else
+ echo >/var/log/onap/vfc/gvnfm-vnflcm/runtime_lcm.log
+fi
+
+MYSQL_IP=`echo $MYSQL_ADDR | cut -d: -f 1`
+MYSQL_PORT=`echo $MYSQL_ADDR | cut -d: -f 2`
+MYSQL_USER=`echo $MYSQL_AUTH | cut -d: -f 1`
+MYSQL_ROOT_PASSWORD=`echo $MYSQL_AUTH | cut -d: -f 2`
+
+function create_database {
+ cd /service/vfc/gvnfm/vnflcm/lcm/resources/bin
+ bash initDB.sh $MYSQL_USER $MYSQL_ROOT_PASSWORD $MYSQL_PORT $MYSQL_IP
+ #DIRNAME=`dirname $0`
+ #HOME=`cd $DIRNAME/; pwd`
+ #man_path=$HOME/../
+ man_path=/service/vfc/gvnfm/vnflcm/lcm
+ #tab=`mysql -u${MYSQL_USER} -p${MYSQL_PASSWORD} -P${MYSQL_PORT} -h${MYSQL_IP} -e "use vfcnfvolcm; select count(*) from vfcnfvolcm;"`
+ tab=`mysql -u${MYSQL_USER} -p${MYSQL_ROOT_PASSWORD} -P${MYSQL_PORT} -h${MYSQL_IP} -e "SELECT count(TABLE_NAME) FROM information_schema.TABLES WHERE TABLE_SCHEMA='gvnfm';"`
+ tab1=`echo $tab |awk '{print $2}'`
+ echo "=========="
+ echo $tab1
+ echo "=========="
+ if [ $tab1 -eq 0 ] ; then
+ echo "============"
+ echo $tab1
+ echo "============"
+ echo "TABLE NOT EXISTS, START MIGRATE"
+ python $man_path/manage.py makemigrations && python $man_path/manage.py migrate &
+ wait
+ tab2=`mysql -u${MYSQL_USER} -p${MYSQL_ROOT_PASSWORD} -P${MYSQL_PORT} -h${MYSQL_IP} -e "SELECT count(TABLE_NAME) FROM information_schema.TABLES WHERE TABLE_SCHEMA='gvnfm';"`
+ tab3=`echo $tab2|awk '{print $2}'`
+ if [ $tab3 -gt 0 ] ; then
+ echo "TABLE CREATE SUCCESSFUL"
+ fi
+else
+ echo "table already existed"
+ exit 1
+fi
+ }
+
+if [ ! -f /service/vfc/gvnfm/vnflcm/lcm/docker/db.txt ]; then
+ echo 1 > /service/vfc/gvnfm/vnflcm/lcm/docker/db.txt
+ echo `pwd` >> /service/vfc/gvnfm/vnflcm/lcm/docker/db.txt
+ create_database
+else
+ echo "database already existed"
+fi