]> scripts.mit.edu Git - wizard.git/commitdiff
Backup on upgrade, add tests.
authorEdward Z. Yang <ezyang@mit.edu>
Sat, 3 Oct 2009 01:55:15 +0000 (21:55 -0400)
committerEdward Z. Yang <ezyang@mit.edu>
Sat, 3 Oct 2009 01:55:15 +0000 (21:55 -0400)
* Fix bug in 'wizard backup'
* Make 'wizard install' perform a commit
* Make 'wizard install app-oldversion' do a hard reset
* Add backup() and restore() to Deployment
* Have sql credentials read environmental variables

Signed-off-by: Edward Z. Yang <ezyang@mit.edu>
TODO
tests/clean.sh [new file with mode: 0755]
tests/test-backup-restore-mediawiki.sh [new file with mode: 0755]
tests/test-upgrade-mediawiki-restore.sh [new file with mode: 0755]
wizard/command/backup.py
wizard/command/configure.py
wizard/command/install.py
wizard/command/restore.py
wizard/command/upgrade.py
wizard/deploy.py
wizard/scripts.py

diff --git a/TODO b/TODO
index 88fc182eab6698d5e2ebdbfc15dea7be779c5a02..f395d69bf58c010b4d5cce50149c231c1d7de27a 100644 (file)
--- a/TODO
+++ b/TODO
@@ -2,7 +2,7 @@ The Git Autoinstaller
 
 TODO NOW:
 
-- Check for extensions, have DB rollback
+- Check for extensions
 - Implement "group" filtering using blanche for limited rollouts.
 
 - Remove "already migrated" cruft that will accumulate if we do small
diff --git a/tests/clean.sh b/tests/clean.sh
new file mode 100755 (executable)
index 0000000..2624926
--- /dev/null
@@ -0,0 +1,2 @@
+#!/bin/sh
+rm -Rf testdir*
diff --git a/tests/test-backup-restore-mediawiki.sh b/tests/test-backup-restore-mediawiki.sh
new file mode 100755 (executable)
index 0000000..368c7d5
--- /dev/null
@@ -0,0 +1,24 @@
+#!/bin/bash -e
+
+TESTNAME="backup_restore_mediawiki"
+source ./setup
+
+wizard install mediawiki-$VERSION-scripts "$TESTDIR" -- --title="TestApp"
+cd "$TESTDIR"
+wizard backup
+
+# destroy some files
+FROB="includes/Setup.php"
+mv "$FROB" "$FROB.bak"
+echo "BOOM" > "$FROB"
+
+# destroy the database
+mysql $MYSQL_ARGS -e "DROP DATABASE \`$WIZARD_MYSQL_DB\`;"
+mysql $MYSQL_ARGS -e "CREATE DATABASE \`$WIZARD_MYSQL_DB\`;"
+
+BACKUP=`wizard restore | head -n1`
+wizard restore "$BACKUP"
+
+cmp "$FROB" "$FROB.bak"
+curl -s -L "http://$WIZARD_WEB_HOST$WIZARD_WEB_PATH/index.php" | grep "<title>"
+
diff --git a/tests/test-upgrade-mediawiki-restore.sh b/tests/test-upgrade-mediawiki-restore.sh
new file mode 100755 (executable)
index 0000000..a2af3e6
--- /dev/null
@@ -0,0 +1,11 @@
+#!/bin/bash -e
+
+TESTNAME="upgrade_mediawiki_restore"
+source ./setup
+
+wizard install mediawiki-$VERSION-scripts "$TESTDIR" -- --title="TestApp"
+wizard upgrade "$TESTDIR"
+cd "$TESTDIR"
+BACKUP=`wizard restore | head -n1`
+wizard restore "$BACKUP"
+git describe --tags
index 77e81a9a9e237b3f61f2929bdeff1830430c223d..8362da787c5ce1cb0a6931c006fb3cdf38880358 100644 (file)
@@ -16,7 +16,7 @@ def main(argv, baton):
     d = deploy.Deployment(".")
     d.verify()
     d.verifyConfigured()
-    d.application.backup(d, options)
+    d.backup(options)
 
 def parse_args(argv, baton):
     usage = """usage: %prog backup [ARGS] [DIR]
index 2879b36fc9d1f7a9b08297a8c76bc14fea13aaed..1ac7ea7734c80eb7d86695c08dd88c820b63af85 100644 (file)
@@ -3,7 +3,7 @@ import optparse
 import sys
 import distutils.version
 
-from wizard import command, deploy, git
+from wizard import command, deploy, git, shell, util
 
 def main(argv, baton):
 
@@ -45,3 +45,12 @@ This is a plumbing command, normal users should use
 
     app.install(distutils.version.LooseVersion(version), options)
 
+    sh = shell.Shell()
+    message = "Autoinstall configuration of %s locker.\n\n%s" % (util.get_dir_owner(), util.get_git_footer())
+    util.set_git_env()
+    try:
+        message += "\nConfigured-by: " + util.get_operator_git()
+    except util.NoOperatorInfo:
+        pass
+    sh.call("git", "commit", "--allow-empty", "-a", "-m", message)
+
index 746463169e40ded3deb0d8ac2bf0b50a53861d3d..e736fc967a4763870ef548ba859f929b8a6fbffa 100644 (file)
@@ -20,7 +20,7 @@ def main(argv, baton):
     sh.call("git", "clone", "--shared", application.repository(options.srv_path), dir)
     with util.ChangeDirectory(dir):
         if version:
-            sh.call("git", "checkout", app)
+            sh.call("git", "reset", "--hard", app)
         # this command's stdin should be hooked up to ours
         try:
             configure_args = args[2:] + command.makeBaseArgs(options)
index 152ce19527c44ea135d0745e679725566cc6dc49..cadc1f878aefb86b370054da0af396aaa71f8132 100644 (file)
@@ -40,7 +40,7 @@ def main(argv, baton):
     except shell.CallError:
         raise Exception("Tag %s doesn't exist in repository" % tag)
     sh.call("git", "reset", "--hard", tag)
-    d.application.restore(d, backup, options)
+    d.restore(backup, options)
 
 def parse_args(argv, baton):
     usage = """usage: %prog restore [ARGS] ID
index 9f388e047eb4d8820a7ff82cd75f23cc4f096db3..66e1d6bd48909a2f1bfcd77f96ab4735eff43a59 100644 (file)
@@ -73,6 +73,8 @@ def main(argv, baton):
     if options.dry_run:
         logging.info("Dry run, bailing.  See results at %s" % temp_wc_dir)
         return
+    # perform database backup
+    d.backup(options)
     # XXX: frob .htaccess to make site inaccessible
     # XXX: need locking
     # git merge (which performs a fast forward)
index 0c6fa94f7a2881c322116363a2fba1ad7a59fd6f..d5ebab3fbd84493a53556ec22c91ddd1a5b7926a 100644 (file)
@@ -105,6 +105,16 @@ class Deployment(object):
         as such dir will generally not equal :attr:`location`.
         """
         return self.application.parametrize(self, dir)
+    def backup(self, options):
+        """
+        Performs a backup of database schemas and other non-versioned data.
+        """
+        with util.ChangeDirectory(self.location):
+            return self.application.backup(self, options)
+    def restore(self, backup, options):
+        """Restores a backup. Destroys state, so be careful!"""
+        with util.ChangeDirectory(self.location):
+            return self.application.restore(self, backup, options)
     def prepareConfig(self):
         """
         Edits files in the deployment such that any user-specific configuration
index 415be1a064a27bec416d015a0dd1eb56e5f7b4bb..9676b3482f8e57b3a0515aad69455c38a1ddb972 100644 (file)
@@ -1,3 +1,5 @@
+import os
+
 from wizard import shell
 
 def get_sql_credentials():
@@ -6,6 +8,11 @@ def get_sql_credentials():
     returned as a three-tuple (host, user, password).
     """
     sh = shell.Shell()
+    host = os.getenv("WIZARD_MYSQL_HOST")
+    user = os.getenv("WIZARD_MYSQL_USER")
+    password = os.getenv("WIZARD_MYSQL_PASSWORD")
+    if host is not None and user is not None and password is not None:
+        return (host, user, password)
     try:
         return sh.eval("/mit/scripts/sql/bin/get-password").split()
     except CallError: