Skip to content

Commit fba8741

Browse files
Santhosh EdukullaGirish Shilamkar
authored andcommitted
Adding few changes and cleaning up the code
- Added few common naming conventions - Cleanedup code - Added a simple utility function Signed-off-by: Santhosh Edukulla <Santhosh.Edukulla@citrix.com> Conflicts: tools/marvin/marvin/codes.py tools/marvin/marvin/integration/lib/utils.py
1 parent 6e1821f commit fba8741

5 files changed

Lines changed: 33 additions & 45 deletions

File tree

‎tools/marvin/marvin/codes.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
a code viz., ENABLED with value "Enabled",then using \
2525
this code in a sample feature say test_a.py as below. \
2626
27-
from marvinCodes import *
27+
from codes import *
2828
if obj.getvalue() == ENABLED
2929
3030
@DateAdded: 20th October 2013

‎tools/marvin/marvin/configGenerator.py‎

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -951,7 +951,7 @@ def generate_setup_config(config, file=None):
951951
fp.close()
952952

953953

954-
def get_setup_config(file):
954+
def getSetupConfig(file):
955955
if not os.path.exists(file):
956956
raise IOError("config file %s not found. \
957957
please specify a valid config file" % file)
@@ -962,9 +962,7 @@ def get_setup_config(file):
962962
ws = line.strip()
963963
if not ws.startswith("#"):
964964
configLines.append(ws)
965-
k = json.loads("\n".join(configLines))
966-
#config = json.loads("\n".join(configLines))
967-
config = k
965+
config = json.loads("\n".join(configLines))
968966
return jsonHelper.jsonLoader(config)
969967

970968
if __name__ == "__main__":
@@ -985,7 +983,7 @@ def get_setup_config(file):
985983
(options, args) = parser.parse_args()
986984

987985
if options.inputfile:
988-
config = get_setup_config(options.inputfile)
986+
config = getSetupConfig(options.inputfile)
989987
if options.advanced:
990988
config = descSetupInAdvancedMode()
991989
elif options.advancedsg:

‎tools/marvin/marvin/deployDataCenter.py‎

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,11 @@ def createClusters(self, clusters, zoneId, podId, vmwareDc=None):
8888
if cluster.hypervisor.lower() != "vmware":
8989
self.addHosts(cluster.hosts, zoneId, podId, clusterId,
9090
cluster.hypervisor)
91-
self.wait_for_host(zoneId, clusterId)
91+
self.waitForHost(zoneId, clusterId)
9292
self.createPrimaryStorages(cluster.primaryStorages, zoneId, podId,
9393
clusterId)
9494

95-
def wait_for_host(self, zoneId, clusterId):
95+
def waitForHost(self, zoneId, clusterId):
9696
"""
9797
Wait for the hosts in the zoneid, clusterid to be up
9898
@@ -123,7 +123,7 @@ def createPrimaryStorages(self, primaryStorages, zoneId, podId, clusterId):
123123
primarycmd.clusterid = clusterId
124124
self.apiClient.createStoragePool(primarycmd)
125125

126-
def createpods(self, pods, zoneId, networkId=None):
126+
def createPods(self, pods, zoneId, networkId=None):
127127
if pods is None:
128128
return
129129
for pod in pods:
@@ -208,7 +208,7 @@ def createCacheStorages(self, cacheStorages, zoneId):
208208
})
209209
self.apiClient.createSecondaryStagingStore(cachecmd)
210210

211-
def createnetworks(self, networks, zoneId):
211+
def createNetworks(self, networks, zoneId):
212212
if networks is None:
213213
return
214214
for network in networks:
@@ -417,16 +417,16 @@ def createZones(self, zones):
417417
guestntwrk.networkofferingid = \
418418
listnetworkofferingresponse[0].id
419419

420-
networkid = self.createnetworks([guestntwrk], zoneId)
421-
self.createpods(zone.pods, zoneId, networkid)
420+
networkid = self.createNetworks([guestntwrk], zoneId)
421+
self.createPods(zone.pods, zoneId, networkid)
422422
if self.isEipElbZone(zone):
423423
self.createVlanIpRanges(zone.networktype, zone.ipranges,
424424
zoneId, forvirtualnetwork=True)
425425

426426
isPureAdvancedZone = (zone.networktype == "Advanced"
427427
and zone.securitygroupenabled != "true")
428428
if isPureAdvancedZone:
429-
self.createpods(zone.pods, zoneId)
429+
self.createPods(zone.pods, zoneId)
430430
self.createVlanIpRanges(zone.networktype, zone.ipranges,
431431
zoneId)
432432
elif (zone.networktype == "Advanced"
@@ -459,7 +459,7 @@ def createZones(self, zones):
459459

460460
networkcmdresponse = self.apiClient.createNetwork(networkcmd)
461461
networkId = networkcmdresponse.id
462-
self.createpods(zone.pods, zoneId, networkId)
462+
self.createPods(zone.pods, zoneId, networkId)
463463

464464
'''Note: Swift needs cache storage first'''
465465
self.createCacheStorages(zone.cacheStorages, zoneId)
@@ -510,7 +510,7 @@ def getCfg(self):
510510

511511
def loadCfg(self):
512512
try:
513-
self.config = configGenerator.get_setup_config(self.configFile)
513+
self.config = configGenerator.getSetupConfig(self.configFile)
514514
except:
515515
raise cloudstackException.InvalidParameterException("Failed to load config %s" % self.configFile)
516516

‎tools/marvin/marvin/integration/lib/utils.py‎

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import datetime
3131
from marvin.cloudstackAPI import *
3232
from marvin.remoteSSHClient import remoteSSHClient
33+
from marvin.codes import *
3334

3435

3536
def restart_mgmt_server(server):
@@ -321,14 +322,14 @@ def is_snapshot_on_nfs(apiclient, dbconn, config, zoneid, snapshotid):
321322

322323
def validateList(inp):
323324
'''
324-
@name: validateList
325-
@Description: 1. A utility function to validate
325+
@name: validateList
326+
@Description: 1. A utility function to validate
326327
whether the input passed is a list
327-
2. The list is empty or not
328+
2. The list is empty or not
328329
3. If it is list and not empty, return PASS and first element
329330
4. If not reason for FAIL
330-
@Input: Input to be validated
331-
@output: List, containing [ Result,FirstElement,Reason ]
331+
@Input: Input to be validated
332+
@output: List, containing [ Result,FirstElement,Reason ]
332333
Ist Argument('Result') : FAIL : If it is not a list
333334
If it is list but empty
334335
PASS : If it is list and not empty
@@ -339,18 +340,18 @@ def validateList(inp):
339340
default to None.
340341
INVALID_INPUT
341342
EMPTY_LIST
342-
'''
343-
ret = [FAIL, None, None]
344-
if inp is None:
345-
ret[2] = INVALID_INPUT
346-
return ret
347-
if not isinstance(inp, list):
348-
ret[2] = INVALID_INPUT
349-
return ret
350-
if len(inp) == 0:
351-
ret[2] = EMPTY_LIST
352-
return ret
353-
return [PASS, inp[0], None]
343+
'''
344+
ret = [FAIL, None, None]
345+
if inp is None:
346+
ret[2] = INVALID_INPUT
347+
return ret
348+
if not isinstance(inp, list):
349+
ret[2] = INVALID_INPUT
350+
return ret
351+
if len(inp) == 0:
352+
ret[2] = EMPTY_LIST
353+
return ret
354+
return [PASS, inp[0], None]
354355

355356
def verifyElementInList(inp, toverify, pos = 0):
356357
'''

‎tools/marvin/marvin/marvinPlugin.py‎

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,6 @@ class MarvinPlugin(Plugin):
3333
name = "marvin"
3434

3535
def configure(self, options, config):
36-
if hasattr(options, self.enableOpt):
37-
if not getattr(options, self.enableOpt):
38-
self.enabled = False
39-
return
40-
else:
41-
self.enabled = True
42-
4336
self.logformat = logging.Formatter("%(asctime)s - %(levelname)s - " +
4437
"%(name)s - %(message)s")
4538

@@ -59,7 +52,7 @@ def configure(self, options, config):
5952
else:
6053
self.result_stream = sys.stdout
6154

62-
deploy = deployDataCenter.deployDataCenters(options.config)
55+
deploy = deployDataCenter.deployDataCenters(options.config_file)
6356
deploy.loadCfg() if options.load else deploy.deploy()
6457
self.setClient(deploy.testClient)
6558
self.setConfig(deploy.getCfg())
@@ -74,7 +67,7 @@ def options(self, parser, env):
7467
"""
7568
parser.add_option("--marvin-config", action="store",
7669
default=env.get('MARVIN_CONFIG', './datacenter.cfg'),
77-
dest="config",
70+
dest="config_file",
7871
help="Marvin's configuration file where the " +
7972
"datacenter information is specified " +
8073
"[MARVIN_CONFIG]")
@@ -146,10 +139,6 @@ def stopTest(self, test):
146139
str(time.ctime(self.startTime)), str(time.ctime(endTime))))
147140

148141
def _injectClients(self, test):
149-
self.debug_stream. \
150-
setFormatter(logging.
151-
Formatter("%(asctime)s - %(levelname)s - %(name)s" +
152-
" - %(message)s"))
153142
setattr(test, "debug", self.logger.debug)
154143
setattr(test, "info", self.logger.info)
155144
setattr(test, "warn", self.logger.warning)

0 commit comments

Comments
 (0)