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>
This commit is contained in:
Santhosh Edukulla 2013-10-28 12:48:05 +05:30 committed by Prasanna Santhanam
parent c8b91f1b72
commit 03830c570e
5 changed files with 54 additions and 28 deletions

View File

@ -24,7 +24,7 @@
a code viz., ENABLED with value "Enabled",then using \
this code in a sample feature say test_a.py as below. \
from marvinCodes import *
from codes import *
if obj.getvalue() == ENABLED
@DateAdded: 20th October 2013
@ -33,3 +33,7 @@
ENABLED = "Enabled"
NETWORK_OFFERING = "network_offering"
ROOT = "ROOT"
INVALID_INPUT = "INVALID INPUT"
EMPTY_LIST = "EMPTY_LIST"
FAIL = 0
PASS = 1

View File

@ -830,7 +830,7 @@ def generate_setup_config(config, file=None):
fp.close()
def get_setup_config(file):
def getSetupConfig(file):
if not os.path.exists(file):
raise IOError("config file %s not found. \
please specify a valid config file" % file)
@ -841,9 +841,7 @@ def get_setup_config(file):
ws = line.strip()
if not ws.startswith("#"):
configLines.append(ws)
k = json.loads("\n".join(configLines))
#config = json.loads("\n".join(configLines))
config = k
config = json.loads("\n".join(configLines))
return jsonHelper.jsonLoader(config)
if __name__ == "__main__":
@ -864,7 +862,7 @@ by default is ./datacenterCfg")
(options, args) = parser.parse_args()
if options.inputfile:
config = get_setup_config(options.inputfile)
config = getSetupConfig(options.inputfile)
if options.advanced:
config = describe_setup_in_advanced_mode()
elif options.advancedsg:

View File

@ -92,11 +92,11 @@ class deployDataCenters(object):
if cluster.hypervisor.lower() != "vmware":
self.addHosts(cluster.hosts, zoneId, podId, clusterId,
cluster.hypervisor)
self.wait_for_host(zoneId, clusterId)
self.waitForHost(zoneId, clusterId)
self.createPrimaryStorages(cluster.primaryStorages, zoneId, podId,
clusterId)
def wait_for_host(self, zoneId, clusterId):
def waitForHost(self, zoneId, clusterId):
"""
Wait for the hosts in the zoneid, clusterid to be up
@ -127,7 +127,7 @@ class deployDataCenters(object):
primarycmd.clusterid = clusterId
self.apiClient.createStoragePool(primarycmd)
def createpods(self, pods, zoneId, networkId=None):
def createPods(self, pods, zoneId, networkId=None):
if pods is None:
return
for pod in pods:
@ -212,7 +212,7 @@ class deployDataCenters(object):
})
self.apiClient.createSecondaryStagingStore(cachecmd)
def createnetworks(self, networks, zoneId):
def createNetworks(self, networks, zoneId):
if networks is None:
return
for network in networks:
@ -421,8 +421,8 @@ class deployDataCenters(object):
guestntwrk.networkofferingid = \
listnetworkofferingresponse[0].id
networkid = self.createnetworks([guestntwrk], zoneId)
self.createpods(zone.pods, zoneId, networkid)
networkid = self.createNetworks([guestntwrk], zoneId)
self.createPods(zone.pods, zoneId, networkid)
if self.isEipElbZone(zone):
self.createVlanIpRanges(zone.networktype, zone.ipranges,
zoneId, forvirtualnetwork=True)
@ -430,7 +430,7 @@ class deployDataCenters(object):
isPureAdvancedZone = (zone.networktype == "Advanced"
and zone.securitygroupenabled != "true")
if isPureAdvancedZone:
self.createpods(zone.pods, zoneId)
self.createPods(zone.pods, zoneId)
self.createVlanIpRanges(zone.networktype, zone.ipranges,
zoneId)
elif (zone.networktype == "Advanced"
@ -463,7 +463,7 @@ class deployDataCenters(object):
networkcmdresponse = self.apiClient.createNetwork(networkcmd)
networkId = networkcmdresponse.id
self.createpods(zone.pods, zoneId, networkId)
self.createPods(zone.pods, zoneId, networkId)
'''Note: Swift needs cache storage first'''
self.createCacheStorages(zone.cacheStorages, zoneId)
@ -514,7 +514,7 @@ class deployDataCenters(object):
def loadCfg(self):
try:
self.config = configGenerator.get_setup_config(self.configFile)
self.config = configGenerator.getSetupConfig(self.configFile)
except:
raise cloudstackException.InvalidParameterException(
"Failed to load config %s" % self.configFile)

View File

@ -30,6 +30,7 @@ import urlparse
import datetime
from marvin.cloudstackAPI import *
from marvin.remoteSSHClient import remoteSSHClient
from marvin.codes import *
def restart_mgmt_server(server):
@ -318,3 +319,37 @@ def is_snapshot_on_nfs(apiclient, dbconn, config, zoneid, snapshotid):
raise Exception("SSH failed for management server: %s - %s" %
(config.mgtSvr[0].mgtSvrIp, e))
return 'snapshot exists' in result
def validateList(inp):
'''
@name: validateList
@Description: 1. A utility function to validate
whether the input passed is a list
2. The list is empty or not
3. If it is list and not empty, return PASS and first element
4. If not reason for FAIL
@Input: Input to be validated
@output: List, containing [ Result,FirstElement,Reason ]
Ist Argument('Result') : FAIL : If it is not a list
If it is list but empty
PASS : If it is list and not empty
IInd Argument('FirstElement'): If it is list and not empty,
then first element
in it, default to None
IIIrd Argument( 'Reason' ): Reason for failure ( FAIL ),
default to None.
INVALID_INPUT
EMPTY_LIST
'''
ret = [FAIL, None, None]
if inp is None:
ret[2] = INVALID_INPUT
return ret
if not isinstance(inp, list):
ret[2] = INVALID_INPUT
return ret
if len(inp) == 0:
ret[2] = EMPTY_LIST
return ret
return [PASS, inp[0], None]

View File

@ -33,13 +33,6 @@ class MarvinPlugin(Plugin):
name = "marvin"
def configure(self, options, config):
if hasattr(options, self.enableOpt):
if not getattr(options, self.enableOpt):
self.enabled = False
return
else:
self.enabled = True
self.logformat = logging.Formatter("%(asctime)s - %(levelname)s - " +
"%(name)s - %(message)s")
@ -59,7 +52,7 @@ class MarvinPlugin(Plugin):
else:
self.result_stream = sys.stdout
deploy = deployDataCenter.deployDataCenters(options.config)
deploy = deployDataCenter.deployDataCenters(options.config_file)
deploy.loadCfg() if options.load else deploy.deploy()
self.setClient(deploy.testClient)
self.setConfig(deploy.getCfg())
@ -74,7 +67,7 @@ class MarvinPlugin(Plugin):
"""
parser.add_option("--marvin-config", action="store",
default=env.get('MARVIN_CONFIG', './datacenter.cfg'),
dest="config",
dest="config_file",
help="Marvin's configuration file where the " +
"datacenter information is specified " +
"[MARVIN_CONFIG]")
@ -146,10 +139,6 @@ class MarvinPlugin(Plugin):
str(time.ctime(self.startTime)), str(time.ctime(endTime))))
def _injectClients(self, test):
self.debug_stream. \
setFormatter(logging.
Formatter("%(asctime)s - %(levelname)s - %(name)s" +
" - %(message)s"))
setattr(test, "debug", self.logger.debug)
setattr(test, "info", self.logger.info)
setattr(test, "warn", self.logger.warning)