3 # ============LICENSE_START==========================================
5 # ===================================================================
6 # Copyright (c) 2019 AT&T Intellectual Property
7 # ===================================================================
8 # Licensed under the Apache License, Version 2.0 (the "License");
9 # you may not use this file except in compliance with the License.
10 # You may obtain a copy of the License at
12 # http://www.apache.org/licenses/LICENSE-2.0
14 # Unless required by applicable law or agreed to in writing, software
15 # distributed under the License is distributed on an "AS IS" BASIS,
16 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 # See the License for the specific language governing permissions and
18 # limitations under the License.
20 # ============LICENSE_END=============================================
21 # ====================================================================
23 if [ -z "$TIMEOUT" ]; then
26 if [ -z "$DELAY" ]; then
29 TO="--request-timeout=$TIMEOUT"
31 if [ $CASS_HOSTNAME ]; then
32 echo "Sleeping for $DELAY seconds before running cql";
34 >&2 echo "#############################################"
35 >&2 echo "############## Let run cql's ################"
36 >&2 echo "#############################################"
37 >&2 echo "Current Variables in play"
38 >&2 echo "Default User"
39 >&2 echo "DEF_USER="$DEF_USER
40 >&2 echo "DEF_PASS=***********"
42 >&2 echo "USERNAME="$USERNAME
43 >&2 echo "PASSWORD=***********"
44 >&2 echo "TIMEOUT="$TIMEOUT
45 >&2 echo "Running cqlsh $TO -u cassandra -p cassandra -e \"describe keyspaces;\" ${CASS_HOSTNAME} ${PORT};"
46 if cqlsh $TO -u cassandra -p cassandra -e "describe keyspaces;" ${CASS_HOSTNAME} ${PORT};
48 >&2 echo "Cassandra user still avalable, will continue as usual";
51 >&2 echo "$DEF_USER failed, trying with $USERNAME"
52 if cqlsh $TO -u $USERNAME -p $PASSWORD -e "describe keyspaces;" ${CASS_HOSTNAME} ${PORT};
54 >&2 echo "Password $USERNAME in play, update Variables"
57 >&2 echo "DEF_USER="$DEF_USER
58 >&2 echo "DEF_PASS=***********"
59 if cqlsh $TO -u $USERNAME -p $PASSWORD -e "describe keyspaces;" ${CASS_HOSTNAME} ${PORT} | grep admin;
61 >&2 echo "Admin table exists, everything looks good"
64 >&2 echo "Admin does not exists but password has changed. Continue as usual with proper username set"
65 >&2 echo "DEF_USER=" $DEF_USER
68 if [ $CASSFAIL ]; then
69 >&2 echo "$DEF_USER and $USERNAME fail. DB might need to be initialized again. This shouldn't have happend."
72 >&2 echo "Continue and as usual"
76 >&2 echo "Running admin.cql file:"
77 >&2 echo "Running cqlsh -u $DEF_USER -p $DEF_PASS -f /cql/admin.cql ${CASS_HOSTNAME} ${PORT}"
79 if cqlsh $TO -u $DEF_USER -p $DEF_PASS -f /cql/admin.cql ${CASS_HOSTNAME} ${PORT};
81 >&2 echo "Success - admin.cql - Admin keyspace created";
83 >&2 echo "Failure - admin.cql";
86 >&2 echo "Running admin_pw.cql file:"
87 >&2 echo "Running cqlsh -u $DEF_USER -p $DEF_PASS -f /cql/admin_pw.cql ${CASS_HOSTNAME} ${PORT}"
89 if cqlsh $TO -u $DEF_USER -p $DEF_PASS -f /cql/admin_pw.cql ${CASS_HOSTNAME} ${PORT};
91 >&2 echo "Success - admin_pw.cql - Password Changed";
93 >&2 echo "Failure - admin_pw.cql";
97 >&2 echo "Running Test - look for admin keyspace:"
98 >&2 echo "Running cqlsh -u $USERNAME -p $PASSWORD -e "select * from system_auth.roles;" ${CASS_HOSTNAME} ${PORT}"
100 if cqlsh $TO -u $USERNAME -p $PASSWORD -e "select * from system_auth.roles;" ${CASS_HOSTNAME} ${PORT}
102 >&2 echo "Success - running test";
104 >&2 echo "Failure - running test";
109 >&2 echo "Missing CASS_HOSTNAME";