From patchwork Fri May 27 04:21:31 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lucas Meneghel Rodrigues X-Patchwork-Id: 822822 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.3) with ESMTP id p4R4Lj10028310 for ; Fri, 27 May 2011 04:21:50 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751525Ab1E0EVq (ORCPT ); Fri, 27 May 2011 00:21:46 -0400 Received: from mx1.redhat.com ([209.132.183.28]:54828 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750777Ab1E0EVp (ORCPT ); Fri, 27 May 2011 00:21:45 -0400 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p4R4Li2r020230 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 27 May 2011 00:21:44 -0400 Received: from justice.redhat.com (vpn-10-216.rdu.redhat.com [10.11.10.216]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id p4R4LaMN004814; Fri, 27 May 2011 00:21:43 -0400 From: Lucas Meneghel Rodrigues To: autotest@test.kernel.org Cc: kvm@vger.kernel.org, Lucas Meneghel Rodrigues Subject: [PATCH 3/6] Adding afe custom database engine Date: Fri, 27 May 2011 01:21:31 -0300 Message-Id: <1306470094-16960-4-git-send-email-lmr@redhat.com> In-Reply-To: <1306470094-16960-1-git-send-email-lmr@redhat.com> References: <1306470094-16960-1-git-send-email-lmr@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.12 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter1.kernel.org [140.211.167.41]); Fri, 27 May 2011 04:21:50 +0000 (UTC) Turns out that we rely on custom code to generate joins that does some trickery with Django ORM system, and was using a method calling get_from_clause, that was present on the Query class on Django 1.1. Now, the method was moved to a class upper in the hierarchy, called SQLCompiler, and SQLCompiler is tied to the db backend being used. After some research, seems like there's no solution cleaner than implementing one db backend special for autotest, just to accomodate this function. So created one db engine that inherits pretty much everything from the mysql one, except for the compiler classes. Tested, and it works fairly well. Eventually more work needs to be put in getting the web app into better shape. Signed-off-by: Lucas Meneghel Rodrigues --- frontend/db/backends/afe/base.py | 22 +++++++++++++++++++ frontend/db/backends/afe/compiler.py | 32 +++++++++++++++++++++++++++++ frontend/db/backends/afe/creation.py | 1 + frontend/db/backends/afe/introspection.py | 1 + frontend/db/backends/afe/validation.py | 1 + 5 files changed, 57 insertions(+), 0 deletions(-) create mode 100644 frontend/db/__init__.py create mode 100644 frontend/db/backends/__init__.py create mode 100644 frontend/db/backends/afe/__init__.py create mode 100644 frontend/db/backends/afe/base.py create mode 100644 frontend/db/backends/afe/compiler.py create mode 100644 frontend/db/backends/afe/creation.py create mode 100644 frontend/db/backends/afe/introspection.py create mode 100644 frontend/db/backends/afe/validation.py diff --git a/frontend/db/__init__.py b/frontend/db/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/frontend/db/backends/__init__.py b/frontend/db/backends/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/frontend/db/backends/afe/__init__.py b/frontend/db/backends/afe/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/frontend/db/backends/afe/base.py b/frontend/db/backends/afe/base.py new file mode 100644 index 0000000..6d617d2 --- /dev/null +++ b/frontend/db/backends/afe/base.py @@ -0,0 +1,22 @@ +from django.db.backends.mysql.base import DatabaseCreation as MySQLCreation +from django.db.backends.mysql.base import DatabaseOperations as MySQLOperations +from django.db.backends.mysql.base import DatabaseWrapper as MySQLDatabaseWrapper +from django.db.backends.mysql.base import DatabaseIntrospection as MySQLIntrospection + +try: + import MySQLdb as Database +except ImportError, e: + from django.core.exceptions import ImproperlyConfigured + raise ImproperlyConfigured("Error loading MySQLdb module: %s" % e) + + +class DatabaseOperations(MySQLOperations): + compiler_module = "autotest_lib.frontend.db.backends.afe.compiler" + + +class DatabaseWrapper(MySQLDatabaseWrapper): + def __init__(self, *args, **kwargs): + super(DatabaseWrapper, self).__init__(*args, **kwargs) + self.creation = MySQLCreation(self) + self.ops = DatabaseOperations() + self.introspection = MySQLIntrospection(self) diff --git a/frontend/db/backends/afe/compiler.py b/frontend/db/backends/afe/compiler.py new file mode 100644 index 0000000..9971415 --- /dev/null +++ b/frontend/db/backends/afe/compiler.py @@ -0,0 +1,32 @@ +from django.db.backends.mysql import compiler as mysql_compiler +from autotest_lib.frontend.afe.model_logic import _quote_name + +class SQLCompiler(mysql_compiler.SQLCompiler): + def get_from_clause(self): + from_, params = super(SQLCompiler, self).get_from_clause() + + if hasattr(self.query, "_custom_joins"): + for join_dict in self.query._custom_joins: + from_.append('%s %s AS %s ON (%s)' + % (join_dict['join_type'], + _quote_name(join_dict['table']), + _quote_name(join_dict['alias']), + join_dict['condition'])) + params.extend(join_dict['condition_values']) + + return from_, params + +class SQLInsertCompiler(mysql_compiler.SQLInsertCompiler, SQLCompiler): + pass + +class SQLDeleteCompiler(mysql_compiler.SQLDeleteCompiler, SQLCompiler): + pass + +class SQLUpdateCompiler(mysql_compiler.SQLUpdateCompiler, SQLCompiler): + pass + +class SQLAggregateCompiler(mysql_compiler.SQLAggregateCompiler, SQLCompiler): + pass + +class SQLDateCompiler(mysql_compiler.SQLDateCompiler, SQLCompiler): + pass diff --git a/frontend/db/backends/afe/creation.py b/frontend/db/backends/afe/creation.py new file mode 100644 index 0000000..955a11e --- /dev/null +++ b/frontend/db/backends/afe/creation.py @@ -0,0 +1 @@ +from django.db.backends.mysql.creation import * diff --git a/frontend/db/backends/afe/introspection.py b/frontend/db/backends/afe/introspection.py new file mode 100644 index 0000000..222bc9b --- /dev/null +++ b/frontend/db/backends/afe/introspection.py @@ -0,0 +1 @@ +from django.db.backends.mysql.introspection import * diff --git a/frontend/db/backends/afe/validation.py b/frontend/db/backends/afe/validation.py new file mode 100644 index 0000000..818b34a --- /dev/null +++ b/frontend/db/backends/afe/validation.py @@ -0,0 +1 @@ +from django.db.backends.mysql.validation import *