From a0eea43cbb93665d9d1ac96765d1abdf2a665d15 Mon Sep 17 00:00:00 2001
From: Micah Anderson <micah@riseup.net>
Date: Tue, 7 Nov 2017 11:54:19 -0500
Subject: [PATCH] CI: do soledad migration during upgrade test

Updating platfrom 0.9 (soledad 0.8.0) to 0.10 (soledad 0.10.3) requires a
soledad-server migration. This integrates the migration in the CI
upgrade_test. Fixes #8881
---
 tests/platform-ci/ci-build.sh | 35 ++++++++++++++++++++++++++++++++---
 1 file changed, 32 insertions(+), 3 deletions(-)

diff --git a/tests/platform-ci/ci-build.sh b/tests/platform-ci/ci-build.sh
index 843642a4..4c9a516c 100755
--- a/tests/platform-ci/ci-build.sh
+++ b/tests/platform-ci/ci-build.sh
@@ -191,8 +191,32 @@ run() {
   test
 }
 
+soledad_migration() {
+  # check the version of soledad installed
+  # if the version is not greater than 0.9, we need to do the migration
+  if ! LEAP_CMD run "dpkg --compare-versions \$(dpkg -l |grep soledad-server|grep ^ii|awk '{ print \$3}') gt 0.9" vm |grep -q oops
+  then
+      echo "Need to migrate from soledad 0.9!"
+      if ! LEAP_CMD run 'systemctl stop leap-mx' vm
+      then fail
+      fi
+      if ! LEAP_CMD run 'systemctl stop soledad-server' vm
+      then fail
+      fi
+      if ! LEAP_CMD run --stream '/usr/share/soledad-server/migration/0.9/migrate.py --verbose --log-file /var/log/leap/soledad_migration.log --do-migrate' vm
+      then fail
+      fi
+      if ! LEAP_CMD run 'systemctl start leap-mx' vm
+      then fail
+      fi
+      if ! LEAP_CMD run 'systemctl start soledad-server' vm
+      then fail
+      fi
+  fi
+}
+
 upgrade_test() {
-  # Checkout stable branch containing last release
+  # Checkout stable branch containing previous stable release
   # and deploy this
   cd "$PLATFORMDIR"
   # due to cache, this remote is sometimes already added
@@ -208,7 +232,7 @@ upgrade_test() {
   /usr/local/bin/bundle install
 
   cd "$PROVIDERDIR"
-
+  LEAP_CMD --version
   build_from_scratch 'couchdb,soledad,mx,webapp,tor,monitor'
   deploy
   test
@@ -225,12 +249,17 @@ upgrade_test() {
   /usr/local/bin/bundle install
 
   cd "$PROVIDERDIR"
-
+  LEAP_CMD --version
+  
   # due to the 'tor' service no longer being valid in 0.10, we need to change
   # that service to 'tor_relay'. This is done by changing the services array
   # with jq to be set to the full correct list of services
   jq '.services = ["couchdb","soledad","mx","webapp","tor_relay","monitor"]' < nodes/${NAME}.json
   deploy
+
+  # check for soledad migration, and run it if necessary
+  soledad_migration
+
   test
 
   cleanup
-- 
GitLab