From b006c993f32d4fc6a337d706e1f6b02b503d390e Mon Sep 17 00:00:00 2001 From: Prasanna Santhanam Date: Wed, 2 Oct 2013 11:28:44 +0530 Subject: [PATCH] marvin_refactor: exception handle for non-standard libraries non-standard python libraries that are not installed by default on python installations need to be exception handled appropriately Signed-off-by: Prasanna Santhanam --- tools/marvin/marvin/TestCaseExecuteEngine.py | 5 ++++- tools/marvin/marvin/cloudstackConnection.py | 13 ++++++++----- tools/marvin/marvin/dbConnection.py | 11 ++++++----- tools/marvin/marvin/remoteSSHClient.py | 1 - tools/marvin/marvin/util.py | 1 - 5 files changed, 18 insertions(+), 13 deletions(-) diff --git a/tools/marvin/marvin/TestCaseExecuteEngine.py b/tools/marvin/marvin/TestCaseExecuteEngine.py index 6495000af3b..c9796b88503 100644 --- a/tools/marvin/marvin/TestCaseExecuteEngine.py +++ b/tools/marvin/marvin/TestCaseExecuteEngine.py @@ -15,7 +15,10 @@ # specific language governing permissions and limitations # under the License. -import unittest2 as unittest +try: + import unittest2 as unittest +except ImportError: + import unittest import os import sys import logging diff --git a/tools/marvin/marvin/cloudstackConnection.py b/tools/marvin/marvin/cloudstackConnection.py index 0337b8658c4..9dfc58b1e5e 100644 --- a/tools/marvin/marvin/cloudstackConnection.py +++ b/tools/marvin/marvin/cloudstackConnection.py @@ -15,7 +15,14 @@ # specific language governing permissions and limitations # under the License. -import requests +try: + import requests + from requests import ConnectionError + from requests import HTTPError + from requests import Timeout + from requests import RequestException +except ImportError: + raise Exception("requests installation not found. use pip install requests to continue") import urllib import base64 import hmac @@ -25,10 +32,6 @@ import time from marvin import cloudstackException from marvin.cloudstackAPI import * from marvin import jsonHelper -from requests import ConnectionError -from requests import HTTPError -from requests import Timeout -from requests import RequestException class CloudConnection(object): diff --git a/tools/marvin/marvin/dbConnection.py b/tools/marvin/marvin/dbConnection.py index 99014abfa20..98c72c50595 100644 --- a/tools/marvin/marvin/dbConnection.py +++ b/tools/marvin/marvin/dbConnection.py @@ -15,13 +15,14 @@ # specific language governing permissions and limitations # under the License. -import mysql +try: + import mysql + from mysql import connector + from mysql.connector import errors +except ImportError: + raise Exception("mysql-connector-python not installed. pip install mysql-connector-python to continue") import contextlib -from mysql import connector -from mysql.connector import errors -from contextlib import closing import cloudstackException -import sys import os diff --git a/tools/marvin/marvin/remoteSSHClient.py b/tools/marvin/marvin/remoteSSHClient.py index fea9b125d19..d64c82deaa4 100644 --- a/tools/marvin/marvin/remoteSSHClient.py +++ b/tools/marvin/marvin/remoteSSHClient.py @@ -20,7 +20,6 @@ import time import cloudstackException import contextlib import logging -from contextlib import closing class remoteSSHClient(object): diff --git a/tools/marvin/marvin/util.py b/tools/marvin/marvin/util.py index 9a97c9d2f8a..609e696ec11 100644 --- a/tools/marvin/marvin/util.py +++ b/tools/marvin/marvin/util.py @@ -19,7 +19,6 @@ from marvin.entity.template import Template from marvin.entity.zone import Zone from marvin.entity.serviceoffering import ServiceOffering from marvin.entity.domain import Domain -from marvin.entity.guestos import GuestOS def get_domain(apiclient): "Returns a default `ROOT` domain"