Move CSIT to integration/csit repo
[integration/csit.git] / plans / appc / healthcheck / db_query.sh
1 #!/usr/bin/env bash
2 ###############################################################################
3 # Copyright 2017 Huawei Technologies Co., Ltd.
4 #
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
8 #
9 #     http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16 ###############################################################################
17 SCRIPTS="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
18 echo $SCRIPTS
19
20 sdnctl_num_tables=$(docker exec -i sdnc_db_container mysql -s -D sdnctl -u sdnctl -pgamma <<<'show tables;' 2>/dev/null | grep -v ERROR | wc -l)
21
22 appcctl_num_tables=$(docker exec -i sdnc_db_container mysql -s -D appcctl -u appcctl -pappcctl <<<'show tables;' 2>/dev/null | grep -v ERROR | wc -l)
23
24
25
26 docker exec -i sdnc_db_container mysql -s -D sdnctl -u sdnctl -pgamma <<<"show tables" 2>/dev/null | ( while read table_name; do 
27 export $table_name="$(docker exec -i sdnc_db_container mysql -s -D sdnctl -u sdnctl -pgamma <<<"select count(*) from $table_name" 2>/dev/null)"
28 done 
29
30 if [ "$sdnctl_num_tables" -ge "1" ]; then
31   echo "There are $sdnctl_num_tables tables in the sdnctl database. "
32 else
33   echo "Database sdnctl is not available."
34   exit 1;
35 fi
36
37 if [ "$appcctl_num_tables" -ge "1" ]; then
38   echo "There is $appcctl_num_tables table in the appcctl database. "
39 else
40   echo "Database appcctl is not available."
41   exit 1;
42 fi
43
44 #if [ "$NODE_TYPES" -eq "0" ]; then
45 #  echo "There is no data in table NODE_TYPES. "
46 #  exit 1;
47 #fi
48
49 #if [ "$SVC_LOGIC" -eq "0" ] ; then
50 #  echo "There is no data in table SVC_LOGIC. "
51 #  exit 1;
52 #fi
53
54 #if [ "$VNF_DG_MAPPING" -eq "0" ]; then
55 #  echo "There is no data in table VNF_DG_MAPPING. "
56 #  exit 1;
57 #fi 
58
59 echo "Expected table data is present."
60 exit 0 )
61
62 if [ "$?" -eq "1" ]; then
63   exit 1;
64 fi
65
66 exit 0