You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by ts...@apache.org on 2013/10/22 08:33:36 UTC

[2/2] git commit: updated refs/heads/master to dfa0678

marvin: a1b979da8 breaks formatting and pep8.

setup/dev/advanced.cfg is used by the simulator deployments that are
usually not https. disabled the http within this config file.

Signed-off-by: Prasanna Santhanam <ts...@apache.org>


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/dfa0678f
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/dfa0678f
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/dfa0678f

Branch: refs/heads/master
Commit: dfa0678fc6edebd79da12206f843264219962988
Parents: a1b979d
Author: Prasanna Santhanam <ts...@apache.org>
Authored: Tue Oct 22 11:50:42 2013 +0530
Committer: Prasanna Santhanam <ts...@apache.org>
Committed: Tue Oct 22 11:59:14 2013 +0530

----------------------------------------------------------------------
 setup/dev/advanced.cfg                      |   6 +-
 tools/marvin/marvin/cloudstackConnection.py | 100 ++++++++++++-----------
 tools/marvin/marvin/cloudstackTestClient.py |  10 ++-
 tools/marvin/marvin/configGenerator.py      |   6 +-
 tools/marvin/marvin/deployDataCenter.py     |  27 +++---
 5 files changed, 77 insertions(+), 72 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/dfa0678f/setup/dev/advanced.cfg
----------------------------------------------------------------------
diff --git a/setup/dev/advanced.cfg b/setup/dev/advanced.cfg
index dfaba00..216314f 100644
--- a/setup/dev/advanced.cfg
+++ b/setup/dev/advanced.cfg
@@ -220,9 +220,9 @@
             "user": "root",
             "port": 8096,
             "hypervisor": "simulator",
-       "useHttps": "True",
-       "certCAPath":  "NA",
-       "certPath":  "NA"
+            "useHttps": "False",
+            "certCAPath":  "NA",
+            "certPath":  "NA"
         }
     ]
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/dfa0678f/tools/marvin/marvin/cloudstackConnection.py
----------------------------------------------------------------------
diff --git a/tools/marvin/marvin/cloudstackConnection.py b/tools/marvin/marvin/cloudstackConnection.py
index a8f8d71..df88fa2 100644
--- a/tools/marvin/marvin/cloudstackConnection.py
+++ b/tools/marvin/marvin/cloudstackConnection.py
@@ -35,7 +35,8 @@ class cloudConnection(object):
 
     """ Connections to make API calls to the cloudstack management server
     """
-    def __init__(self, mgmtDet,asyncTimeout=3600, logging=None, scheme='http',path='client/api'):
+    def __init__(self, mgmtDet, asyncTimeout=3600, logging=None,
+                 scheme='http', path='client/api'):
         self.loglevel()  # Turn off requests logs
         self.apiKey = mgmtDet.apiKey
         self.securityKey = mgmtDet.securityKey
@@ -43,19 +44,19 @@ class cloudConnection(object):
         self.port = mgmtDet.port
         self.user = mgmtDet.user
         self.passwd = mgmtDet.passwd
-   self.certCAPath = mgmtDet.certCAPath
-   self.certPath = mgmtDet.certPath
+        self.certCAPath = mgmtDet.certCAPath
+        self.certPath = mgmtDet.certPath
         self.logging = logging
         self.path = path
         self.retries = 5
-   self.protocol = "http"
+        self.protocol = scheme
         self.asyncTimeout = asyncTimeout
         self.auth = True
         if self.port == 8096 or \
            (self.apiKey is None and self.securityKey is None):
             self.auth = False
         if mgmtDet.useHttps == "True":
-           self.protocol = "https"
+            self.protocol = "https"
         self.baseurl = "%s://%s:%d/%s"\
                        % (self.protocol, self.mgtSvr, self.port, self.path)
 
@@ -143,52 +144,53 @@ class cloudConnection(object):
             payload["signature"] = signature
 
         try:
-       '''
-       https_flag : Signifies whether to verify connection over http or https, if set to true uses https otherwise http
-       cert_path  : Signifies ca and cert path required by requests library for the connection
-       '''
-       https_flag  = False
-       cert_path    = ()
-       if self.protocol == "https":
-       https_flag = True
-           if self.certCAPath != "NA" and self.certPath  != "NA":
-           cert_path = ( self.certCAPath,self.certPath )
-
-       '''
-       Verify whether protocol is "http", then call the request over http
-            '''
-       if self.protocol == "http":
-               if method == 'POST':
-                   response = requests.post(self.baseurl, params=payload, verify=https_flag)
-               else:
-                   response = requests.get(self.baseurl, params=payload,  verify=https_flag)
+        #https_flag : whether https enabled or not
+        #cert_path  : ca and cert paths of the https connection
+            https_flag = False
+            cert_path = ()
+            if self.protocol == "https":
+                https_flag = True
+                if self.certCAPath != "NA" and self.certPath != "NA":
+                    cert_path = (self.certCAPath, self.certPath)
+            #Verify whether protocol is "http", then call the request over http
+            if self.protocol == "http":
+                if method == 'POST':
+                    response = requests.post(self.baseurl, params=payload,
+                                             verify=https_flag)
+                else:
+                    response = requests.get(self.baseurl, params=payload,
+                                            verify=https_flag)
             else:
-       exception_check = False
-       exception_info  = None
-           '''
-       If protocol is https, then request the url with user provided certificates provided as part of cert
-       '''
-           try:
-                   if method == 'POST':
-                       response = requests.post(self.baseurl, params=payload, cert=cert_path, verify=https_flag)
-                   else:
-                       response = requests.get(self.baseurl, params=payload,  cert=cert_path, verify=https_flag)
-           except Exception,e:
-           '''
-           If an exception occurs with current CA certs, then try with default certs path, we dont need to mention here the cert path
-           '''
-           self.logging.debug( "Creating CS connection over https didnt worked with user provided certs %s"%e )
-           exception_check  = True
-           exception_info = e
-           if method == 'POST':
-                               response = requests.post(self.baseurl, params=payload, verify=https_flag)
-                   else:
-                               response = requests.get(self.baseurl, params=payload,  verify=https_flag)
-       finally:
-           if exception_check == True and exception_info is not None:
-               raise exception_info
+                exception_check = False
+                exception_info = None
+                #use user provided CA certs for request
+                try:
+                    if method == 'POST':
+                        response = requests.post(self.baseurl, params=payload,
+                                                 cert=cert_path,
+                                                 verify=https_flag)
+                    else:
+                        response = requests.get(self.baseurl, params=payload,
+                                                cert=cert_path,
+                                                verify=https_flag)
+                except Exception, e:
+                    # attempt a connection using default certs
+                    self.logging.debug("connection failed using provided certs"
+                                       " because of %s" % e)
+                    exception_check = True
+                    exception_info = e
+                    if method == 'POST':
+                        response = requests.post(self.baseurl, params=payload,
+                                                 verify=https_flag)
+                    else:
+                        response = requests.get(self.baseurl, params=payload,
+                                                verify=https_flag)
+                finally:
+                    if exception_check and exception_info is not None:
+                        raise exception_info
         except ConnectionError, c:
-            self.logging.debug("Connection refused. Reason: %s : %s" %(self.baseurl, c))
+            self.logging.debug("Connection refused."
+                               " Reason: %s : %s" % (self.baseurl, c))
             raise c
         except HTTPError, h:
             self.logging.debug("Server returned error code: %s" % h)

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/dfa0678f/tools/marvin/marvin/cloudstackTestClient.py
----------------------------------------------------------------------
diff --git a/tools/marvin/marvin/cloudstackTestClient.py b/tools/marvin/marvin/cloudstackTestClient.py
index 807633c..5dcd8bf 100644
--- a/tools/marvin/marvin/cloudstackTestClient.py
+++ b/tools/marvin/marvin/cloudstackTestClient.py
@@ -25,9 +25,11 @@ import hashlib
 
 
 class cloudstackTestClient(object):
-    def __init__(self,mgmtDetails,asyncTimeout=3600,defaultWorkerThreads=10, logging=None):
+    def __init__(self, mgmtDetails, asyncTimeout=3600,
+                 defaultWorkerThreads=10, logging=None):
         self.connection = \
-            cloudstackConnection.cloudConnection( mgmtDetails,asyncTimeout,logging)
+            cloudstackConnection.cloudConnection(mgmtDetails, asyncTimeout,
+                                                 logging)
         self.apiClient =\
             cloudstackAPIClient.CloudStackAPIClient(self.connection)
         self.dbConnection = None
@@ -46,8 +48,8 @@ class cloudstackTestClient(object):
 
     def dbConfigure(self, host="localhost", port=3306, user='cloud',
                     passwd='cloud', db='cloud'):
-        self.dbConnection = dbConnection.dbConnection(host, port, user, passwd,
-                                                      db)
+        self.dbConnection = dbConnection.dbConnection(host, port,
+                                                      user, passwd, db)
 
     def isAdminContext(self):
         """

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/dfa0678f/tools/marvin/marvin/configGenerator.py
----------------------------------------------------------------------
diff --git a/tools/marvin/marvin/configGenerator.py b/tools/marvin/marvin/configGenerator.py
index f0e303e..45c3d69 100644
--- a/tools/marvin/marvin/configGenerator.py
+++ b/tools/marvin/marvin/configGenerator.py
@@ -27,9 +27,9 @@ class managementServer(object):
         self.port = 8096
         self.apiKey = None
         self.securityKey = None
-   self.useHttps = None
-   self.certCAPath = None
-   self.certPath = None
+        self.certCAPath = None
+        self.useHttps = None
+        self.certPath = None
 
 
 class dbServer(object):

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/dfa0678f/tools/marvin/marvin/deployDataCenter.py
----------------------------------------------------------------------
diff --git a/tools/marvin/marvin/deployDataCenter.py b/tools/marvin/marvin/deployDataCenter.py
index afba8e6..6b5f64b 100644
--- a/tools/marvin/marvin/deployDataCenter.py
+++ b/tools/marvin/marvin/deployDataCenter.py
@@ -32,7 +32,7 @@ class deployDataCenters(object):
         if not path.exists(cfgFile) \
            and not path.exists(path.abspath(cfgFile)):
             raise IOError("config file %s not found. please \
-specify a valid config file" % cfgFile)
+                            specify a valid config file" % cfgFile)
         self.configFile = cfgFile
 
     def addHosts(self, hosts, zoneId, podId, clusterId, hypervisor):
@@ -512,7 +512,8 @@ specify a valid config file" % cfgFile)
         try:
             self.config = configGenerator.get_setup_config(self.configFile)
         except:
-            raise cloudstackException.InvalidParameterException("Failed to load config %s" % self.configFile)
+            raise cloudstackException.InvalidParameterException(
+                "Failed to load config %s" % self.configFile)
 
         mgtDetails = self.config.mgtSvr[0]
         loggers = self.config.logger
@@ -532,27 +533,28 @@ specify a valid config file" % cfgFile)
         if testClientLogFile is not None:
             testClientLogger = logging.getLogger("testclient.testengine.run")
             fh = logging.FileHandler(testClientLogFile)
-            fh.setFormatter(logging.
-            Formatter("%(asctime)s - %(levelname)s - %(name)s\
-           - %(message)s"))
+            fh.setFormatter(logging.Formatter(
+                "%(asctime)s - %(levelname)s - %(name)s\ - %(message)s")
+            )
             testClientLogger.addHandler(fh)
             testClientLogger.setLevel(logging.INFO)
         self.testClientLogger = testClientLogger
 
         self.testClient = \
-            cloudstackTestClient.\
-            cloudstackTestClient( mgtDetails,logging=self.testClientLogger)
+            cloudstackTestClient.cloudstackTestClient(
+                mgtDetails, logging=self.testClientLogger)
 
         if mgtDetails.apiKey is None:
-           mgtDetails.apiKey,mgtDetails.securityKey = self.registerApiKey()
-           mgtDetails.port  = 8080
-                self.testClient = cloudstackTestClient.cloudstackTestClient( mgtDetails,logging=self.testClientLogger)
+            mgtDetails.apiKey, mgtDetails.securityKey = self.registerApiKey()
+            mgtDetails.port = 8080
+            self.testClient = cloudstackTestClient.cloudstackTestClient(
+                mgtDetails, logging=self.testClientLogger)
 
         """config database"""
         dbSvr = self.config.dbSvr
         if dbSvr is not None:
-            self.testClient.dbConfigure(dbSvr.dbSvr, dbSvr.port, dbSvr.user, \
-                                        dbSvr.passwd, dbSvr.db)
+            self.testClient.dbConfigure(
+                dbSvr.dbSvr, dbSvr.port, dbSvr.user, dbSvr.passwd, dbSvr.db)
 
         self.apiClient = self.testClient.getApiClient()
         """set hypervisor"""
@@ -561,7 +563,6 @@ specify a valid config file" % cfgFile)
         else:
             self.apiClient.hypervisor = "XenServer"  # Defaults to Xenserver
 
-
     def updateConfiguration(self, globalCfg):
         if globalCfg is None:
             return None