Skip to content

Commit dfa0678

Browse files
author
Prasanna Santhanam
committed
marvin: a1b979d 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 <tsp@apache.org>
1 parent a1b979d commit dfa0678

5 files changed

Lines changed: 77 additions & 72 deletions

File tree

setup/dev/advanced.cfg

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -220,9 +220,9 @@
220220
"user": "root",
221221
"port": 8096,
222222
"hypervisor": "simulator",
223-
"useHttps": "True",
224-
"certCAPath": "NA",
225-
"certPath": "NA"
223+
"useHttps": "False",
224+
"certCAPath": "NA",
225+
"certPath": "NA"
226226
}
227227
]
228228
}

tools/marvin/marvin/cloudstackConnection.py

Lines changed: 51 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -35,27 +35,28 @@ class cloudConnection(object):
3535

3636
""" Connections to make API calls to the cloudstack management server
3737
"""
38-
def __init__(self, mgmtDet,asyncTimeout=3600, logging=None, scheme='http',path='client/api'):
38+
def __init__(self, mgmtDet, asyncTimeout=3600, logging=None,
39+
scheme='http', path='client/api'):
3940
self.loglevel() # Turn off requests logs
4041
self.apiKey = mgmtDet.apiKey
4142
self.securityKey = mgmtDet.securityKey
4243
self.mgtSvr = mgmtDet.mgtSvrIp
4344
self.port = mgmtDet.port
4445
self.user = mgmtDet.user
4546
self.passwd = mgmtDet.passwd
46-
self.certCAPath = mgmtDet.certCAPath
47-
self.certPath = mgmtDet.certPath
47+
self.certCAPath = mgmtDet.certCAPath
48+
self.certPath = mgmtDet.certPath
4849
self.logging = logging
4950
self.path = path
5051
self.retries = 5
51-
self.protocol = "http"
52+
self.protocol = scheme
5253
self.asyncTimeout = asyncTimeout
5354
self.auth = True
5455
if self.port == 8096 or \
5556
(self.apiKey is None and self.securityKey is None):
5657
self.auth = False
5758
if mgmtDet.useHttps == "True":
58-
self.protocol = "https"
59+
self.protocol = "https"
5960
self.baseurl = "%s://%s:%d/%s"\
6061
% (self.protocol, self.mgtSvr, self.port, self.path)
6162

@@ -143,52 +144,53 @@ def request(self, command, auth=True, payload={}, method='GET'):
143144
payload["signature"] = signature
144145

145146
try:
146-
'''
147-
https_flag : Signifies whether to verify connection over http or https, if set to true uses https otherwise http
148-
cert_path : Signifies ca and cert path required by requests library for the connection
149-
'''
150-
https_flag = False
151-
cert_path = ()
152-
if self.protocol == "https":
153-
https_flag = True
154-
if self.certCAPath != "NA" and self.certPath != "NA":
155-
cert_path = ( self.certCAPath,self.certPath )
156-
157-
'''
158-
Verify whether protocol is "http", then call the request over http
159-
'''
160-
if self.protocol == "http":
161-
if method == 'POST':
162-
response = requests.post(self.baseurl, params=payload, verify=https_flag)
163-
else:
164-
response = requests.get(self.baseurl, params=payload, verify=https_flag)
147+
#https_flag : whether https enabled or not
148+
#cert_path : ca and cert paths of the https connection
149+
https_flag = False
150+
cert_path = ()
151+
if self.protocol == "https":
152+
https_flag = True
153+
if self.certCAPath != "NA" and self.certPath != "NA":
154+
cert_path = (self.certCAPath, self.certPath)
155+
#Verify whether protocol is "http", then call the request over http
156+
if self.protocol == "http":
157+
if method == 'POST':
158+
response = requests.post(self.baseurl, params=payload,
159+
verify=https_flag)
160+
else:
161+
response = requests.get(self.baseurl, params=payload,
162+
verify=https_flag)
165163
else:
166-
exception_check = False
167-
exception_info = None
168-
'''
169-
If protocol is https, then request the url with user provided certificates provided as part of cert
170-
'''
171-
try:
172-
if method == 'POST':
173-
response = requests.post(self.baseurl, params=payload, cert=cert_path, verify=https_flag)
174-
else:
175-
response = requests.get(self.baseurl, params=payload, cert=cert_path, verify=https_flag)
176-
except Exception,e:
177-
'''
178-
If an exception occurs with current CA certs, then try with default certs path, we dont need to mention here the cert path
179-
'''
180-
self.logging.debug( "Creating CS connection over https didnt worked with user provided certs %s"%e )
181-
exception_check = True
182-
exception_info = e
183-
if method == 'POST':
184-
response = requests.post(self.baseurl, params=payload, verify=https_flag)
185-
else:
186-
response = requests.get(self.baseurl, params=payload, verify=https_flag)
187-
finally:
188-
if exception_check == True and exception_info is not None:
189-
raise exception_info
164+
exception_check = False
165+
exception_info = None
166+
#use user provided CA certs for request
167+
try:
168+
if method == 'POST':
169+
response = requests.post(self.baseurl, params=payload,
170+
cert=cert_path,
171+
verify=https_flag)
172+
else:
173+
response = requests.get(self.baseurl, params=payload,
174+
cert=cert_path,
175+
verify=https_flag)
176+
except Exception, e:
177+
# attempt a connection using default certs
178+
self.logging.debug("connection failed using provided certs"
179+
" because of %s" % e)
180+
exception_check = True
181+
exception_info = e
182+
if method == 'POST':
183+
response = requests.post(self.baseurl, params=payload,
184+
verify=https_flag)
185+
else:
186+
response = requests.get(self.baseurl, params=payload,
187+
verify=https_flag)
188+
finally:
189+
if exception_check and exception_info is not None:
190+
raise exception_info
190191
except ConnectionError, c:
191-
self.logging.debug("Connection refused. Reason: %s : %s" %(self.baseurl, c))
192+
self.logging.debug("Connection refused."
193+
" Reason: %s : %s" % (self.baseurl, c))
192194
raise c
193195
except HTTPError, h:
194196
self.logging.debug("Server returned error code: %s" % h)

tools/marvin/marvin/cloudstackTestClient.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,11 @@
2525

2626

2727
class cloudstackTestClient(object):
28-
def __init__(self,mgmtDetails,asyncTimeout=3600,defaultWorkerThreads=10, logging=None):
28+
def __init__(self, mgmtDetails, asyncTimeout=3600,
29+
defaultWorkerThreads=10, logging=None):
2930
self.connection = \
30-
cloudstackConnection.cloudConnection( mgmtDetails,asyncTimeout,logging)
31+
cloudstackConnection.cloudConnection(mgmtDetails, asyncTimeout,
32+
logging)
3133
self.apiClient =\
3234
cloudstackAPIClient.CloudStackAPIClient(self.connection)
3335
self.dbConnection = None
@@ -46,8 +48,8 @@ def identifier(self, id):
4648

4749
def dbConfigure(self, host="localhost", port=3306, user='cloud',
4850
passwd='cloud', db='cloud'):
49-
self.dbConnection = dbConnection.dbConnection(host, port, user, passwd,
50-
db)
51+
self.dbConnection = dbConnection.dbConnection(host, port,
52+
user, passwd, db)
5153

5254
def isAdminContext(self):
5355
"""

tools/marvin/marvin/configGenerator.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ def __init__(self):
2727
self.port = 8096
2828
self.apiKey = None
2929
self.securityKey = None
30-
self.useHttps = None
31-
self.certCAPath = None
32-
self.certPath = None
30+
self.certCAPath = None
31+
self.useHttps = None
32+
self.certPath = None
3333

3434

3535
class dbServer(object):

tools/marvin/marvin/deployDataCenter.py

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def __init__(self, cfgFile):
3232
if not path.exists(cfgFile) \
3333
and not path.exists(path.abspath(cfgFile)):
3434
raise IOError("config file %s not found. please \
35-
specify a valid config file" % cfgFile)
35+
specify a valid config file" % cfgFile)
3636
self.configFile = cfgFile
3737

3838
def addHosts(self, hosts, zoneId, podId, clusterId, hypervisor):
@@ -512,7 +512,8 @@ def loadCfg(self):
512512
try:
513513
self.config = configGenerator.get_setup_config(self.configFile)
514514
except:
515-
raise cloudstackException.InvalidParameterException("Failed to load config %s" % self.configFile)
515+
raise cloudstackException.InvalidParameterException(
516+
"Failed to load config %s" % self.configFile)
516517

517518
mgtDetails = self.config.mgtSvr[0]
518519
loggers = self.config.logger
@@ -532,27 +533,28 @@ def loadCfg(self):
532533
if testClientLogFile is not None:
533534
testClientLogger = logging.getLogger("testclient.testengine.run")
534535
fh = logging.FileHandler(testClientLogFile)
535-
fh.setFormatter(logging.
536-
Formatter("%(asctime)s - %(levelname)s - %(name)s\
537-
- %(message)s"))
536+
fh.setFormatter(logging.Formatter(
537+
"%(asctime)s - %(levelname)s - %(name)s\ - %(message)s")
538+
)
538539
testClientLogger.addHandler(fh)
539540
testClientLogger.setLevel(logging.INFO)
540541
self.testClientLogger = testClientLogger
541542

542543
self.testClient = \
543-
cloudstackTestClient.\
544-
cloudstackTestClient( mgtDetails,logging=self.testClientLogger)
544+
cloudstackTestClient.cloudstackTestClient(
545+
mgtDetails, logging=self.testClientLogger)
545546

546547
if mgtDetails.apiKey is None:
547-
mgtDetails.apiKey,mgtDetails.securityKey = self.registerApiKey()
548-
mgtDetails.port = 8080
549-
self.testClient = cloudstackTestClient.cloudstackTestClient( mgtDetails,logging=self.testClientLogger)
548+
mgtDetails.apiKey, mgtDetails.securityKey = self.registerApiKey()
549+
mgtDetails.port = 8080
550+
self.testClient = cloudstackTestClient.cloudstackTestClient(
551+
mgtDetails, logging=self.testClientLogger)
550552

551553
"""config database"""
552554
dbSvr = self.config.dbSvr
553555
if dbSvr is not None:
554-
self.testClient.dbConfigure(dbSvr.dbSvr, dbSvr.port, dbSvr.user, \
555-
dbSvr.passwd, dbSvr.db)
556+
self.testClient.dbConfigure(
557+
dbSvr.dbSvr, dbSvr.port, dbSvr.user, dbSvr.passwd, dbSvr.db)
556558

557559
self.apiClient = self.testClient.getApiClient()
558560
"""set hypervisor"""
@@ -561,7 +563,6 @@ def loadCfg(self):
561563
else:
562564
self.apiClient.hypervisor = "XenServer" # Defaults to Xenserver
563565

564-
565566
def updateConfiguration(self, globalCfg):
566567
if globalCfg is None:
567568
return None

0 commit comments

Comments
 (0)