Return-Path: X-Original-To: apmail-incubator-cloudstack-dev-archive@minotaur.apache.org Delivered-To: apmail-incubator-cloudstack-dev-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id BEC1DD7EA for ; Sat, 20 Oct 2012 22:29:45 +0000 (UTC) Received: (qmail 31102 invoked by uid 500); 20 Oct 2012 22:29:45 -0000 Delivered-To: apmail-incubator-cloudstack-dev-archive@incubator.apache.org Received: (qmail 31012 invoked by uid 500); 20 Oct 2012 22:29:45 -0000 Mailing-List: contact cloudstack-dev-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: cloudstack-dev@incubator.apache.org Delivered-To: mailing list cloudstack-dev@incubator.apache.org Received: (qmail 31003 invoked by uid 99); 20 Oct 2012 22:29:45 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 20 Oct 2012 22:29:45 +0000 X-ASF-Spam-Status: No, hits=-0.0 required=5.0 tests=RCVD_IN_DNSWL_LOW,SPF_NEUTRAL X-Spam-Check-By: apache.org Received-SPF: neutral (nike.apache.org: local policy) Received: from [209.85.216.175] (HELO mail-qc0-f175.google.com) (209.85.216.175) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 20 Oct 2012 22:29:39 +0000 Received: by mail-qc0-f175.google.com with SMTP id j3so850306qcs.6 for ; Sat, 20 Oct 2012 15:29:17 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type:x-gm-message-state; bh=LQnR44BT9VIu85l1uYWkPWTHHhO6SKjGCyJY5W0wfBs=; b=deyp4se9vq4rMQwOwGzw0N9F60Twl9WC9kEJmNEmDkiFD7jbkVAhy+EQzDXJJKjXPI n1sKDHeOfDm/3shxYVh8uU0kUhelJNvCoSme17GTcC3L7OPi35YxObRmf4MKCLY1+RGg xvQVG3WJxsg0rWbAp1khwddF4b8AgYHEc16FkJfoNhzoCbLs3XoKZ8l+T9yzDXiZlXk/ vCwnzvzV5gS+jkYUGB+TBk+Az6qmd1eOwmLHDIFNM6wWsgLYjXNpQ0vYWZwZJqqD78m0 Rj85aPeNjDERSED9qoAgw8Yz+mMdRGz2hyxS1C+y+3QslEWDr9SYVXnzHjt7N/hIURXL MlLw== Received: by 10.224.207.8 with SMTP id fw8mr2383152qab.92.1350772157281; Sat, 20 Oct 2012 15:29:17 -0700 (PDT) MIME-Version: 1.0 Received: by 10.49.97.200 with HTTP; Sat, 20 Oct 2012 15:28:57 -0700 (PDT) In-Reply-To: <20121020114954.2E40919468@tyr.zones.apache.org> References: <20121020114954.2E40919468@tyr.zones.apache.org> From: David Nalley Date: Sat, 20 Oct 2012 18:28:57 -0400 Message-ID: Subject: Re: [2/2] git commit: Summary: Replace pymysql in marvin with a stable mysql-connector-python To: cloudstack-dev@incubator.apache.org Content-Type: text/plain; charset=ISO-8859-1 X-Gm-Message-State: ALoCoQlzaWpWJvUSFTMX+vZgLq07i+iODZo8K1Z9fJkha3Vvwa16CPHDwcVkWdOUHmlZMD9eEthU X-Virus-Checked: Checked by ClamAV on apache.org Prasanna: You are changing dependencies here - this needs to be brought up and discussed (and potentially documented.) What are the licensing implications of this move? --David On Sat, Oct 20, 2012 at 7:49 AM, wrote: > Summary: Replace pymysql in marvin with a stable mysql-connector-python > > Detail: mysql-connector-python developed by Oracle will replace the MIT > licensed pymysql. mysql-connector-python is developed by Oracle and is > more favourable, faster and actively developed. > > With this commit - the dbConnection object is also auto managed by > contextlib. Each transaction requests its own connection rather than > sharing one single connection for all the test runs. > > BUG-ID : None > Reviewed-by: timeit comparison of pymysql and mysql-connector-python > Reported-by: dbExceptions and timeouts from Marvin test runs > Signed-off-by: Prasanna Santhanam 1350732083 +0530 > > > Project: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/repo > Commit: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/commit/355b1529 > Tree: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/tree/355b1529 > Diff: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/diff/355b1529 > > Branch: refs/heads/master > Commit: 355b15299323482af06f0e8f0cb32b4d954d9ea2 > Parents: c63f4ea > Author: Prasanna Santhanam > Authored: Sat Oct 20 16:50:51 2012 +0530 > Committer: Prasanna Santhanam > Committed: Sat Oct 20 16:57:06 2012 +0530 > > ---------------------------------------------------------------------- > tools/marvin/marvin/dbConnection.py | 63 +++++++++++------------------- > tools/marvin/setup.py | 2 +- > 2 files changed, 24 insertions(+), 41 deletions(-) > ---------------------------------------------------------------------- > > > http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/355b1529/tools/marvin/marvin/dbConnection.py > ---------------------------------------------------------------------- > diff --git a/tools/marvin/marvin/dbConnection.py b/tools/marvin/marvin/dbConnection.py > index 1992f80..eb01d73 100644 > --- a/tools/marvin/marvin/dbConnection.py > +++ b/tools/marvin/marvin/dbConnection.py > @@ -15,59 +15,42 @@ > # specific language governing permissions and limitations > # under the License. > > -import pymysql > +import mysql > +import contextlib > +from mysql import connector > +from mysql.connector import errors > +from contextlib import closing > import cloudstackException > import sys > import os > -import traceback > + > class dbConnection(object): > def __init__(self, host="localhost", port=3306, user='cloud', passwd='cloud', db='cloud'): > self.host = host > self.port = port > - self.user = user > + self.user = str(user) #Workaround: http://bugs.mysql.com/?id=67306 > self.passwd = passwd > self.database = db > > - try: > - self.db = pymysql.Connect(host=host, port=port, user=user, passwd=passwd, db=db) > - except: > - traceback.print_exc() > - raise cloudstackException.InvalidParameterException(sys.exc_info()) > - > - def __copy__(self): > - return dbConnection(self.host, self.port, self.user, self.passwd, self.database) > - > - def close(self): > - try: > - self.db.close() > - except: > - pass > - > - def execute(self, sql=None): > + def execute(self, sql=None, params=None): > if sql is None: > return None > - > + > resultRow = [] > - cursor = None > - try: > - # commit to restart the transaction, else we don't get fresh data > - self.db.commit() > - cursor = self.db.cursor() > - cursor.execute(sql) > - > - result = cursor.fetchall() > - if result is not None: > - for r in result: > - resultRow.append(r) > - return resultRow > - except pymysql.MySQLError, e: > - raise cloudstackException.dbException("db Exception:%s"%e) > - except: > - raise cloudstackException.internalError(sys.exc_info()) > - finally: > - if cursor is not None: > - cursor.close() > - > + with contextlib.closing(mysql.connector.connect(host=self.host, port=self.port, user=self.user, password=self.passwd, db=self.database)) as conn: > + conn.autocommit = True > + with contextlib.closing(conn.cursor(buffered=True)) as cursor: > + cursor.execute(sql, params) > + try: > + result = cursor.fetchall() > + except errors.InterfaceError: > + #Raised on empty result - DML > + result = [] > + if result: > + [resultRow.append(r) for r in result] > + > + return resultRow > + > def executeSqlFromFile(self, fileName=None): > if fileName is None: > raise cloudstackException.InvalidParameterException("file can't not none") > > http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/355b1529/tools/marvin/setup.py > ---------------------------------------------------------------------- > diff --git a/tools/marvin/setup.py b/tools/marvin/setup.py > index c9841f3..118d6ba 100644 > --- a/tools/marvin/setup.py > +++ b/tools/marvin/setup.py > @@ -37,7 +37,7 @@ setup(name="Marvin", > packages=["marvin", "marvin.cloudstackAPI", "marvin.sandbox", "marvin.sandbox.advanced", "marvin.sandbox.basic"], > license="LICENSE.txt", > install_requires=[ > - "pymysql", > + "mysql-connector-python", > "paramiko", > "nose", > "unittest-xml-reporting" >