summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSteven Jones2011-09-23 08:56:11 +0100
committerSteven Jones2011-09-23 08:56:11 +0100
commitd48dd661b97833e20c7dac851bd5a6dc53ba94dd (patch)
tree776cd18f040c3202f8be56b52fd217cddc9a1425
parent74d187510faeb4b612bde00d56a581ce5eadc0ad (diff)
Add the beginnings of some tests.dev/1194676-jenkins-tests
-rw-r--r--tests/provision_tests.drush.inc133
1 files changed, 133 insertions, 0 deletions
diff --git a/tests/provision_tests.drush.inc b/tests/provision_tests.drush.inc
new file mode 100644
index 0000000..0eeb7ae
--- /dev/null
+++ b/tests/provision_tests.drush.inc
@@ -0,0 +1,133 @@
+<?php
+/**
+ * @file
+ * Some tests for hostmaster and provison.
+ *
+ * These could live in Hostmaster or Provision, and there are advantages and
+ * disadvantages to both. But I decided that I'd just get on with it and pop
+ * them into Provision.
+ */
+
+define('PROVISION_TESTS_BUILDS_REPO', 'https://github.com/mig5/builds/raw/master');
+
+/**
+ * Implementation of hook_drush_command().
+ */
+function provision_tests_drush_command() {
+ $items['provision-tests-run'] = array(
+ 'description' => dt('Runs provision tests'),
+ 'bootstrap' => DRUSH_BOOTSTRAP_DRUPAL_FULL,
+ // Although we're a provision command, we require hostmaster to be around to
+ // run the tests correctly
+ 'drupal dependencies' => array(
+ 'hosting',
+ ),
+ );
+
+ return $items;
+}
+
+/**
+ * Drush command to run the provision tests.
+ */
+function drush_provision_tests_run() {
+ if (!drush_confirm(dt('This command should only be run on a clean Aegir install, and data may be lost! Do you want to continue?'))) {
+ return drush_user_abort();
+ }
+ drush_provision_tests_install_platform('drupal5');
+ drush_provision_tests_install_platform('drupal6');
+ drush_provision_tests_install_platform('drupal7');
+ drush_provision_tests_install_platform('openatrium');
+
+ // Install some sites.
+ drush_provision_tests_install_site('drupal5', 'default');
+ drush_provision_tests_install_site('drupal6', 'default');
+ drush_provision_tests_install_site('drupal7', 'standard');
+ drush_provision_tests_install_site('openatrium', 'openatrium');
+
+ // Remove the sites.
+ drush_provision_tests_remove_site('drupal5', 'default');
+ drush_provision_tests_remove_site('drupal6', 'default');
+ drush_provision_tests_remove_site('drupal7', 'standard');
+ drush_provision_tests_remove_site('openatrium', 'openatrium');
+
+ // Clean up a little.
+ drush_provision_tests_remove_platform('drupal5');
+ drush_provision_tests_remove_platform('drupal6');
+ drush_provision_tests_remove_platform('drupal7');
+ drush_provision_tests_remove_platform('openatrium');
+
+ if (drush_get_error() != DRUSH_SUCCESS) {
+ return drush_set_error(drush_get_error(), 'Running tests failed');
+ }
+}
+
+/**
+ * Helper function to install a platform.
+ */
+function drush_provision_tests_install_platform($platform_name) {
+ $args = array(
+ PROVISION_TESTS_BUILDS_REPO . "/$platform_name.build",
+ "/var/aegir/platforms/$platform_name"
+ );
+ drush_backend_invoke('make', $args);
+ $args = array(
+ 'root' => "/var/aegir/platforms/$platform_name",
+ "@platform_$platform_name",
+ 'context_type' => 'platform',
+ );
+ drush_backend_invoke('provision-save', $args);
+ provision_backend_invoke('@hostmaster', 'hosting-import', array("@platform_$platform_name",));
+ drush_provision_tests_run_remaining_tasks();
+}
+
+/**
+ * Helper function to remove a platform.
+ */
+function drush_provision_tests_remove_platform($platform_name) {
+ provision_backend_invoke('@hostmaster', 'hosting-task', array("@platform_$platform_name", 'delete'));
+ drush_provision_tests_run_remaining_tasks();
+}
+
+/**
+ * Helper function to install a site.
+ */
+function drush_provision_tests_install_site($platform_name, $profile_name) {
+ $args = array(
+ 'uri' => "$platform_name.mig5.net",
+ "@$platform_name.mig5.net",
+ 'context_type' => 'site',
+ 'platform' => "@platform_$platform_name",
+ 'profile' => $profile_name,
+ 'db_server' => '@server_localhost',
+ 'root' => "/var/aegir/platforms/$platform_name",
+ );
+ drush_backend_invoke('provision-save', $args);
+ provision_backend_invoke("@$platform_name.mig5.net", 'provision-install');
+ provision_backend_invoke('@hostmaster', 'hosting-task', array("@platform_$platform_name", 'verify'));
+ drush_provision_tests_run_remaining_tasks();
+}
+
+/**
+ * Helper function to delete a site.
+ */
+function drush_provision_tests_remove_site($platform_name, $profile_name) {
+ provision_backend_invoke('@hostmaster', 'hosting-task', array("@$platform_name.mig5.net", 'delete'));
+ drush_provision_tests_run_remaining_tasks();
+}
+
+/**
+ * Run all remaining hosting tasks.
+ */
+function drush_provision_tests_run_remaining_tasks() {
+ $tasks = array();
+ $result = db_query("SELECT t.nid FROM {hosting_task} t INNER JOIN {node} n ON t.vid = n.vid WHERE t.task_status = %d ORDER BY n.changed, n.nid ASC", 0);
+ while ($node = db_fetch_object($result)) {
+ $tasks[$node->nid] = node_load($node->nid);
+ }
+
+ foreach ($tasks as $task) {
+ provision_backend_invoke('@hostmaster', "hosting-task", array($task->nid));
+ }
+}
+