From cf33be4596bf3fb784fbeaaea58a934b139ead0e Mon Sep 17 00:00:00 2001 From: Joshua Tauberer Date: Thu, 26 Nov 2015 14:47:49 +0000 Subject: [PATCH] fix boto 2 conflict on Google Compute Engine instances GCE installs some Python-2-only boto plugin that conflicts with boto running under Python 3. It gives a SyntaxError in /usr/share/google/boto/boto_plugins/compute_auth.py (https://github.com/GoogleCloudPlatform/compute-image-packages). Disabling boto's default configuration file prior to importing boto so that GCE's plugin is not loaded. See https://discourse.mailinabox.email/t/500-internal-server-error-for-admin/942. --- CHANGELOG.md | 1 + management/backup.py | 3 ++- management/daemon.py | 1 + management/utils.py | 8 ++++++++ 4 files changed, 12 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5fec01d..b762247 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,6 +22,7 @@ System: * If ownCloud sends out email, it will use the box's administrative address now (admin@yourboxname). * Z-Push (Exchange/ActiveSync) logs now exclude warnings and are now rotated to save disk space. * Fix pip command that might have not installed all necessary Python packages. +* The control panel and backup would not work on Google Compute Engine because they install a conflicting boto package. v0.14 (November 4, 2015) ------------------------ diff --git a/management/backup.py b/management/backup.py index aebfbbc..63b8aa6 100755 --- a/management/backup.py +++ b/management/backup.py @@ -12,7 +12,7 @@ import os, os.path, shutil, glob, re, datetime import dateutil.parser, dateutil.relativedelta, dateutil.tz import rtyaml -from utils import exclusive_process, load_environment, shell, wait_for_service +from utils import exclusive_process, load_environment, shell, wait_for_service, fix_boto def backup_status(env): # Root folder @@ -326,6 +326,7 @@ def list_target_files(config): elif p.scheme == "s3": # match to a Region + fix_boto() # must call prior to importing boto import boto.s3 from boto.exception import BotoServerError for region in boto.s3.regions(): diff --git a/management/daemon.py b/management/daemon.py index 9b71b61..32bbcc5 100755 --- a/management/daemon.py +++ b/management/daemon.py @@ -94,6 +94,7 @@ def index(): no_users_exist = (len(get_mail_users(env)) == 0) no_admins_exist = (len(get_admins(env)) == 0) + utils.fix_boto() # must call prior to importing boto import boto.s3 backup_s3_hosts = [(r.name, r.endpoint) for r in boto.s3.regions()] diff --git a/management/utils.py b/management/utils.py index 9e628fd..b77b748 100644 --- a/management/utils.py +++ b/management/utils.py @@ -245,6 +245,14 @@ def wait_for_service(port, public, env, timeout): return False time.sleep(min(timeout/4, 1)) +def fix_boto(): + # Google Compute Engine instances install some Python-2-only boto plugins that + # conflict with boto running under Python 3. Disable boto's default configuration + # file prior to importing boto so that GCE's plugin is not loaded: + import os + os.environ["BOTO_CONFIG"] = "/etc/boto3.cfg" + + if __name__ == "__main__": from dns_update import get_dns_domains from web_update import get_web_domains, get_default_www_redirects