Commit 718aee7a authored by Thomas Markwalder's avatar Thomas Markwalder

[master] Corrected CQL upgrade script

    Merge branch '344-cql-upgrade-script-fails-on-ubuntu'
parents e6290f00 ed78d538
...@@ -352,6 +352,9 @@ cql_unused_subnet_id_test() { ...@@ -352,6 +352,9 @@ cql_unused_subnet_id_test() {
# Wipe the database. # Wipe the database.
cql_wipe cql_wipe
# Report test success.
test_finish 0
} }
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
prefix=@prefix@ prefix=@prefix@
# Include utilities. Use installed version if available and # Include utilities. Use installed version if available and
# use build version if it isn't. # use build version if it isn't.
if [ -e @datarootdir@/@PACKAGE_NAME@/scripts/admin-utils.sh ]; then if [ -e "@datarootdir@/@PACKAGE_NAME@/scripts/admin-utils.sh" ]; then
. @datarootdir@/@PACKAGE_NAME@/scripts/admin-utils.sh . @datarootdir@/@PACKAGE_NAME@/scripts/admin-utils.sh
else else
. @abs_top_builddir@/src/bin/admin/admin-utils.sh . @abs_top_builddir@/src/bin/admin/admin-utils.sh
...@@ -12,7 +12,7 @@ fi ...@@ -12,7 +12,7 @@ fi
# Need a path for temporary files created during upgrade data migration # Need a path for temporary files created during upgrade data migration
# Use the state directory in the install path directory if it exists, otherwise # Use the state directory in the install path directory if it exists, otherwise
# use the build tree # use the build tree
if [ -e @localstatedir@/@PACKAGE_NAME@ ]; then if [ -e "@localstatedir@/@PACKAGE_NAME@" ]; then
temp_file_dir="@localstatedir@/@PACKAGE_NAME@" temp_file_dir="@localstatedir@/@PACKAGE_NAME@"
else else
temp_file_dir="@abs_top_builddir@/src/share/database/scripts/cql" temp_file_dir="@abs_top_builddir@/src/share/database/scripts/cql"
...@@ -62,22 +62,22 @@ INSERT INTO schema_version (version, minor) VALUES(3, 0); ...@@ -62,22 +62,22 @@ INSERT INTO schema_version (version, minor) VALUES(3, 0);
-- This line concludes database upgrade to version 3.0 -- This line concludes database upgrade to version 3.0
EOF EOF
if [ $? -ne 0 ] if [ "$?" -ne 0 ]
then then
echo Schema udpate FAILED! echo Schema udpate FAILED!
exit -1 exit 1
fi fi
} }
# Function to delete temporary migration files # Function to delete temporary migration files
clean_up() { clean_up() {
# clean up the files # clean up the files
if [ -e $export_file ] if [ -e "$export_file" ]
then then
rm $export_file rm $export_file
fi fi
if [ -e $update_file ] if [ -e "$update_file" ]
then then
rm $update_file rm $update_file
fi fi
...@@ -95,7 +95,7 @@ exit_now() { ...@@ -95,7 +95,7 @@ exit_now() {
explanation=$1 explanation=$1
clean_up clean_up
if [ $status -eq 0 ] if [ "$status" -eq 0 ]
then then
echo "Data Migration SUCCESS! $explanation" echo "Data Migration SUCCESS! $explanation"
else else
...@@ -175,9 +175,19 @@ migrate_host_data() { ...@@ -175,9 +175,19 @@ migrate_host_data() {
TO '$export_file'" TO '$export_file'"
cqlsh $cqlargs -e "$query" cqlsh $cqlargs -e "$query"
if [ $? -ne 0 ] if [ "$?" -ne 0 ]
then then
exit_now -1 "Cassandra export failed! Could not migrate data!" exit_now 1 "Cassandra export failed! Could not migrate data!"
fi
# Strip the carriage returns that CQL insists on adding.
if [ -e "$export_file" ]
then
cat $export_file | tr -d '\015' > $export_file.2
mv $export_file.2 $export_file
else
# Shouldn't happen but then again we're talking about CQL here
exit_now 1 "Cassandra export file $export_file is missing?"
fi fi
# Iterate through the exported data, accumulating update statements, # Iterate through the exported data, accumulating update statements,
...@@ -188,10 +198,11 @@ migrate_host_data() { ...@@ -188,10 +198,11 @@ migrate_host_data() {
while read line while read line
do do
let line_cnt++; line_cnt=$((line_cnt + 1));
update_cols="" update_cols=""
xIFS="$IFS" xIFS="$IFS"
IFS=$'\r,' IFS=$','
i=1 i=1
# Parse the column values # Parse the column values
for val in $line for val in $line
...@@ -211,30 +222,30 @@ migrate_host_data() { ...@@ -211,30 +222,30 @@ migrate_host_data() {
;; ;;
*) *)
# We're going to assume that since any error is fatal # We're going to assume that since any error is fatal
exit_now -1 "Line# $line_cnt, too many values, wrong or corrupt file" exit_now 1 "Line# $line_cnt, too many values, wrong or corrupt file"
;; ;;
esac esac
let i++ i=$((i + 1))
done done
if [ $i -ne 5 ] if [ "$i" -ne 5 ]
then then
# We're going to assume that since any error is fatal # We're going to assume that since any error is fatal
exit_now -1 "Line# $line_cnt, too few values, wrong or corrupt file" exit_now 1 "Line# $line_cnt, too few values, wrong or corrupt file"
fi fi
# If any of the current host's columns need to be replace, append an update for it # If any of the current host's columns need to be replace, append an update for it
if [ ! -z "$update_cols" ] if [ ! -z "$update_cols" ]
then then
echo "update host_reservations set $update_cols where id = $host_id;" >> $update_file echo "update host_reservations set $update_cols where id = $host_id;" >> $update_file
let update_cnt++ update_cnt=$((update_cnt + 1))
fi fi
IFS="$xIFS" IFS="$xIFS"
done < $export_file done < $export_file
# If we didn't record any updates, then hey, we're good to go! # If we didn't record any updates, then hey, we're good to go!
if [ $update_cnt == 0 ] if [ "$update_cnt" -eq 0 ]
then then
exit_now 0 "Completed successfully: No updates were needed" exit_now 0 "Completed successfully: No updates were needed"
fi fi
...@@ -243,10 +254,9 @@ migrate_host_data() { ...@@ -243,10 +254,9 @@ migrate_host_data() {
echo "$update_cnt update statements written to $update_file" echo "$update_cnt update statements written to $update_file"
echo "Running the updates..." echo "Running the updates..."
cqlsh $cqlargs -f "$update_file" cqlsh $cqlargs -f "$update_file"
if [ $? -ne 0 ] if [ "$?" -ne 0 ]
then then
exit_now -1 "Cassandra updates failed" exit_now 1 "Cassandra updates failed"
exit -1
fi fi
exit_now 0 "Updated $update_cnt of $line_cnt records" exit_now 0 "Updated $update_cnt of $line_cnt records"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment