From 63d36883605e42cf48eec1f50e2496f43ea6a496 Mon Sep 17 00:00:00 2001 From: Santhosh Edukulla Date: Tue, 1 Apr 2014 20:58:11 +0530 Subject: [PATCH] Added fix for CLOUDSTACK-6316 Added changes for CLOUDSTACK-6316. More details in the bug Signed-off-by: Santhosh Edukulla --- .../maint/test_host_high_availability.py | 13 +- tools/marvin/marvin/__init__.py | 2 +- tools/marvin/marvin/asyncJobMgr.py | 10 +- tools/marvin/marvin/cloudstackConnection.py | 72 +- tools/marvin/marvin/cloudstackException.py | 4 + tools/marvin/marvin/cloudstackTestCase.py | 4 +- tools/marvin/marvin/cloudstackTestClient.py | 111 +- tools/marvin/marvin/codegenerator.py | 11 +- tools/marvin/marvin/config/test_data.py | 3 +- tools/marvin/marvin/configGenerator.py | 110 +- tools/marvin/marvin/dbConnection.py | 3 +- tools/marvin/marvin/deployAndRun.py | 6 +- tools/marvin/marvin/deployDataCenter.py | 1302 +++++++++-------- tools/marvin/marvin/jsonHelper.py | 7 +- tools/marvin/marvin/marvinInit.py | 52 +- tools/marvin/marvin/marvinLog.py | 11 +- tools/marvin/marvin/marvinPlugin.py | 33 +- tools/marvin/marvin/sshClient.py | 22 +- tools/marvin/marvin/tcExecuteEngine.py | 3 +- tools/marvin/marvin/testSetupSuccess.py | 1 + 20 files changed, 932 insertions(+), 848 deletions(-) diff --git a/test/integration/component/maint/test_host_high_availability.py b/test/integration/component/maint/test_host_high_availability.py index f81bff2e8fe..4cd7fd8fe84 100644 --- a/test/integration/component/maint/test_host_high_availability.py +++ b/test/integration/component/maint/test_host_high_availability.py @@ -24,6 +24,7 @@ from marvin.cloudstackAPI import * from marvin.lib.utils import * from marvin.lib.base import * from marvin.lib.common import * +import time class Services: @@ -619,11 +620,7 @@ class TestHostHighAvailability(cloudstackTestCase): #verify the VM live migration happened to another running host self.debug("Waiting for VM to come up") - wait_for_vm( - self.apiclient, - virtualmachineid=vm_with_ha_enabled.id, - interval=timeout - ) + time.sleep(timeout) vms = VirtualMachine.list( self.apiclient, @@ -751,11 +748,7 @@ class TestHostHighAvailability(cloudstackTestCase): #verify the VM live migration happened to another running host self.debug("Waiting for VM to come up") - wait_for_vm( - self.apiclient, - virtualmachineid=vm_with_ha_disabled.id, - interval=timeout - ) + time.sleep(timeout) vms = VirtualMachine.list( self.apiclient, diff --git a/tools/marvin/marvin/__init__.py b/tools/marvin/marvin/__init__.py index 7af168e20bc..7102e3f3107 100644 --- a/tools/marvin/marvin/__init__.py +++ b/tools/marvin/marvin/__init__.py @@ -15,4 +15,4 @@ # specific language governing permissions and limitations # under the License. -#Marvin - The cloudstack test client +# Marvin - The cloudstack test client diff --git a/tools/marvin/marvin/asyncJobMgr.py b/tools/marvin/marvin/asyncJobMgr.py index ee3ae5ad3d5..00e8c19b3ce 100644 --- a/tools/marvin/marvin/asyncJobMgr.py +++ b/tools/marvin/marvin/asyncJobMgr.py @@ -26,12 +26,14 @@ import datetime class job(object): + def __init__(self): self.id = None self.cmd = None class jobStatus(object): + def __init__(self): self.result = None self.status = None @@ -47,6 +49,7 @@ class jobStatus(object): class workThread(threading.Thread): + def __init__(self, in_queue, outqueue, apiClient, db=None, lock=None): threading.Thread.__init__(self) self.inqueue = in_queue @@ -62,7 +65,7 @@ class workThread(threading.Thread): try: self.lock.acquire() result = self.connection.poll(job.jobId, job.responsecls).jobresult - except cloudstackException.CloudstackAPIException, e: + except cloudstackException.CloudstackAPIException as e: result = str(e) finally: self.lock.release() @@ -102,7 +105,7 @@ class workThread(threading.Thread): except: pass jobstatus.status = True - except cloudstackException.CloudstackAPIException, e: + except cloudstackException.CloudstackAPIException as e: jobstatus.result = str(e) jobstatus.status = False except: @@ -129,6 +132,7 @@ class workThread(threading.Thread): class jobThread(threading.Thread): + def __init__(self, inqueue, interval): threading.Thread.__init__(self) self.inqueue = inqueue @@ -149,12 +153,14 @@ class jobThread(threading.Thread): class outputDict(object): + def __init__(self): self.lock = threading.Condition() self.dict = {} class asyncJobMgr(object): + def __init__(self, apiClient, db): self.inqueue = Queue.Queue() self.output = outputDict() diff --git a/tools/marvin/marvin/cloudstackConnection.py b/tools/marvin/marvin/cloudstackConnection.py index 26116ccb7d8..c4a4b0d88e8 100644 --- a/tools/marvin/marvin/cloudstackConnection.py +++ b/tools/marvin/marvin/cloudstackConnection.py @@ -21,9 +21,9 @@ import base64 import hmac import hashlib import time -from cloudstackAPI import * -import jsonHelper -from codes import ( +from .cloudstackAPI import * +from . import jsonHelper +from .codes import ( FAILED, INVALID_RESPONSE, INVALID_INPUT, @@ -42,12 +42,14 @@ from marvin.cloudstackException import GetDetailExceptionInfo class CSConnection(object): + ''' @Desc: Connection Class to make API\Command calls to the CloudStack Management Server Sends the GET\POST requests to CS based upon the information provided and retrieves the parsed response. ''' + def __init__(self, mgmtDet, asyncTimeout=3600, logger=None, path='client/api'): self.apiKey = mgmtDet.apiKey @@ -56,10 +58,9 @@ class CSConnection(object): self.port = mgmtDet.port self.user = mgmtDet.user self.passwd = mgmtDet.passwd + self.certPath = () if mgmtDet.certCAPath != "NA" and mgmtDet.certPath != "NA": self.certPath = (mgmtDet.certCAPath, mgmtDet.certPath) - else: - self.certPath = () self.logger = logger self.path = path self.retries = 5 @@ -94,28 +95,33 @@ class CSConnection(object): cmd = queryAsyncJobResult.queryAsyncJobResultCmd() cmd.jobid = jobid timeout = self.asyncTimeout - + start_time = time.time() + end_time = time.time() + async_response = FAILED + self.logger.debug("=== Jobid: %s Started ===" % (str(jobid))) while timeout > 0: async_response = self.\ marvinRequest(cmd, response_type=response_cmd) if async_response != FAILED: job_status = async_response.jobstatus - if job_status in [JOB_FAILED, JOB_CANCELLED]: - self.logger.debug("=====JobId:%s Either " - "got Cancelled or Failed======" - % (str(jobid))) - return FAILED - if job_status == JOB_SUCCEEDED: - self.logger.debug("======JobId:%s Succeeded=====" - % (str(jobid))) - return async_response + if job_status in [JOB_FAILED, + JOB_CANCELLED, + JOB_SUCCEEDED]: + break time.sleep(5) timeout -= 5 self.logger.debug("JobId:%s is Still Processing, " "Will TimeOut in:%s" % (str(jobid), str(timeout))) - return FAILED - except Exception, e: + end_time = time.time() + tot_time = int(start_time - end_time) + self.logger.debug( + "===Jobid:%s ; StartTime:%s ; EndTime:%s ; " + "TotalTime:%s===" % + (str(jobid), str(time.ctime(start_time)), + str(time.ctime(end_time)), str(tot_time))) + return async_response + except Exception as e: self.__lastError = GetDetailExceptionInfo(e) self.logger.exception("__poll: Exception Occurred :%s" % self.__lastError) @@ -165,11 +171,11 @@ class CSConnection(object): cert=self.certPath, verify=self.httpsFlag) return response - except Exception, e: - self.__lastError = GetDetailExceptionInfo(e) + except Exception as e: + self.__lastError = e self.logger.\ exception("__sendPostReqToCS : Exception " - "Occurred: %s" % self.__lastError) + "Occurred: %s" % str(self.__lastError)) return FAILED def __sendGetReqToCS(self, url, payload): @@ -187,10 +193,10 @@ class CSConnection(object): cert=self.certPath, verify=self.httpsFlag) return response - except Exception, e: - self.__lastError = GetDetailExceptionInfo(e) + except Exception as e: + self.__lastError = e self.logger.exception("__sendGetReqToCS : Exception Occurred: %s" % - self.__lastError) + str(self.__lastError)) return FAILED def __sendCmdToCS(self, command, auth=True, payload={}, method='GET'): @@ -213,8 +219,9 @@ class CSConnection(object): payload["apiKey"] = self.apiKey payload["signature"] = self.__sign(payload) - #Verify whether protocol is "http", then call the request over http - if self.protocol == "http" or self.protocol == "https": + # Verify whether protocol is "http" or "https", then send the + # request + if self.protocol in ["http", "https"]: self.logger.debug("Payload: %s" % str(payload)) if method == 'POST': self.logger.debug("=======Sending POST Cmd : %s=======" @@ -227,7 +234,7 @@ class CSConnection(object): else: self.logger.exception("__sendCmdToCS: Invalid Protocol") return FAILED - except Exception, e: + except Exception as e: self.logger.exception("__sendCmdToCS: Exception:%s" % GetDetailExceptionInfo(e)) return FAILED @@ -276,7 +283,7 @@ class CSConnection(object): payload["%s[%d].%s" % (param, i, k)] = v i += 1 return cmd_name.strip(), isAsync, payload - except Exception, e: + except Exception as e: self.logger.\ exception("__sanitizeCmd: CmdName : " "%s : Exception:%s" % (cmd_name, @@ -352,10 +359,13 @@ class CSConnection(object): 4. Check if the Command Response received above is valid or Not. If not return Invalid Response ''' - return self.__parseAndGetResponse(cmd_response, - response_type, - is_async) - except Exception, e: + ret = self.__parseAndGetResponse(cmd_response, + response_type, + is_async) + if ret == FAILED: + raise self.__lastError + return ret + except Exception as e: self.logger.exception("marvinRequest : CmdName: %s Exception: %s" % (str(cmd), GetDetailExceptionInfo(e))) return FAILED diff --git a/tools/marvin/marvin/cloudstackException.py b/tools/marvin/marvin/cloudstackException.py index 3da28b76ef3..c2eb57a4231 100644 --- a/tools/marvin/marvin/cloudstackException.py +++ b/tools/marvin/marvin/cloudstackException.py @@ -21,6 +21,7 @@ from marvin.codes import (INVALID_INPUT, EXCEPTION_OCCURRED) class CloudstackAPIException(Exception): + def __init__(self, cmd="", result=""): self.errorMsg = "Execute cmd: %s failed, due to: %s" % (cmd, result) @@ -29,6 +30,7 @@ class CloudstackAPIException(Exception): class InvalidParameterException(Exception): + def __init__(self, msg=''): self.errorMsg = msg @@ -37,6 +39,7 @@ class InvalidParameterException(Exception): class dbException(Exception): + def __init__(self, msg=''): self.errorMsg = msg @@ -45,6 +48,7 @@ class dbException(Exception): class internalError(Exception): + def __init__(self, msg=''): self.errorMsg = msg diff --git a/tools/marvin/marvin/cloudstackTestCase.py b/tools/marvin/marvin/cloudstackTestCase.py index 303f7ade3bc..5cb4a109286 100644 --- a/tools/marvin/marvin/cloudstackTestCase.py +++ b/tools/marvin/marvin/cloudstackTestCase.py @@ -37,7 +37,7 @@ def user(Name, DomainName, AcctType): class cloudstackTestCase(unittest.case.TestCase): clstestclient = None - def assertElementInList(inp, toverify, responsevar=None, pos=0, + def assertElementInList(inp, toverify, responsevar=None, pos=0, assertmsg="TC Failed for reason"): ''' @Name: assertElementInList @@ -46,7 +46,7 @@ class cloudstackTestCase(unittest.case.TestCase): Takes one additional argument of what message to assert with when failed ''' - out = verifyElementInList(inp, toverify, responsevar, pos) + out = verifyElementInList(inp, toverify, responsevar, pos) unittest.TestCase.assertEquals(out[0], PASS, "msg:%s" % out[1]) @classmethod diff --git a/tools/marvin/marvin/cloudstackTestClient.py b/tools/marvin/marvin/cloudstackTestClient.py index 0dac5f49d48..b3a06220d66 100644 --- a/tools/marvin/marvin/cloudstackTestClient.py +++ b/tools/marvin/marvin/cloudstackTestClient.py @@ -15,23 +15,20 @@ # specific language governing permissions and limitations # under the License. -from cloudstackConnection import CSConnection -import asyncJobMgr -from dbConnection import DbConnection -from cloudstackAPI import * -import random -import string -import hashlib -from codes import (FAILED, PASS, ADMIN, DOMAIN_ADMIN, - USER, SUCCESS, XEN_SERVER) -from configGenerator import ConfigManager -from marvin.lib import utils +from marvin.cloudstackConnection import CSConnection +from marvin.asyncJobMgr import asyncJobMgr +from marvin.dbConnection import DbConnection +from marvin.cloudstackAPI import * +from marvin.codes import (FAILED, PASS, ADMIN, DOMAIN_ADMIN, + USER, SUCCESS, XEN_SERVER) +from marvin.configGenerator import ConfigManager from marvin.cloudstackException import GetDetailExceptionInfo from marvin.lib.utils import (random_gen, validateList) from marvin.cloudstackAPI.cloudstackAPIClient import CloudStackAPIClient class CSTestClient(object): + ''' @Desc : CloudStackTestClient is encapsulated entity for creating and getting various clients viz., apiclient, @@ -46,13 +43,14 @@ class CSTestClient(object): logger : provides logging facilities for this library zone : The zone on which test suites using this test client will run ''' + def __init__(self, mgmt_details, dbsvr_details, async_timeout=3600, - default_worker_threads=10, logger=None, test_data_filepath=None, - zone=None): + zone=None, + hypervisor_type=None): self.__mgmtDetails = mgmt_details self.__dbSvrDetails = dbsvr_details self.__csConnection = None @@ -60,15 +58,15 @@ class CSTestClient(object): self.__testClient = None self.__asyncTimeOut = async_timeout self.__logger = logger - self.__defaultWorkerThreads = default_worker_threads self.__apiClient = None self.__userApiClient = None self.__asyncJobMgr = None self.__id = None - self.__hypervisor = None + self.__hypervisor = hypervisor_type self.__testDataFilePath = test_data_filepath self.__parsedTestDataConfig = None self.__zone = zone + self.__setHypervisorInfo() @property def identifier(self): @@ -96,36 +94,30 @@ class CSTestClient(object): Even, if it is not available, return None @Output : Returns the Zone Name ''' - if self.__zone is None: - if self.__parsedTestDataConfig: - ret = self.__parsedTestDataConfig.get("zone") - if ret != "NA": - self.__zone = ret return self.__zone def getHypervisorInfo(self): ''' @Name : getHypervisorInfo @Desc : Provides the hypervisor Information to test users + @Output : Return Hypervisor Information ''' - if not self.__hypervisor: - if self.__mgmtDetails.hypervisor: - self.__hypervisor = self.__mgmtDetails.hypervisor - else: - self.__hypervisor = XEN_SERVER return self.__hypervisor - - def __setHypervisorToClient(self): + def __setHypervisorInfo(self): ''' - @Name : ___setHypervisorToClient - @Desc: Set the HyperVisor Details under API Client; - default to Xen + @Name : __setHypervisorInfo + @Desc: Set the HyperVisor details; + default to XenServer ''' - if self.__mgmtDetails.hypervisor: - self.__apiClient.hypervisor = self.__mgmtDetails.hypervisor - else: - self.__apiClient.hypervisor = XEN_SERVER + try: + if not self.__hypervisor: + self.__hypervisor = XEN_SERVER + return SUCCESS + except Exception as e: + print "\n Exception Occurred Under __setHypervisorInfo " \ + "%s" % GetDetailExceptionInfo(e) + return FAILED def __createApiClient(self): try: @@ -178,12 +170,8 @@ class CSTestClient(object): self.__asyncTimeOut, self.__logger) self.__apiClient = CloudStackAPIClient(self.__csConnection) - ''' - Set the HyperVisor Details to Client default to Xen - ''' - self.__setHypervisorToClient() return SUCCESS - except Exception, e: + except Exception as e: self.__logger.exception(" Exception Occurred Under " "__createApiClient: %s" % GetDetailExceptionInfo(e)) @@ -210,16 +198,18 @@ class CSTestClient(object): ''' @Name : ___getKeys @Desc : Retrieves the API and Secret Key for the provided Userid + @Input: userid: Userid to register + @Output: FAILED or tuple with apikey and secretkey ''' try: register_user = registerUserKeys.registerUserKeysCmd() register_user.id = userid register_user_res = \ self.__apiClient.registerUserKeys(register_user) - if register_user_res == FAILED: + if not register_user_res: return FAILED return (register_user_res.apikey, register_user_res.secretkey) - except Exception, e: + except Exception as e: self.__logger.exception("Exception Occurred Under __geKeys : " "%s" % GetDetailExceptionInfo(e)) return FAILED @@ -247,14 +237,21 @@ class CSTestClient(object): configuration file. They can overwrite it with providing their own configuration file as well. ''' + ''' + 1. Check Config,Zone,Hypervisor Information + ''' self.__configObj = ConfigManager(self.__testDataFilePath) - if self.__configObj: - self.__parsedTestDataConfig = self.__configObj.getConfig() - self.__logger.debug("Parsing Test data successful") - else: - self.__logger.error("createTestClient : Not able to create " + + if not self.__configObj or not self.__hypervisor: + self.__logger.error("createTestClient : " + "Either Hypervisor is None or " + "Not able to create " "ConfigManager Object") return FAILED + + self.__parsedTestDataConfig = self.__configObj.getConfig() + self.__logger.debug("Parsing Test data successful") + ''' 2. Create DB Connection ''' @@ -265,12 +262,12 @@ class CSTestClient(object): ret = self.__createApiClient() if ret == FAILED: self.__logger.\ - error("********Test Client Creation Failed********") + error("==== Test Client Creation Failed ====") else: self.__logger.\ - debug("********Test Client Creation Successful********") + debug("==== Test Client Creation Successful ====") return ret - except Exception, e: + except Exception as e: self.__logger.exception("Exception Occurred " "Under createTestClient " ": %s" % GetDetailExceptionInfo(e)) @@ -302,6 +299,10 @@ class CSTestClient(object): @Name : ___createUserApiClient @Desc : Creates a User API Client with given UserName\DomainName Parameters + @Input: UserName: Username to be created in cloudstack + DomainName: Domain under which the above account be created + accType: Type of Account EX: Root,Non Root etc + @Output: Return the API client for the user ''' try: if not self.isAdminContext(): @@ -364,9 +365,9 @@ class CSTestClient(object): self.__csConnection.logger) self.__userApiClient = CloudStackAPIClient(newUserConnection) self.__userApiClient.connection = newUserConnection - self.__userApiClient.hypervisor = self.__apiClient.hypervisor + self.__userApiClient.hypervisor = self.__hypervisor return self.__userApiClient - except Exception, e: + except Exception as e: self.__logger.exception("Exception Occurred " "Under getUserApiClient : %s" % GetDetailExceptionInfo(e)) @@ -399,16 +400,12 @@ class CSTestClient(object): def getUserApiClient(self, account, domain, type=0): """ @Name : getUserApiClient - @Desc : Provides the User API Client to Users + @Desc : Provides the User API Client to test Users 0 - user ; 1 - admin;2 - domain admin @OutPut : FAILED In case of an issue else User API Client """ - return FAILED if (self.__createUserApiClient(account, - domain, - type) - == FAILED) \ - else self.__userApiClient + return self.__createUserApiClient(account, domain, type) def submitCmdsAndWait(self, cmds, workers=1): ''' diff --git a/tools/marvin/marvin/codegenerator.py b/tools/marvin/marvin/codegenerator.py index d4a81cfa967..1e02ddfb379 100644 --- a/tools/marvin/marvin/codegenerator.py +++ b/tools/marvin/marvin/codegenerator.py @@ -25,6 +25,7 @@ import urllib2 class cmdParameterProperty(object): + def __init__(self): self.name = None self.required = False @@ -34,6 +35,7 @@ class cmdParameterProperty(object): class cloudStackCmd(object): + def __init__(self): self.name = "" self.desc = "" @@ -43,6 +45,7 @@ class cloudStackCmd(object): class CodeGenerator(object): + """ Apache CloudStack- marvin python classes can be generated from the json returned by API discovery or from the xml spec of commands generated by @@ -208,12 +211,12 @@ class CodeGenerator(object): body += self.space + '@property' + self.newline body += self.space + 'def id(self):' + self.newline - body += self.space*2 + 'return self._id' + self.newline + body += self.space * 2 + 'return self._id' + self.newline body += self.newline body += self.space + '@id.setter' + self.newline body += self.space + 'def id(self, identifier):' + self.newline - body += self.space*2 + 'self._id = identifier' + self.newline + body += self.space * 2 + 'self._id = identifier' + self.newline body += self.newline for cmdName in self.cmdsName: @@ -340,7 +343,7 @@ class CodeGenerator(object): paramProperty.desc = response['description'] if 'type' in response: if response['type'] in ['list', 'map', 'set']: - #Here list becomes a subproperty + # Here list becomes a subproperty if 'response' in response: for innerResponse in response['response']: subProperty =\ @@ -394,7 +397,7 @@ class CodeGenerator(object): csCmd.request.append(paramProperty) for response in cmd['response']: - #FIXME: ExtractImage related APIs return empty dicts in response + # FIXME: ExtractImage related APIs return empty dicts in response if len(response) > 0: paramProperty = self.constructResponseFromJSON(response) csCmd.response.append(paramProperty) diff --git a/tools/marvin/marvin/config/test_data.py b/tools/marvin/marvin/config/test_data.py index 563bc0768f8..3c1d4aff6da 100644 --- a/tools/marvin/marvin/config/test_data.py +++ b/tools/marvin/marvin/config/test_data.py @@ -5,7 +5,8 @@ test_data = { "regionendpoint": "http://region2:8080/client" }, "zone": "NA", - "domain": { "name": "domain" }, + "hypervisor": "XenServer", + "vdomain": { "name": "domain" }, "email" : "test@test.com", "gateway" : "172.1.1.1", "netmask" : "255.255.255.0", diff --git a/tools/marvin/marvin/configGenerator.py b/tools/marvin/marvin/configGenerator.py index 43b4d7c283f..68ec24eb2bc 100644 --- a/tools/marvin/marvin/configGenerator.py +++ b/tools/marvin/marvin/configGenerator.py @@ -25,6 +25,7 @@ from marvin.config.test_data import test_data class managementServer(object): + def __init__(self): self.mgtSvrIp = None self.port = 8096 @@ -36,6 +37,7 @@ class managementServer(object): class dbServer(object): + def __init__(self): self.dbSvr = None self.port = 3306 @@ -85,6 +87,7 @@ class zone(object): class trafficType(object): + def __init__(self, typ, labeldict=None): self.typ = typ # Guest/Management/Public if labeldict: @@ -97,6 +100,7 @@ class trafficType(object): class pod(object): + def __init__(self): self.gateway = None self.name = None @@ -111,6 +115,7 @@ class pod(object): class VmwareDc(object): + def __init__(self): self.zoneid = None self.name = None @@ -120,6 +125,7 @@ class VmwareDc(object): class cluster(object): + def __init__(self): self.clustername = None self.clustertype = None @@ -134,6 +140,7 @@ class cluster(object): class host(object): + def __init__(self): self.hypervisor = None self.password = None @@ -151,6 +158,7 @@ class host(object): class physicalNetwork(object): + def __init__(self): self.name = None self.tags = [] @@ -165,6 +173,7 @@ class physicalNetwork(object): class provider(object): + def __init__(self, name=None): self.name = name self.state = None @@ -175,6 +184,7 @@ class provider(object): class network(object): + def __init__(self): self.displaytext = None self.name = None @@ -187,6 +197,7 @@ class network(object): class iprange(object): + def __init__(self): '''tagged/untagged''' self.gateway = None @@ -200,12 +211,14 @@ class iprange(object): class primaryStorage(object): + def __init__(self): self.name = None self.url = None class secondaryStorage(object): + def __init__(self): self.url = None self.provider = None @@ -213,6 +226,7 @@ class secondaryStorage(object): class cacheStorage(object): + def __init__(self): self.url = None self.provider = None @@ -220,6 +234,7 @@ class cacheStorage(object): class s3(object): + def __init__(self): self.accesskey = None self.secretkey = None @@ -232,6 +247,7 @@ class s3(object): class netscaler(object): + def __init__(self, hostname=None, username='nsroot', password='nsroot'): self.hostname = hostname self.username = username @@ -248,11 +264,12 @@ class netscaler(object): def __repr__(self): req = zip(self.__dict__.keys(), self.__dict__.values()) - return self.hostname+"?" + "&".join(["=".join([r[0], r[1]]) - for r in req]) + return self.hostname + "?" + "&".join(["=".join([r[0], r[1]]) + for r in req]) class srx(object): + def __init__(self, hostname=None, username='root', password='admin'): self.hostname = hostname self.username = username @@ -271,11 +288,12 @@ class srx(object): def __repr__(self): req = zip(self.__dict__.keys(), self.__dict__.values()) - return self.hostname+"?" + "&".join(["=".join([r[0], r[1]]) - for r in req]) + return self.hostname + "?" + "&".join(["=".join([r[0], r[1]]) + for r in req]) class bigip(object): + def __init__(self, hostname=None, username='root', password='default'): self.hostname = hostname self.username = username @@ -292,11 +310,12 @@ class bigip(object): def __repr__(self): req = zip(self.__dict__.keys(), self.__dict__.values()) - return self.hostname+"?" + "&".join(["=".join([r[0], r[1]]) - for r in req]) + return self.hostname + "?" + "&".join(["=".join([r[0], r[1]]) + for r in req]) class ConfigManager(object): + ''' @Name: ConfigManager @Desc: 1. It provides the basic configuration facilities to marvin. @@ -328,6 +347,7 @@ class ConfigManager(object): 8. Users can use their own configuration file passed to "getConfig" API,once configObj is returned. ''' + def __init__(self, cfg_file=None): self.__filePath = cfg_file self.__parsedCfgDict = None @@ -364,8 +384,8 @@ class ConfigManager(object): configLines.append(ws) config = json.loads("\n".join(configLines)) config_dict = config - except Exception, e: - #Will replace with log once we have logging done + except Exception as e: + # Will replace with log once we have logging done print "\n Exception occurred under ConfigManager:__parseConfig" \ " :%s", GetDetailExceptionInfo(e) finally: @@ -413,9 +433,9 @@ class ConfigManager(object): def getDeviceUrl(obj): req = zip(obj.__dict__.keys(), obj.__dict__.values()) if obj.hostname: - return "http://" + obj.hostname+"?" + "&".join(["=".join([r[0], - r[1]]) - for r in req]) + return "http://" + obj.hostname + "?" + "&".join(["=".join([r[0], + r[1]]) + for r in req]) else: return None @@ -430,11 +450,11 @@ def descSetupInBasicMode(): z.dns2 = "8.8.4.4" z.internaldns1 = "192.168.110.254" z.internaldns2 = "192.168.110.253" - z.name = "test"+str(l) + z.name = "test" + str(l) z.networktype = 'Basic' z.securitygroupenabled = 'True' - #If security groups are reqd + # If security groups are reqd sgprovider = provider() sgprovider.broadcastdomainrange = 'Pod' sgprovider.name = 'SecurityGroupProvider' @@ -460,15 +480,15 @@ def descSetupInBasicMode(): ip = iprange() ip.gateway = p.gateway ip.netmask = p.netmask - ip.startip = "192.168.%d.%d" % (i, j*20) - ip.endip = "192.168.%d.%d" % (i, j*20+10) + ip.startip = "192.168.%d.%d" % (i, j * 20) + ip.endip = "192.168.%d.%d" % (i, j * 20 + 10) p.guestIpRanges.append(ip) '''add 10 clusters''' for j in range(2): c = cluster() - c.clustername = "test"+str(l)+str(i) + str(j) + c.clustername = "test" + str(l) + str(i) + str(j) c.clustertype = "CloudManaged" c.hypervisor = "Simulator" @@ -477,15 +497,16 @@ def descSetupInBasicMode(): h = host() h.username = "root" h.password = "password" - memory = 8*1024*1024*1024 - localstorage = 1*1024*1024*1024*1024 + memory = 8 * 1024 * 1024 * 1024 + localstorage = 1 * 1024 * 1024 * 1024 * 1024 h.url = "http://sim/%d%d%d%d" % (l, i, j, k) c.hosts.append(h) '''add 2 primary storages''' for m in range(2): primary = primaryStorage() - primary.name = "primary"+str(l) + str(i) + str(j) + str(m) + primary.name = "primary" + \ + str(l) + str(i) + str(j) + str(m) primary.url = "nfs://localhost/path%s" % (str(l) + str(i) + str(j) + str(m)) c.primaryStorages.append(primary) @@ -497,7 +518,7 @@ def descSetupInBasicMode(): '''add two secondary''' for i in range(5): secondary = secondaryStorage() - secondary.url = "nfs://localhost/path"+str(l) + str(i) + secondary.url = "nfs://localhost/path" + str(l) + str(i) z.secondaryStorages.append(secondary) zs.zones.append(z) @@ -539,7 +560,7 @@ def descSetupInEipMode(): z.dns2 = "8.8.4.4" z.internaldns1 = "192.168.110.254" z.internaldns2 = "192.168.110.253" - z.name = "test"+str(l) + z.name = "test" + str(l) z.networktype = 'Basic' ips = iprange() @@ -550,7 +571,7 @@ def descSetupInEipMode(): ips.netmask = "255.255.255.0" z.ipranges.append(ips) - #If security groups are reqd + # If security groups are reqd sgprovider = provider() sgprovider.broadcastdomainrange = 'Pod' sgprovider.name = 'SecurityGroupProvider' @@ -584,15 +605,15 @@ def descSetupInEipMode(): ip = iprange() ip.gateway = p.gateway ip.netmask = p.netmask - ip.startip = "192.168.%d.%d" % (i, j*20) - ip.endip = "192.168.%d.%d" % (i, j*20+10) + ip.startip = "192.168.%d.%d" % (i, j * 20) + ip.endip = "192.168.%d.%d" % (i, j * 20 + 10) p.guestIpRanges.append(ip) '''add 10 clusters''' for j in range(2): c = cluster() - c.clustername = "test"+str(l)+str(i) + str(j) + c.clustername = "test" + str(l) + str(i) + str(j) c.clustertype = "CloudManaged" c.hypervisor = "Simulator" @@ -607,7 +628,8 @@ def descSetupInEipMode(): '''add 2 primary storages''' for m in range(2): primary = primaryStorage() - primary.name = "primary"+str(l) + str(i) + str(j) + str(m) + primary.name = "primary" + \ + str(l) + str(i) + str(j) + str(m) primary.url = "nfs://localhost/path%s" % (str(l) + str(i) + str(j) + str(m)) @@ -620,7 +642,7 @@ def descSetupInEipMode(): '''add two secondary''' for i in range(5): secondary = secondaryStorage() - secondary.url = "nfs://localhost/path"+str(l) + str(i) + secondary.url = "nfs://localhost/path" + str(l) + str(i) z.secondaryStorages.append(secondary) zs.zones.append(z) @@ -660,7 +682,7 @@ def descSetupInAdvancedMode(): z.dns2 = "8.8.4.4" z.internaldns1 = "192.168.110.254" z.internaldns2 = "192.168.110.253" - z.name = "test"+str(l) + z.name = "test" + str(l) z.networktype = 'Advanced' z.guestcidraddress = "10.1.1.0/24" z.vlan = "100-2000" @@ -696,7 +718,7 @@ def descSetupInAdvancedMode(): '''add 10 clusters''' for j in range(2): c = cluster() - c.clustername = "test"+str(l)+str(i) + str(j) + c.clustername = "test" + str(l) + str(i) + str(j) c.clustertype = "CloudManaged" c.hypervisor = "Simulator" @@ -707,7 +729,7 @@ def descSetupInAdvancedMode(): h.password = "password" memory = 8 * 1024 * 1024 * 1024 localstorage = 1 * 1024 * 1024 * 1024 * 1024 - #h.url = "http://sim/%d%d%d%d/cpucore=1&cpuspeed=8000&\ + # h.url = "http://sim/%d%d%d%d/cpucore=1&cpuspeed=8000&\ # memory=%d&localstorage=%d"%(l, i, j, k, memory, # localstorage) h.url = "http://sim/%d%d%d%d" % (l, i, j, k) @@ -716,8 +738,9 @@ def descSetupInAdvancedMode(): '''add 2 primary storages''' for m in range(2): primary = primaryStorage() - primary.name = "primary"+str(l) + str(i) + str(j) + str(m) - #primary.url = "nfs://localhost/path%s/size=%d" % + primary.name = "primary" + \ + str(l) + str(i) + str(j) + str(m) + # primary.url = "nfs://localhost/path%s/size=%d" % # (str(l) + str(i) + str(j) + str(m), size) primary.url = "nfs://localhost/path%s" % (str(l) + str(i) + str(j) @@ -731,7 +754,7 @@ def descSetupInAdvancedMode(): '''add two secondary''' for i in range(5): secondary = secondaryStorage() - secondary.url = "nfs://localhost/path"+str(l) + str(i) + secondary.url = "nfs://localhost/path" + str(l) + str(i) z.secondaryStorages.append(secondary) '''add default public network''' @@ -781,7 +804,7 @@ def descSetupInAdvancedsgMode(): z.dns2 = "8.8.4.4" z.internaldns1 = "192.168.110.254" z.internaldns2 = "192.168.110.253" - z.name = "test"+str(l) + z.name = "test" + str(l) z.networktype = 'Advanced' z.vlan = "100-2000" z.securitygroupenabled = "true" @@ -790,7 +813,7 @@ def descSetupInAdvancedsgMode(): pn.name = "test-network" pn.traffictypes = [trafficType("Guest"), trafficType("Management")] - #If security groups are reqd + # If security groups are reqd sgprovider = provider() sgprovider.broadcastdomainrange = 'ZONE' sgprovider.name = 'SecurityGroupProvider' @@ -810,7 +833,7 @@ def descSetupInAdvancedsgMode(): '''add 10 clusters''' for j in range(2): c = cluster() - c.clustername = "test"+str(l)+str(i) + str(j) + c.clustername = "test" + str(l) + str(i) + str(j) c.clustertype = "CloudManaged" c.hypervisor = "Simulator" @@ -821,17 +844,18 @@ def descSetupInAdvancedsgMode(): h.password = "password" memory = 8 * 1024 * 1024 * 1024 localstorage = 1 * 1024 * 1024 * 1024 * 1024 - #h.url = "http://sim/%d%d%d%d/cpucore=1&cpuspeed=8000&\ - #memory=%d&localstorage=%d" % (l, i, j, k, memory, - #localstorage) + # h.url = "http://sim/%d%d%d%d/cpucore=1&cpuspeed=8000&\ + # memory=%d&localstorage=%d" % (l, i, j, k, memory, + # localstorage) h.url = "http://sim/%d%d%d%d" % (l, i, j, k) c.hosts.append(h) '''add 2 primary storages''' for m in range(2): primary = primaryStorage() - primary.name = "primary"+str(l) + str(i) + str(j) + str(m) - #primary.url = "nfs://localhost/path%s/size=%d" % \ + primary.name = "primary" + \ + str(l) + str(i) + str(j) + str(m) + # primary.url = "nfs://localhost/path%s/size=%d" % \ #(str(l) + str(i) + str(j) + str(m), size) primary.url = "nfs://localhost/path%s" % \ (str(l) + str(i) + str(j) + str(m)) @@ -844,7 +868,7 @@ def descSetupInAdvancedsgMode(): '''add two secondary''' for i in range(5): secondary = secondaryStorage() - secondary.url = "nfs://localhost/path"+str(l) + str(i) + secondary.url = "nfs://localhost/path" + str(l) + str(i) z.secondaryStorages.append(secondary) '''add default guest network''' @@ -904,7 +928,7 @@ def getSetupConfig(file): configLines.append(ws) config = json.loads("\n".join(configLines)) return jsonHelper.jsonLoader(config) - except Exception, e: + except Exception as e: print "\nException Occurred under getSetupConfig %s" % \ GetDetailExceptionInfo(e) diff --git a/tools/marvin/marvin/dbConnection.py b/tools/marvin/marvin/dbConnection.py index ba7bac9fa95..66c6cb17738 100644 --- a/tools/marvin/marvin/dbConnection.py +++ b/tools/marvin/marvin/dbConnection.py @@ -26,6 +26,7 @@ import os class DbConnection(object): + def __init__(self, host="localhost", port=3306, user='cloud', passwd='cloud', db='cloud'): self.host = host @@ -51,7 +52,7 @@ class DbConnection(object): try: resultRow = cursor.fetchall() except errors.InterfaceError: - #Raised on empty result - DML + # Raised on empty result - DML resultRow = [] return resultRow diff --git a/tools/marvin/marvin/deployAndRun.py b/tools/marvin/marvin/deployAndRun.py index 56747a7cb2d..d3b6b8606b0 100644 --- a/tools/marvin/marvin/deployAndRun.py +++ b/tools/marvin/marvin/deployAndRun.py @@ -15,13 +15,13 @@ # specific language governing permissions and limitations # under the License. -from tcExecuteEngine import TestCaseExecuteEngine +from .tcExecuteEngine import TestCaseExecuteEngine import sys import os import traceback import time from argparse import ArgumentParser -from marvinInit import MarvinInit +from .marvinInit import MarvinInit from marvin.codes import (SUCCESS, FAILED, EXCEPTION, @@ -96,7 +96,7 @@ def startMarvin(cfg_file, load_flag): else: print "\nMarvin Initialization Failed" exit(1) - except Exception, e: + except Exception as e: print "\n Exception occurred while starting Marvin %s" % str(e) exit(1) diff --git a/tools/marvin/marvin/deployDataCenter.py b/tools/marvin/marvin/deployDataCenter.py index d4a0b851520..8e39e73123e 100644 --- a/tools/marvin/marvin/deployDataCenter.py +++ b/tools/marvin/marvin/deployDataCenter.py @@ -17,11 +17,11 @@ """ @Desc : -class DeployDataCenters: Deployes datacenters according to a json - configuration file -class DeleteDataCenter: Deletes a datacenter based upon the dc cfg +class DeployDataCenters: Deploys DeleteDataCenters according to a json + configuration file. +class DeleteDataCenters: Deletes a DataCenter based upon the dc cfg settings provided. - This settings file is exported + This settings file is the exported configuration from DeployDataCenters post its success """ @@ -42,7 +42,10 @@ from optparse import OptionParser class DeployDataCenters(object): ''' - @Desc : Deploys the Data Center with information provided + @Desc : Deploys the Data Center with information provided. + Once the Deployment is successful, it will export + the DataCenter settings to an obj file + ( can be used if wanted to delete the created DC) ''' def __init__(self, @@ -59,36 +62,45 @@ class DeployDataCenters(object): self.__cleanUp = {} def __persistDcConfig(self): - if self.__logFolderPath: - dc_file_path = self.__logFolderPath + "/dc_entries.obj" - else: - ts = time.strftime("%b_%d_%Y_%H_%M_%S", - time.localtime()) - dc_file_path = "dc_entries_" + str(ts) + ".obj" - file_to_write = open(dc_file_path, 'w') - if file_to_write: - pickle.dump(self.__cleanUp, file_to_write) - print "\n=== Data Center Settings are dumped to %s" % dc_file_path - self.__tcRunLogger.debug( - "\n=== Data Center Settings are dumped to %s===" % - dc_file_path) + try: + if self.__logFolderPath: + dc_file_path = self.__logFolderPath + "/dc_entries.obj" + else: + ts = time.strftime("%b_%d_%Y_%H_%M_%S", + time.localtime()) + dc_file_path = "dc_entries_" + str(ts) + ".obj" + file_to_write = open(dc_file_path, 'w') + if file_to_write: + pickle.dump(self.__cleanUp, file_to_write) + print "\n=== Data Center Settings are dumped to %s===" % \ + dc_file_path + self.__tcRunLogger.debug( + "\n=== Data Center Settings are dumped to %s===" % + dc_file_path) + except Exception as e: + print "Exception Occurred %s" % GetDetailExceptionInfo(e) def __cleanAndExit(self): - print "\n===Deploy DC Failed, So Cleaning to Exit===" - self.__tcRunLogger.debug("===Deploy DC Failed, So Cleaning to Exit===") - remove_dc_obj = DeleteDataCenter(self.__testClient, - dc_cfg=self.__cleanUp, - tc_run_logger=self.__tcRunLogger - ) - if remove_dc_obj: - if remove_dc_obj.removeDataCenter() == FAILED: - print "\n===Removing DataCenter Failed===" - self.__tcRunLogger.debug("===Removing DataCenter Failed===") - else: - print "\n===Removing DataCenter Successful===" - self.__tcRunLogger.debug( - "===Removing DataCenter Successful===") - exit(1) + try: + print "\n===Deploy DC Failed, So Cleaning to Exit===" + self.__tcRunLogger.debug( + "===Deploy DC Failed, So Cleaning to Exit===") + remove_dc_obj = DeleteDataCenters(self.__testClient, + dc_cfg=self.__cleanUp, + tc_run_logger=self.__tcRunLogger + ) + if remove_dc_obj: + if remove_dc_obj.removeDataCenter() == FAILED: + print "\n===Removing DataCenter Failed===" + self.__tcRunLogger.debug( + "===Removing DataCenter Failed===") + else: + print "\n===Removing DataCenter Successful===" + self.__tcRunLogger.debug( + "===Removing DataCenter Successful===") + exit(1) + except Exception as e: + print "Exception Occurred %s" % GetDetailExceptionInfo(e) def __addToCleanUp(self, type, id): if type not in self.__cleanUp.keys(): @@ -100,529 +112,540 @@ class DeployDataCenters(object): self.__cleanUp["order"].append(type) def addHosts(self, hosts, zoneId, podId, clusterId, hypervisor): - if hosts is None: - return - for host in hosts: - hostcmd = addHost.addHostCmd() - hostcmd.clusterid = clusterId - hostcmd.cpunumber = host.cpunumer - hostcmd.cpuspeed = host.cpuspeed - hostcmd.hostmac = host.hostmac - hostcmd.hosttags = host.hosttags - hostcmd.hypervisor = host.hypervisor - hostcmd.memory = host.memory - hostcmd.password = host.password - hostcmd.podid = podId - hostcmd.url = host.url - hostcmd.username = host.username - hostcmd.zoneid = zoneId - hostcmd.hypervisor = hypervisor - ret = self.__apiClient.addHost(hostcmd) - if ret != FAILED and ret[0].id: - self.__tcRunLogger.debug("=== Add Host Successful ===") - self.__addToCleanUp("Host", ret[0].id) - else: - self.__tcRunLogger.exception("=== Adding Host Failed ===") - self.__cleanAndExit() + try: + if hosts is None: + return + for host in hosts: + hostcmd = addHost.addHostCmd() + hostcmd.clusterid = clusterId + hostcmd.cpunumber = host.cpunumer + hostcmd.cpuspeed = host.cpuspeed + hostcmd.hostmac = host.hostmac + hostcmd.hosttags = host.hosttags + hostcmd.hypervisor = host.hypervisor + hostcmd.memory = host.memory + hostcmd.password = host.password + hostcmd.podid = podId + hostcmd.url = host.url + hostcmd.username = host.username + hostcmd.zoneid = zoneId + hostcmd.hypervisor = hypervisor + ret = self.__apiClient.addHost(hostcmd) + if ret: + self.__tcRunLogger.debug("=== Add Host Successful ===") + self.__addToCleanUp("Host", ret[0].id) + except Exception as e: + print "Exception Occurred %s" % GetDetailExceptionInfo(e) + self.__tcRunLogger.exception("=== Adding Host Failed ===") + self.__cleanAndExit() def addVmWareDataCenter(self, vmwareDc): - vdc = addVmwareDc.addVmwareDcCmd() - vdc.zoneid = vmwareDc.zoneid - vdc.name = vmwareDc.name - vdc.vcenter = vmwareDc.vcenter - vdc.username = vmwareDc.username - vdc.password = vmwareDc.password - ret = self.__apiClient.addVmwareDc(vdc) - if ret != FAILED and ret.id: - self.__tcRunLogger.debug("=== Adding VmWare DC Successful===") - self.__addToCleanUp("VmwareDc", ret.id) - else: + try: + vdc = addVmwareDc.addVmwareDcCmd() + vdc.zoneid = vmwareDc.zoneid + vdc.name = vmwareDc.name + vdc.vcenter = vmwareDc.vcenter + vdc.username = vmwareDc.username + vdc.password = vmwareDc.password + ret = self.__apiClient.addVmwareDc(vdc) + if ret.id: + self.__tcRunLogger.debug("=== Adding VmWare DC Successful===") + self.__addToCleanUp("VmwareDc", ret.id) + except Exception as e: + print "Exception Occurred %s" % GetDetailExceptionInfo(e) self.__tcRunLogger.exception("=== Adding VmWare DC Failed===") self.__cleanAndExit() def createClusters(self, clusters, zoneId, podId, vmwareDc=None): - if clusters is None: - return - if vmwareDc is not None: - vmwareDc.zoneid = zoneId - self.addVmWareDataCenter(vmwareDc) + try: + if clusters is None: + return + if vmwareDc is not None: + vmwareDc.zoneid = zoneId + self.addVmWareDataCenter(vmwareDc) - for cluster in clusters: - clustercmd = addCluster.addClusterCmd() - clustercmd.clustername = cluster.clustername - clustercmd.clustertype = cluster.clustertype - clustercmd.hypervisor = cluster.hypervisor - clustercmd.password = cluster.password - clustercmd.podid = podId - clustercmd.url = cluster.url - clustercmd.username = cluster.username - clustercmd.zoneid = zoneId - clusterresponse = self.__apiClient.addCluster(clustercmd) - if clusterresponse != FAILED and clusterresponse[0].id: - clusterId = clusterresponse[0].id - self.__tcRunLogger.\ - debug("Cluster Name : %s Id : %s Created Successfully" - % (str(cluster.clustername), str(clusterId))) - self.__addToCleanUp("Cluster", clusterId) - else: - self.__tcRunLogger.exception("====Cluster %s Creation Failed" - "=====" % - str(cluster.clustername)) - self.__cleanAndExit() - if cluster.hypervisor.lower() != "vmware": - self.addHosts(cluster.hosts, zoneId, podId, clusterId, - cluster.hypervisor) - self.waitForHost(zoneId, clusterId) - self.createPrimaryStorages(cluster.primaryStorages, - zoneId, - podId, - clusterId) + for cluster in clusters: + clustercmd = addCluster.addClusterCmd() + clustercmd.clustername = cluster.clustername + clustercmd.clustertype = cluster.clustertype + clustercmd.hypervisor = cluster.hypervisor + clustercmd.password = cluster.password + clustercmd.podid = podId + clustercmd.url = cluster.url + clustercmd.username = cluster.username + clustercmd.zoneid = zoneId + clusterresponse = self.__apiClient.addCluster(clustercmd) + if clusterresponse[0].id: + clusterId = clusterresponse[0].id + self.__tcRunLogger.\ + debug("Cluster Name : %s Id : %s Created Successfully" + % (str(cluster.clustername), str(clusterId))) + self.__addToCleanUp("Cluster", clusterId) + if cluster.hypervisor.lower() != "vmware": + self.addHosts(cluster.hosts, zoneId, podId, clusterId, + cluster.hypervisor) + self.waitForHost(zoneId, clusterId) + self.createPrimaryStorages(cluster.primaryStorages, + zoneId, + podId, + clusterId) + except Exception as e: + print "Exception Occurred %s" % GetDetailExceptionInfo(e) + self.__tcRunLogger.exception("====Cluster %s Creation Failed" + "=====" % + str(cluster.clustername)) + self.__cleanAndExit() def waitForHost(self, zoneId, clusterId): """ Wait for the hosts in the zoneid, clusterid to be up 2 retries with 30s delay """ - retry, timeout = 2, 30 - cmd = listHosts.listHostsCmd() - cmd.clusterid, cmd.zoneid = clusterId, zoneId - hosts = self.__apiClient.listHosts(cmd) - if hosts == FAILED: + try: + retry, timeout = 2, 30 + cmd = listHosts.listHostsCmd() + cmd.clusterid, cmd.zoneid = clusterId, zoneId + hosts = self.__apiClient.listHosts(cmd) + while retry != 0: + for host in hosts: + if host.state != 'Up': + break + sleep(timeout) + retry = retry - 1 + except Exception as e: self.__tcRunLogger.exception("=== List Hosts Failed===") self.__cleanAndExit() - while retry != 0: - for host in hosts: - if host.state != 'Up': - break - sleep(timeout) - retry = retry - 1 def createPrimaryStorages(self, primaryStorages, zoneId, podId, clusterId): - if primaryStorages is None: - return - for primary in primaryStorages: - primarycmd = createStoragePool.createStoragePoolCmd() - primarycmd.details = primary.details - primarycmd.name = primary.name - primarycmd.podid = podId - primarycmd.tags = primary.tags - primarycmd.url = primary.url - primarycmd.zoneid = zoneId - primarycmd.clusterid = clusterId - ret = self.__apiClient.createStoragePool(primarycmd) - if ret != FAILED and ret.id: - self.__tcRunLogger.debug( - "=== Creating Storage Pool Successful===") - self.__addToCleanUp("StoragePool", ret.id) - else: - self.__tcRunLogger.\ - exception("=== Create Storage Pool Failed===") - self.__cleanAndExit() + try: + if primaryStorages is None: + return + for primary in primaryStorages: + primarycmd = createStoragePool.createStoragePoolCmd() + primarycmd.details = primary.details + primarycmd.name = primary.name + primarycmd.podid = podId + primarycmd.tags = primary.tags + primarycmd.url = primary.url + primarycmd.zoneid = zoneId + primarycmd.clusterid = clusterId + ret = self.__apiClient.createStoragePool(primarycmd) + if ret.id: + self.__tcRunLogger.debug( + "=== Creating Storage Pool Successful===") + self.__addToCleanUp("StoragePool", ret.id) + except Exception as e: + print "Exception Occurred %s" % GetDetailExceptionInfo(e) + self.__tcRunLogger.\ + exception("=== Create Storage Pool Failed===") + self.__cleanAndExit() def createPods(self, pods, zoneId, networkId=None): - if pods is None: - return - for pod in pods: - createpod = createPod.createPodCmd() - createpod.name = pod.name - createpod.gateway = pod.gateway - createpod.netmask = pod.netmask - createpod.startip = pod.startip - createpod.endip = pod.endip - createpod.zoneid = zoneId - createpodResponse = self.__apiClient.createPod(createpod) - if createpodResponse != \ - FAILED and createpodResponse.id: - podId = createpodResponse.id - self.__tcRunLogger.debug("Pod Name : %s Id : %s " - "Created Successfully" % - (str(pod.name), str(podId))) - self.__addToCleanUp("Pod", podId) - else: - self.__tcRunLogger.\ - exception("====Pod: %s Creation " - "Failed=====" % str(pod.name)) - self.__cleanAndExit() - - if pod.guestIpRanges is not None and networkId is not None: - self.createVlanIpRanges("Basic", pod.guestIpRanges, zoneId, - podId, networkId) - - self.createClusters(pod.clusters, zoneId, podId, - vmwareDc=pod.vmwaredc) + try: + if pods is None: + return + for pod in pods: + createpod = createPod.createPodCmd() + createpod.name = pod.name + createpod.gateway = pod.gateway + createpod.netmask = pod.netmask + createpod.startip = pod.startip + createpod.endip = pod.endip + createpod.zoneid = zoneId + createpodResponse = self.__apiClient.createPod(createpod) + if createpodResponse.id: + podId = createpodResponse.id + self.__tcRunLogger.debug("Pod Name : %s Id : %s " + "Created Successfully" % + (str(pod.name), str(podId))) + self.__addToCleanUp("Pod", podId) + if pod.guestIpRanges is not None and networkId is not None: + self.createVlanIpRanges("Basic", pod.guestIpRanges, zoneId, + podId, networkId) + self.createClusters(pod.clusters, zoneId, podId, + vmwareDc=pod.vmwaredc) + except Exception as e: + print "Exception Occurred %s" % GetDetailExceptionInfo(e) + self.__tcRunLogger.\ + exception("====Pod: %s Creation " + "Failed=====" % str(pod.name)) + self.__cleanAndExit() def createVlanIpRanges(self, mode, ipranges, zoneId, podId=None, networkId=None, forvirtualnetwork=None): - if ipranges is None: - return - for iprange in ipranges: - vlanipcmd = createVlanIpRange.createVlanIpRangeCmd() - vlanipcmd.account = iprange.account - vlanipcmd.domainid = iprange.domainid - vlanipcmd.endip = iprange.endip - vlanipcmd.gateway = iprange.gateway - vlanipcmd.netmask = iprange.netmask - vlanipcmd.networkid = networkId - vlanipcmd.podid = podId - vlanipcmd.startip = iprange.startip - vlanipcmd.zoneid = zoneId - vlanipcmd.vlan = iprange.vlan - if mode == "Basic": - if forvirtualnetwork: - vlanipcmd.forvirtualnetwork = "true" + try: + if ipranges is None: + return + for iprange in ipranges: + vlanipcmd = createVlanIpRange.createVlanIpRangeCmd() + vlanipcmd.account = iprange.account + vlanipcmd.domainid = iprange.domainid + vlanipcmd.endip = iprange.endip + vlanipcmd.gateway = iprange.gateway + vlanipcmd.netmask = iprange.netmask + vlanipcmd.networkid = networkId + vlanipcmd.podid = podId + vlanipcmd.startip = iprange.startip + vlanipcmd.zoneid = zoneId + vlanipcmd.vlan = iprange.vlan + if mode == "Basic": + if forvirtualnetwork: + vlanipcmd.forvirtualnetwork = "true" + else: + vlanipcmd.forvirtualnetwork = "false" else: - vlanipcmd.forvirtualnetwork = "false" - else: - vlanipcmd.forvirtualnetwork = "true" - ret = self.__apiClient.createVlanIpRange(vlanipcmd) - if ret != FAILED and ret.id: - self.__tcRunLogger.debug( - "=== Creating Vlan Ip Range Successful===") - self.__addToCleanUp("VlanIpRange", ret.id) - else: - self.__tcRunLogger.\ - exception("=== Create Vlan Ip Range Failed===") - self.__cleanAndExit() + vlanipcmd.forvirtualnetwork = "true" + ret = self.__apiClient.createVlanIpRange(vlanipcmd) + if ret.id: + self.__tcRunLogger.debug( + "=== Creating Vlan Ip Range Successful===") + self.__addToCleanUp("VlanIpRange", ret.id) + except Exception as e: + print "Exception Occurred %s" % GetDetailExceptionInfo(e) + self.__tcRunLogger.\ + exception("=== Create Vlan Ip Range Failed===") + self.__cleanAndExit() def createSecondaryStorages(self, secondaryStorages, zoneId): - if secondaryStorages is None: - return - for secondary in secondaryStorages: - secondarycmd = addImageStore.addImageStoreCmd() - secondarycmd.url = secondary.url - secondarycmd.provider = secondary.provider - secondarycmd.details = [] + try: + if secondaryStorages is None: + return + for secondary in secondaryStorages: + secondarycmd = addImageStore.addImageStoreCmd() + secondarycmd.url = secondary.url + secondarycmd.provider = secondary.provider + secondarycmd.details = [] - if secondarycmd.provider == 'S3' \ - or secondarycmd.provider == "Swift": - for key, value in vars(secondary.details).iteritems(): - secondarycmd.details.append({ + if secondarycmd.provider == 'S3' \ + or secondarycmd.provider == "Swift": + for key, value in vars(secondary.details).iteritems(): + secondarycmd.details.append({ + 'key': key, + 'value': value + }) + if secondarycmd.provider == "NFS": + secondarycmd.zoneid = zoneId + ret = self.__apiClient.addImageStore(secondarycmd) + if ret.id: + self.__tcRunLogger.debug( + "===Add Image Store Successful===") + self.__addToCleanUp("ImageStore", ret.id) + except Exception as e: + print "Exception Occurred %s" % GetDetailExceptionInfo(e) + self.__tcRunLogger.\ + exception("=== Add Image Store Failed===") + self.__cleanAndExit() + + def createCacheStorages(self, cacheStorages, zoneId): + try: + if cacheStorages is None: + return + for cache in cacheStorages: + cachecmd = createSecondaryStagingStore.\ + createSecondaryStagingStoreCmd() + cachecmd.url = cache.url + cachecmd.provider = cache.provider + cachecmd.zoneid = zoneId + cachecmd.details = [] + + if cache.details: + for key, value in vars(cache.details).iteritems(): + cachecmd.details.append({ 'key': key, 'value': value }) - if secondarycmd.provider == "NFS": - secondarycmd.zoneid = zoneId - ret = self.__apiClient.addImageStore(secondarycmd) - if ret != FAILED and ret.id: - self.__tcRunLogger.debug("===Add Image Store Successful===") - self.__addToCleanUp("ImageStore", ret.id) - else: - self.__tcRunLogger.\ - exception("=== Add Image Store Failed===") - self.__cleanAndExit() - - def createCacheStorages(self, cacheStorages, zoneId): - if cacheStorages is None: - return - for cache in cacheStorages: - cachecmd = createSecondaryStagingStore.\ - createSecondaryStagingStoreCmd() - cachecmd.url = cache.url - cachecmd.provider = cache.provider - cachecmd.zoneid = zoneId - cachecmd.details = [] - - if cache.details: - for key, value in vars(cache.details).iteritems(): - cachecmd.details.append({ - 'key': key, - 'value': value - }) - ret = self.__apiClient.createSecondaryStagingStore(cachecmd) - if ret != FAILED and ret.id: - self.__tcRunLogger.debug( - "===Creating Secondary StagingStore Successful===") - self.__addToCleanUp("SecondaryStagingStore", ret.id) - else: - self.__tcRunLogger.\ - exception("=== Creating " - "SecondaryStagingStorage Failed===") - self.__cleanAndExit() + ret = self.__apiClient.createSecondaryStagingStore(cachecmd) + if ret.id: + self.__tcRunLogger.debug( + "===Creating Secondary StagingStore Successful===") + self.__addToCleanUp("SecondaryStagingStore", ret.id) + except Exception as e: + print "Exception Occurred %s" % GetDetailExceptionInfo(e) + self.__tcRunLogger.\ + exception("=== Creating " + "SecondaryStagingStorage Failed===") + self.__cleanAndExit() def createNetworks(self, networks, zoneId): - if networks is None: - return - for network in networks: - networkcmd = createNetwork.createNetworkCmd() - networkcmd.displaytext = network.displaytext - networkcmd.name = network.name - networkcmd.networkofferingid = network.networkofferingid - networkcmd.zoneid = zoneId + try: + if networks is None: + return + for network in networks: + networkcmd = createNetwork.createNetworkCmd() + networkcmd.displaytext = network.displaytext + networkcmd.name = network.name + networkcmd.networkofferingid = network.networkofferingid + networkcmd.zoneid = zoneId - ipranges = network.ipranges - if ipranges: - iprange = ipranges.pop() - networkcmd.startip = iprange.startip - networkcmd.endip = iprange.endip - networkcmd.gateway = iprange.gateway - networkcmd.netmask = iprange.netmask - networkcmdresponse = self.__apiClient.createNetwork(networkcmd) - if networkcmdresponse != \ - FAILED and networkcmdresponse.id: - networkId = networkcmdresponse.id - self.__tcRunLogger.\ - debug("Creating Network Name : %s Id : %s Successful" - % (str(network.name), str(networkId))) - self.__addToCleanUp("Network", networkId) - else: - self.__tcRunLogger.\ - exception("====Network : %s " - "Creation Failed=====" % str(network.name)) - self.__cleanAndExit() - return networkId + ipranges = network.ipranges + if ipranges: + iprange = ipranges.pop() + networkcmd.startip = iprange.startip + networkcmd.endip = iprange.endip + networkcmd.gateway = iprange.gateway + networkcmd.netmask = iprange.netmask + networkcmdresponse = self.__apiClient.createNetwork(networkcmd) + if networkcmdresponse.id: + networkId = networkcmdresponse.id + self.__tcRunLogger.\ + debug("Creating Network Name : %s Id : %s Successful" + % (str(network.name), str(networkId))) + self.__addToCleanUp("Network", networkId) + return networkId + except Exception as e: + print "Exception Occurred %s" % GetDetailExceptionInfo(e) + self.__tcRunLogger.\ + exception("====Network : %s " + "Creation Failed=====" % str(network.name)) + self.__cleanAndExit() def createPhysicalNetwork(self, net, zoneid): - phynet = createPhysicalNetwork.createPhysicalNetworkCmd() - phynet.zoneid = zoneid - phynet.name = net.name - phynet.isolationmethods = net.isolationmethods - phynetwrk = self.__apiClient.createPhysicalNetwork(phynet) - if phynetwrk != FAILED and phynetwrk.id: - self.__tcRunLogger.\ - debug("Creating Physical Network Name : " - "%s Id : %s Successful" % (str(phynet.name), - str(phynetwrk.id))) - self.__addToCleanUp("PhysicalNetwork", phynetwrk.id) - else: + try: + phynet = createPhysicalNetwork.createPhysicalNetworkCmd() + phynet.zoneid = zoneid + phynet.name = net.name + phynet.isolationmethods = net.isolationmethods + phynetwrk = self.__apiClient.createPhysicalNetwork(phynet) + if phynetwrk.id: + self.__tcRunLogger.\ + debug("Creating Physical Network Name : " + "%s Id : %s Successful" % (str(phynet.name), + str(phynetwrk.id))) + self.__addToCleanUp("PhysicalNetwork", phynetwrk.id) + self.addTrafficTypes(phynetwrk.id, net.traffictypes) + return phynetwrk + except Exception as e: + print "Exception Occurred %s" % GetDetailExceptionInfo(e) self.__tcRunLogger.exception("====Physical Network " "Creation Failed=====") self.__cleanAndExit() - self.addTrafficTypes(phynetwrk.id, net.traffictypes) - return phynetwrk def updatePhysicalNetwork(self, networkid, state="Enabled", vlan=None): - upnet = updatePhysicalNetwork.updatePhysicalNetworkCmd() - upnet.id = networkid - upnet.state = state - if vlan: - upnet.vlan = vlan - ret = self.__apiClient.updatePhysicalNetwork(upnet) - if ret == FAILED: + try: + upnet = updatePhysicalNetwork.updatePhysicalNetworkCmd() + upnet.id = networkid + upnet.state = state + if vlan: + upnet.vlan = vlan + ret = self.__apiClient.updatePhysicalNetwork(upnet) + return ret + except Exception as e: + print "Exception Occurred %s" % GetDetailExceptionInfo(e) self.__tcRunLogger.\ exception("====Update Physical Network Failed=====") self.__cleanAndExit() - return ret def enableProvider(self, provider_id): - upnetprov =\ - updateNetworkServiceProvider.updateNetworkServiceProviderCmd() - upnetprov.id = provider_id - upnetprov.state = "Enabled" - ret = self.__apiClient.updateNetworkServiceProvider(upnetprov) - if ret == FAILED: + try: + upnetprov =\ + updateNetworkServiceProvider.updateNetworkServiceProviderCmd() + upnetprov.id = provider_id + upnetprov.state = "Enabled" + ret = self.__apiClient.updateNetworkServiceProvider(upnetprov) + if ret.id: + self.__tcRunLogger.debug( + "===Update Network Service Provider Successfull===") + except Exception as e: + print "Exception Occurred %s" % GetDetailExceptionInfo(e) self.__tcRunLogger.\ - exception("====Update Network Service Provider Failed=====") + exception( + "====Update Network Service Provider Failed=====") self.__cleanAndExit() - else: - self.__tcRunLogger.debug( - "===Update Network Service Provider Successfull===") def configureProviders(self, phynetwrk, providers): """ We will enable the virtualrouter elements for all zones. Other providers like NetScalers, SRX, etc are explicitly added/configured """ - for provider in providers: - pnetprov = listNetworkServiceProviders.\ - listNetworkServiceProvidersCmd() - pnetprov.physicalnetworkid = phynetwrk.id - pnetprov.state = "Disabled" - pnetprov.name = provider.name - pnetprovres = self.__apiClient.listNetworkServiceProviders( - pnetprov) - if pnetprovres == FAILED: - self.__tcRunLogger.\ - exception("====List Network " - "Service Providers Failed=====") - self.__cleanAndExit() - - if pnetprovres and len(pnetprovres) > 0: - if provider.name == 'VirtualRouter'\ - or provider.name == 'VpcVirtualRouter': - vrprov = listVirtualRouterElements.\ - listVirtualRouterElementsCmd() - vrprov.nspid = pnetprovres[0].id - vrprovresponse = self.__apiClient.\ - listVirtualRouterElements(vrprov) - vrprovid = vrprovresponse[0].id - - vrconfig = \ - configureVirtualRouterElement.\ - configureVirtualRouterElementCmd() - vrconfig.enabled = "true" - vrconfig.id = vrprovid - if self.__apiClient.\ - configureVirtualRouterElement(vrconfig) == \ - FAILED: - self.__tcRunLogger.\ - exception("====ConfigureVirtualRouterElement " - "Failed=====") - self.__cleanAndExit() - self.enableProvider(pnetprovres[0].id) - elif provider.name == 'InternalLbVm': - internallbprov = listInternalLoadBalancerElements.\ - listInternalLoadBalancerElementsCmd() - internallbprov.nspid = pnetprovres[0].id - internallbresponse = self.__apiClient.\ - listInternalLoadBalancerElements(internallbprov) - if internallbresponse == FAILED: - self.__tcRunLogger.\ - exception("====List " - "InternalLoadBalancerElements " - "Failed=====") - self.__cleanAndExit() - internallbid = internallbresponse[0].id - internallbconfig = \ - configureInternalLoadBalancerElement.\ - configureInternalLoadBalancerElementCmd() - internallbconfig.enabled = "true" - internallbconfig.id = internallbid - if self.__apiClient.\ + try: + for provider in providers: + pnetprov = listNetworkServiceProviders.\ + listNetworkServiceProvidersCmd() + pnetprov.physicalnetworkid = phynetwrk.id + pnetprov.state = "Disabled" + pnetprov.name = provider.name + pnetprovres = self.__apiClient.listNetworkServiceProviders( + pnetprov) + if pnetprovres and len(pnetprovres) > 0: + if provider.name == 'VirtualRouter'\ + or provider.name == 'VpcVirtualRouter': + vrprov = listVirtualRouterElements.\ + listVirtualRouterElementsCmd() + vrprov.nspid = pnetprovres[0].id + vrprovresponse = self.__apiClient.\ + listVirtualRouterElements(vrprov) + vrprovid = vrprovresponse[0].id + vrconfig = \ + configureVirtualRouterElement.\ + configureVirtualRouterElementCmd() + vrconfig.enabled = "true" + vrconfig.id = vrprovid + self.__apiClient.\ + configureVirtualRouterElement(vrconfig) + self.enableProvider(pnetprovres[0].id) + elif provider.name == 'InternalLbVm': + internallbprov = listInternalLoadBalancerElements.\ + listInternalLoadBalancerElementsCmd() + internallbprov.nspid = pnetprovres[0].id + internallbresponse = self.__apiClient.\ + listInternalLoadBalancerElements(internallbprov) + internallbid = internallbresponse[0].id + internallbconfig = \ + configureInternalLoadBalancerElement.\ + configureInternalLoadBalancerElementCmd() + internallbconfig.enabled = "true" + internallbconfig.id = internallbid + self.__apiClient.\ configureInternalLoadBalancerElement( - internallbconfig) == FAILED: - self.__tcRunLogger.exception( - "==== Configure Internal LB Failed===") - self.__cleanAndExit() - self.enableProvider(pnetprovres[0].id) - elif provider.name == 'SecurityGroupProvider': - self.enableProvider(pnetprovres[0].id) - elif provider.name in ['Netscaler', 'JuniperSRX', 'F5BigIp']: - netprov = addNetworkServiceProvider.\ - addNetworkServiceProviderCmd() - netprov.name = provider.name - netprov.physicalnetworkid = phynetwrk.id - result = self.__apiClient.addNetworkServiceProvider(netprov) - if result != FAILED and result.id: - self.__tcRunLogger.\ - debug("==== AddNetworkServiceProvider " - "Successful=====") - self.__addToCleanUp("NetworkServiceProvider", result.id) - else: - self.__tcRunLogger.\ - exception("==== AddNetworkServiceProvider " - "Failed=====") - self.__cleanAndExit() - - for device in provider.devices: - if provider.name == 'Netscaler': - dev = addNetscalerLoadBalancer.\ - addNetscalerLoadBalancerCmd() - dev.username = device.username - dev.password = device.password - dev.networkdevicetype = device.networkdevicetype - dev.url = configGenerator.getDeviceUrl(device) - dev.physicalnetworkid = phynetwrk.id - ret = self.__apiClient.addNetscalerLoadBalancer(dev) - if ret != FAILED and ret.id: - self.__tcRunLogger.\ - debug("==== AddNetScalerLB " - "Successful=====") - self.__addToCleanUp( - "NetscalerLoadBalancer", - ret.id) + internallbconfig) + self.enableProvider(pnetprovres[0].id) + elif provider.name == 'SecurityGroupProvider': + self.enableProvider(pnetprovres[0].id) + elif provider.name in ['Netscaler', 'JuniperSRX', 'F5BigIp']: + netprov = addNetworkServiceProvider.\ + addNetworkServiceProviderCmd() + netprov.name = provider.name + netprov.physicalnetworkid = phynetwrk.id + result = self.__apiClient.addNetworkServiceProvider( + netprov) + if result.id: + self.__tcRunLogger.\ + debug("==== AddNetworkServiceProvider " + "Successful=====") + self.__addToCleanUp( + "NetworkServiceProvider", + result.id) + for device in provider.devices: + if provider.name == 'Netscaler': + dev = addNetscalerLoadBalancer.\ + addNetscalerLoadBalancerCmd() + dev.username = device.username + dev.password = device.password + dev.networkdevicetype = device.networkdevicetype + dev.url = configGenerator.getDeviceUrl(device) + dev.physicalnetworkid = phynetwrk.id + ret = self.__apiClient.addNetscalerLoadBalancer( + dev) + if ret.id: + self.__tcRunLogger.\ + debug("==== AddNetScalerLB " + "Successful=====") + self.__addToCleanUp( + "NetscalerLoadBalancer", + ret.id) + elif provider.name == 'JuniperSRX': + dev = addSrxFirewall.addSrxFirewallCmd() + dev.username = device.username + dev.password = device.password + dev.networkdevicetype = device.networkdevicetype + dev.url = configGenerator.getDeviceUrl(device) + dev.physicalnetworkid = phynetwrk.id + ret = self.__apiClient.addSrxFirewall(dev) + if ret.id: + self.__tcRunLogger.\ + debug("==== AddSrx " + "Successful=====") + self.__addToCleanUp("SrxFirewall", ret.id) + elif provider.name == 'F5BigIp': + dev = addF5LoadBalancer.addF5LoadBalancerCmd() + dev.username = device.username + dev.password = device.password + dev.networkdevicetype = device.networkdevicetype + dev.url = configGenerator.getDeviceUrl(device) + dev.physicalnetworkid = phynetwrk.id + ret = self.__apiClient.addF5LoadBalancer(dev) + if ret.id: + self.__tcRunLogger.\ + debug("==== AddF5 " + "Successful=====") + self.__addToCleanUp("F5LoadBalancer", ret.id) else: - self.__tcRunLogger.exception( - "===AddNetScalerLB Failed===") - self.__cleanAndExit() - - elif provider.name == 'JuniperSRX': - dev = addSrxFirewall.addSrxFirewallCmd() - dev.username = device.username - dev.password = device.password - dev.networkdevicetype = device.networkdevicetype - dev.url = configGenerator.getDeviceUrl(device) - dev.physicalnetworkid = phynetwrk.id - ret = self.__apiClient.addSrxFirewall(dev) - if ret != FAILED and ret.id: - self.__tcRunLogger.\ - debug("==== AddSrx " - "Successful=====") - self.__addToCleanUp("SrxFirewall", ret.id) - else: - self.__tcRunLogger.exception("===AddSrx Failed===") - self.__cleanAndExit() - - elif provider.name == 'F5BigIp': - dev = addF5LoadBalancer.addF5LoadBalancerCmd() - dev.username = device.username - dev.password = device.password - dev.networkdevicetype = device.networkdevicetype - dev.url = configGenerator.getDeviceUrl(device) - dev.physicalnetworkid = phynetwrk.id - ret = self.__apiClient.addF5LoadBalancer(dev) - if ret != FAILED and ret.id: - self.__tcRunLogger.\ - debug("==== AddF5 " - "Successful=====") - self.__addToCleanUp("F5LoadBalancer", ret.id) - else: - self.__tcRunLogger.exception("===AddF5 Failed===") - self.__cleanAndExit() - else: - raise InvalidParameterException("Device %s " - "doesn't match " - "any know provider " - "type" % device) - self.enableProvider(result.id) + raise InvalidParameterException( + "Device %s doesn't match " + "any know provider " + "type" % device) + self.enableProvider(result.id) + except Exception as e: + print "Exception Occurred %s" % GetDetailExceptionInfo(e) + self.__tcRunLogger.\ + exception("====List Network " + "Service Providers Failed=====") + self.__cleanAndExit() def addTrafficTypes(self, physical_network_id, traffictypes): [self.addTrafficType(physical_network_id, traffic_type) for traffic_type in traffictypes] def addTrafficType(self, physical_network_id, traffictype): - traffic_type = addTrafficType.addTrafficTypeCmd() - traffic_type.physicalnetworkid = physical_network_id - traffic_type.traffictype = traffictype.typ - traffic_type.kvmnetworklabel = traffictype.kvm\ - if traffictype.kvm is not None else None - traffic_type.xennetworklabel = traffictype.xen\ - if traffictype.xen is not None else None - traffic_type.vmwarenetworklabel = traffictype.vmware\ - if traffictype.vmware is not None else None - traffic_type.simulatorlabel = traffictype.simulator\ - if traffictype.simulator is not None else None - ret = self.__apiClient.addTrafficType(traffic_type) - if ret == FAILED: + try: + traffic_type = addTrafficType.addTrafficTypeCmd() + traffic_type.physicalnetworkid = physical_network_id + traffic_type.traffictype = traffictype.typ + traffic_type.kvmnetworklabel = traffictype.kvm\ + if traffictype.kvm is not None else None + traffic_type.xennetworklabel = traffictype.xen\ + if traffictype.xen is not None else None + traffic_type.vmwarenetworklabel = traffictype.vmware\ + if traffictype.vmware is not None else None + traffic_type.simulatorlabel = traffictype.simulator\ + if traffictype.simulator is not None else None + ret = self.__apiClient.addTrafficType(traffic_type) + if ret.id: + self.__tcRunLogger.debug("===Add TrafficType Successful====") + self.__addToCleanUp("TrafficType", ret.id) + return ret + except Exception as e: + print "Exception Occurred : %s" % GetDetailExceptionInfo(e) self.__tcRunLogger.\ exception("==== Add TrafficType Failed=====") self.__cleanAndExit() - else: - self.__tcRunLogger.debug("===Add TrafficType Successful====") - self.__addToCleanUp("TrafficType", ret.id) - return ret def enableZone(self, zoneid, allocation_state="Enabled"): - zoneCmd = updateZone.updateZoneCmd() - zoneCmd.id = zoneid - zoneCmd.allocationstate = allocation_state - ret = self.__apiClient.updateZone(zoneCmd) - if ret == FAILED: - self.__tcRunLogger.exception("==== Update Zone Failed=====") + try: + zoneCmd = updateZone.updateZoneCmd() + zoneCmd.id = zoneid + zoneCmd.allocationstate = allocation_state + ret = self.__apiClient.updateZone(zoneCmd) + if ret.id: + self.__tcRunLogger.debug("==== Enable Zone SuccessFul=====") + return ret + except Exception as e: + print "Exception Occurred : %s" % GetDetailExceptionInfo(e) + self.__tcRunLogger.exception("==== Enable Zone Failed=====") self.__cleanAndExit() - return ret def updateZoneDetails(self, zoneid, details): - zoneCmd = updateZone.updateZoneCmd() - zoneCmd.id = zoneid - zoneCmd.details = details - ret = self.__apiClient.updateZone(zoneCmd) - if ret == FAILED: + try: + zoneCmd = updateZone.updateZoneCmd() + zoneCmd.id = zoneid + zoneCmd.details = details + ret = self.__apiClient.updateZone(zoneCmd) + if ret.id: + self.__tcRunLogger.debug("=== Update Zone SuccessFul===") + return ret + except Exception as e: + print "Exception Occurred : %s" % GetDetailExceptionInfo(e) self.__tcRunLogger.exception("==== Update Zone Failed=====") self.__cleanAndExit() - return ret def createZone(self, zone, rec=0): try: zoneresponse = self.__apiClient.createZone(zone) - if zoneresponse == FAILED: + if zoneresponse.id: + self.__addToCleanUp("Zone", zoneresponse.id) + self.__tcRunLogger.\ + debug("Zone Name : %s Id : %s Created Successfully" % + (str(zone.name), str(zoneresponse.id))) + return zoneresponse.id + else: self.__tcRunLogger.\ exception("====Zone : %s Creation Failed=====" % str(zone.name)) @@ -635,137 +658,116 @@ class DeployDataCenters(object): print "\n====Recreating Zone With New Name ====", \ str(zone.name) return self.createZone(zone, 1) - else: - self.__addToCleanUp("Zone", zoneresponse.id) - self.__tcRunLogger.\ - debug("Zone Name : %s Id : %s Created Successfully" % - (str(zone.name), str(zoneresponse.id))) - return zoneresponse.id except Exception as e: - print "\nException Occurred under createZone %s" % \ + print "\nException Occurred under createZone : %s" % \ GetDetailExceptionInfo(e) return FAILED def createZones(self, zones): - for zone in zones: - zonecmd = createZone.createZoneCmd() - zonecmd.dns1 = zone.dns1 - zonecmd.dns2 = zone.dns2 - zonecmd.internaldns1 = zone.internaldns1 - zonecmd.internaldns2 = zone.internaldns2 - zonecmd.name = zone.name - zonecmd.securitygroupenabled = zone.securitygroupenabled - zonecmd.localstorageenabled = zone.localstorageenabled - zonecmd.networktype = zone.networktype - if zone.securitygroupenabled != "true": - zonecmd.guestcidraddress = zone.guestcidraddress - zoneId = self.createZone(zonecmd) - if zoneId == FAILED: - self.__tcRunLogger.\ - exception( - "====Zone: %s Creation Failed. So Exiting=====" % - str(zone.name)) - self.__cleanAndExit() - for pnet in zone.physical_networks: - phynetwrk = self.createPhysicalNetwork(pnet, zoneId) - self.configureProviders(phynetwrk, pnet.providers) - self.updatePhysicalNetwork(phynetwrk.id, "Enabled", - vlan=pnet.vlan) - if zone.networktype == "Basic": - listnetworkoffering =\ - listNetworkOfferings.listNetworkOfferingsCmd() - listnetworkoffering.name =\ - "DefaultSharedNetscalerEIPandELBNetworkOffering" \ - if len(filter(lambda x: - x.typ == 'Public', - zone.physical_networks[0]. - traffictypes)) > 0 \ - else "DefaultSharedNetworkOfferingWithSGService" - if zone.networkofferingname is not None: - listnetworkoffering.name = zone.networkofferingname - - listnetworkofferingresponse = \ - self.__apiClient.listNetworkOfferings(listnetworkoffering) - if listnetworkofferingresponse == FAILED: + try: + for zone in zones: + zonecmd = createZone.createZoneCmd() + zonecmd.dns1 = zone.dns1 + zonecmd.dns2 = zone.dns2 + zonecmd.internaldns1 = zone.internaldns1 + zonecmd.internaldns2 = zone.internaldns2 + zonecmd.name = zone.name + zonecmd.securitygroupenabled = zone.securitygroupenabled + zonecmd.localstorageenabled = zone.localstorageenabled + zonecmd.networktype = zone.networktype + if zone.securitygroupenabled != "true": + zonecmd.guestcidraddress = zone.guestcidraddress + zoneId = self.createZone(zonecmd) + if zoneId == FAILED: self.__tcRunLogger.\ - exception("==== " - "ListNetworkOfferingResponse Failed=====") + exception( + "====Zone: %s Creation Failed. So Exiting=====" % + str(zone.name)) self.__cleanAndExit() - guestntwrk = configGenerator.network() - guestntwrk.displaytext = "guestNetworkForBasicZone" - guestntwrk.name = "guestNetworkForBasicZone" - guestntwrk.zoneid = zoneId - guestntwrk.networkofferingid = \ - listnetworkofferingresponse[0].id - - networkid = self.createNetworks([guestntwrk], zoneId) - self.createPods(zone.pods, zoneId, networkid) - if self.isEipElbZone(zone): + for pnet in zone.physical_networks: + phynetwrk = self.createPhysicalNetwork(pnet, zoneId) + self.configureProviders(phynetwrk, pnet.providers) + self.updatePhysicalNetwork(phynetwrk.id, "Enabled", + vlan=pnet.vlan) + if zone.networktype == "Basic": + listnetworkoffering =\ + listNetworkOfferings.listNetworkOfferingsCmd() + listnetworkoffering.name =\ + "DefaultSharedNetscalerEIPandELBNetworkOffering" \ + if len(filter(lambda x: + x.typ == 'Public', + zone.physical_networks[0]. + traffictypes)) > 0 \ + else "DefaultSharedNetworkOfferingWithSGService" + if zone.networkofferingname is not None: + listnetworkoffering.name = zone.networkofferingname + listnetworkofferingresponse = \ + self.__apiClient.listNetworkOfferings( + listnetworkoffering) + guestntwrk = configGenerator.network() + guestntwrk.displaytext = "guestNetworkForBasicZone" + guestntwrk.name = "guestNetworkForBasicZone" + guestntwrk.zoneid = zoneId + guestntwrk.networkofferingid = \ + listnetworkofferingresponse[0].id + networkid = self.createNetworks([guestntwrk], zoneId) + self.createPods(zone.pods, zoneId, networkid) + if self.isEipElbZone(zone): + self.createVlanIpRanges( + zone.networktype, zone.ipranges, + zoneId, forvirtualnetwork=True) + isPureAdvancedZone = (zone.networktype == "Advanced" + and zone.securitygroupenabled != "true") + if isPureAdvancedZone: + self.createPods(zone.pods, zoneId) self.createVlanIpRanges(zone.networktype, zone.ipranges, - zoneId, forvirtualnetwork=True) - - isPureAdvancedZone = (zone.networktype == "Advanced" - and zone.securitygroupenabled != "true") - if isPureAdvancedZone: - self.createPods(zone.pods, zoneId) - self.createVlanIpRanges(zone.networktype, zone.ipranges, - zoneId) - elif (zone.networktype == "Advanced" - and zone.securitygroupenabled == "true"): - listnetworkoffering =\ - listNetworkOfferings.listNetworkOfferingsCmd() - listnetworkoffering.name =\ - "DefaultSharedNetworkOfferingWithSGService" - if zone.networkofferingname is not None: - listnetworkoffering.name = zone.networkofferingname - listnetworkofferingresponse = \ - self.__apiClient.listNetworkOfferings(listnetworkoffering) - if listnetworkofferingresponse == FAILED: - self.__tcRunLogger.\ - exception("==== ListNetworkOfferingResponse " - "Failed=====") - self.__cleanAndExit() - networkcmd = createNetwork.createNetworkCmd() - networkcmd.displaytext = "Shared SG enabled network" - networkcmd.name = "Shared SG enabled network" - networkcmd.networkofferingid =\ - listnetworkofferingresponse[0].id - networkcmd.zoneid = zoneId - - ipranges = zone.ipranges - if ipranges: - iprange = ipranges.pop() - networkcmd.startip = iprange.startip - networkcmd.endip = iprange.endip - networkcmd.gateway = iprange.gateway - networkcmd.netmask = iprange.netmask - networkcmd.vlan = iprange.vlan - - networkcmdresponse = self.__apiClient.createNetwork(networkcmd) - if networkcmdresponse != \ - FAILED and networkcmdresponse.id: - self.__addToCleanUp("Network", networkcmdresponse.id) - self.__tcRunLogger.\ - debug("create Network Successful. NetworkId : %s " - % str(networkcmdresponse.id)) - else: - self.__tcRunLogger.\ - exception("====Create Network Failed=====") - self.__cleanAndExit() - self.createPods(zone.pods, zoneId, networkcmdresponse.id) - - '''Note: Swift needs cache storage first''' - self.createCacheStorages(zone.cacheStorages, zoneId) - self.createSecondaryStorages(zone.secondaryStorages, zoneId) - - enabled = getattr(zone, 'enabled', 'True') - if enabled == 'True' or enabled is None: - self.enableZone(zoneId, "Enabled") - details = getattr(zone, 'details') - if details is not None: - det = [d.__dict__ for d in details] - self.updateZoneDetails(zoneId, det) - return + zoneId) + elif (zone.networktype == "Advanced" + and zone.securitygroupenabled == "true"): + listnetworkoffering =\ + listNetworkOfferings.listNetworkOfferingsCmd() + listnetworkoffering.name =\ + "DefaultSharedNetworkOfferingWithSGService" + if zone.networkofferingname is not None: + listnetworkoffering.name = zone.networkofferingname + listnetworkofferingresponse = \ + self.__apiClient.listNetworkOfferings( + listnetworkoffering) + networkcmd = createNetwork.createNetworkCmd() + networkcmd.displaytext = "Shared SG enabled network" + networkcmd.name = "Shared SG enabled network" + networkcmd.networkofferingid =\ + listnetworkofferingresponse[0].id + networkcmd.zoneid = zoneId + ipranges = zone.ipranges + if ipranges: + iprange = ipranges.pop() + networkcmd.startip = iprange.startip + networkcmd.endip = iprange.endip + networkcmd.gateway = iprange.gateway + networkcmd.netmask = iprange.netmask + networkcmd.vlan = iprange.vlan + networkcmdresponse = self.__apiClient.createNetwork( + networkcmd) + if networkcmdresponse.id: + self.__addToCleanUp("Network", networkcmdresponse.id) + self.__tcRunLogger.\ + debug("create Network Successful. NetworkId : %s " + % str(networkcmdresponse.id)) + self.createPods(zone.pods, zoneId, networkcmdresponse.id) + '''Note: Swift needs cache storage first''' + self.createCacheStorages(zone.cacheStorages, zoneId) + self.createSecondaryStorages(zone.secondaryStorages, zoneId) + enabled = getattr(zone, 'enabled', 'True') + if enabled == 'True' or enabled is None: + self.enableZone(zoneId, "Enabled") + details = getattr(zone, 'details') + if details is not None: + det = [d.__dict__ for d in details] + self.updateZoneDetails(zoneId, det) + return + except Exception as e: + print "\nException Occurred %s" % GetDetailExceptionInfo(e) def isEipElbZone(self, zone): if (zone.networktype == "Basic" @@ -782,20 +784,22 @@ class DeployDataCenters(object): self.__apiClient = self.__testClient.getApiClient() def updateConfiguration(self, globalCfg): - if globalCfg is None or self.__apiClient is None: - return None - - for config in globalCfg: - updateCfg = updateConfiguration.updateConfigurationCmd() - updateCfg.name = config.name - updateCfg.value = config.value - if self.__apiClient.updateConfiguration(updateCfg) == FAILED: - self.__tcRunLogger.\ - exception("===UpdateConfiguration Failed===") - self.__cleanAndExit() - else: - self.__tcRunLogger.debug( - "==UpdateConfiguration Successfull===") + try: + if globalCfg is None or self.__apiClient is None: + return None + for config in globalCfg: + updateCfg = updateConfiguration.updateConfigurationCmd() + updateCfg.name = config.name + updateCfg.value = config.value + ret = self.__apiClient.updateConfiguration(updateCfg) + if ret.id: + self.__tcRunLogger.debug( + "==UpdateConfiguration Successfull===") + except Exception as e: + print "Exception Occurred %s" % GetDetailExceptionInfo(e) + self.__tcRunLogger.\ + exception("===UpdateConfiguration Failed===") + self.__cleanAndExit() def copyAttributesToCommand(self, source, command): map(lambda attr: setattr(command, attr, getattr(source, attr, None)), @@ -803,15 +807,16 @@ class DeployDataCenters(object): ["required", "isAsync"], dir(command))) def configureS3(self, s3): - if s3 is None: - return - command = addS3.addS3Cmd() - self.copyAttributesToCommand(s3, command) - ret = self.__apiClient.addS3(command) - if ret != FAILED and ret.id: - self.__tcRunLogger.debug("===AddS3 Successfull===") - self.__addToCleanUp("s3", ret.id) - else: + try: + if s3 is None: + return + command = addS3.addS3Cmd() + self.copyAttributesToCommand(s3, command) + ret = self.__apiClient.addS3(command) + if ret.id: + self.__tcRunLogger.debug("===AddS3 Successfull===") + self.__addToCleanUp("s3", ret.id) + except Exception as e: self.__tcRunLogger.exception("====AddS3 Failed===") self.__cleanAndExit() @@ -819,13 +824,25 @@ class DeployDataCenters(object): try: print "\n==== Deploy DC Started ====" self.__tcRunLogger.debug("\n==== Deploy DC Started ====") + ''' + Step1 : Set the Client + ''' self.setClient() + ''' + Step2: Update the Configuration + ''' self.updateConfiguration(self.__config.globalConfig) + ''' + Step3 :Deploy the Zone + ''' self.createZones(self.__config.zones) self.configureS3(self.__config.s3) + ''' + Persist the Configuration to an external file post DC creation + ''' self.__persistDcConfig() - self.__tcRunLogger.debug("\n====Deploy DC Successful====") print "\n====Deploy DC Successful=====" + self.__tcRunLogger.debug("\n====Deploy DC Successful====") return SUCCESS except Exception as e: print "\nException Occurred Under deploy :%s" % \ @@ -836,12 +853,18 @@ class DeployDataCenters(object): return FAILED -class DeleteDataCenter: +class DeleteDataCenters: ''' @Desc : Deletes the Data Center using the settings provided. - Reads the Configuration provided from file - Uses the read configuration to delete the DataCenter + tc_client :Client for deleting the DC. + dc_cfg_file : obj file exported by DeployDataCenter + when successfully created DC. + This file is serialized one containing + entries with successful DC. + dc_cfg: If dc_cfg_file, is not available, we can use + the dictionary of elements to delete. + tc_run_logger: Logger to dump log messages. ''' def __init__(self, @@ -861,7 +884,7 @@ class DeleteDataCenter: @Name : __deleteCmds @Desc : Deletes the entities provided by cmd ''' - if cmd_name == "deleteHostCmd": + if cmd_name.lower() == "deletehostcmd": cmd_obj.forcedestroylocalstorage = "true" cmd_obj.force = "true" ''' @@ -872,7 +895,7 @@ class DeleteDataCenter: host_maint_cmd.id = cmd_obj.id host_maint_resp = self.__apiClient.prepareHostForMaintenance( host_maint_cmd) - if host_maint_resp != FAILED: + if host_maint_resp: ''' Step2 : List Hosts for Resource State ''' @@ -882,25 +905,25 @@ class DeleteDataCenter: for i in xrange(retries): list_host_resp = self.__apiClient.\ listHosts(list_host_cmd) - if (list_host_resp != FAILED) and\ + if (list_host_resp) and\ (list_host_resp[0].resourcestate == 'Maintenance'): break sleep(30) - if cmd_name == "deleteStorage": + if cmd_name.lower() == "deletestoragepoolcmd": cmd_obj.forced = "true" store_maint_cmd = enableStorageMaintenance.\ enableStorageMaintenanceCmd() store_maint_cmd.id = cmd_obj.id store_maint_resp = self.__apiClient.\ enableStorageMaintenance(store_maint_cmd) - if store_maint_resp != FAILED: + if store_maint_resp: list_store_cmd = listStoragePools.listStoragePoolsCmd() list_store_cmd.id = cmd_obj.id retries = 3 for i in xrange(retries): store_maint_resp = self.__apiClient.\ listStoragePools(list_store_cmd) - if (store_maint_resp != FAILED) and \ + if (store_maint_resp) and \ (store_maint_resp[0].state == 'Maintenance'): break sleep(30) @@ -946,7 +969,7 @@ class DeleteDataCenter: del_cmd_obj) del_func = getattr(self.__apiClient, del_mod) del_cmd_resp = del_func(del_cmd_obj) - if del_cmd_resp == FAILED: + if del_cmd_resp: self.__tcRunLogger.debug( "====%s CleanUp Failed. ID: %s ===" % (type, id)) @@ -994,9 +1017,14 @@ class DeleteDataCenter: if __name__ == "__main__": ''' - @Desc : This facility is mainly to deploy + @Desc : 1. This facility is mainly to deploy DataCenter by using this module as script by using the input provided configuration. + EX: python deployDataCenter.py -i + 2. Removes a DataCenter as well by providing + the input file + EX: python deployDataCenter.py -i + -r ''' parser = OptionParser() parser.add_option("-i", "--input", action="store", @@ -1016,7 +1044,7 @@ if __name__ == "__main__": if options.input is None and options.remove is None: print "\n==== For DeployDataCenter: Please Specify a " \ "Valid Input Configuration File====" - print "\n==== For DeleteDataCenter: Please Specify a " \ + print "\n==== For DeleteDataCenters: Please Specify a " \ "Valid DC Exported Configuration Settings or File====" exit(1) @@ -1068,10 +1096,10 @@ if __name__ == "__main__": ''' @Desc : Removes a Data Center with provided Config ''' - remove_dc_obj = DeleteDataCenter(obj_tc_client, - dc_cfg_file=options.remove, - tc_run_logger=tc_run_logger - ) + remove_dc_obj = DeleteDataCenters(obj_tc_client, + dc_cfg_file=options.remove, + tc_run_logger=tc_run_logger + ) if remove_dc_obj: if remove_dc_obj.removeDataCenter() == FAILED: print "\n===Removing DataCenter Failed===" diff --git a/tools/marvin/marvin/jsonHelper.py b/tools/marvin/marvin/jsonHelper.py index f7db5ba7829..3f48a00ba68 100644 --- a/tools/marvin/marvin/jsonHelper.py +++ b/tools/marvin/marvin/jsonHelper.py @@ -18,11 +18,13 @@ import cloudstackException import json import inspect -from cloudstackAPI import * +from marvin.cloudstackAPI import * class jsonLoader(object): + '''The recursive class for building and representing objects with.''' + def __init__(self, obj): for k in obj: v = obj[k] @@ -52,6 +54,7 @@ class jsonLoader(object): class jsonDump(object): + @staticmethod def __serialize(obj): """Recursively walk object's hierarchy.""" @@ -247,7 +250,7 @@ due to missing parameter jobid" }''' try: asynJob = getResultObj(result) - except cloudstackException.CloudstackAPIException, e: + except cloudstackException.CloudstackAPIException as e: print e result = '{ "queryasyncjobresultresponse" : {} }' diff --git a/tools/marvin/marvin/marvinInit.py b/tools/marvin/marvin/marvinInit.py index 7ceba78911d..ba7c4de0130 100644 --- a/tools/marvin/marvin/marvinInit.py +++ b/tools/marvin/marvin/marvinInit.py @@ -24,26 +24,17 @@ for starting it. 3. Deploys the Data Center based upon input. ''' -import marvin -from marvin import configGenerator +from marvin.configGenerator import getSetupConfig from marvin.marvinLog import MarvinLog from marvin.deployDataCenter import DeployDataCenters from marvin.cloudstackTestClient import CSTestClient from marvin.cloudstackException import GetDetailExceptionInfo from marvin.codes import( - PASS, - YES, - NO, + XEN_SERVER, SUCCESS, FAILED ) -import sys -import time import os -import logging -import string -import random -from sys import exit class MarvinInit: @@ -51,7 +42,8 @@ class MarvinInit: def __init__(self, config_file, deploy_dc_flag=None, test_mod_name="deploydc", - zone=None): + zone=None, + hypervisor_type=None): self.__configFile = config_file self.__deployFlag = deploy_dc_flag self.__logFolderPath = None @@ -62,6 +54,7 @@ class MarvinInit: self.__testDataFilePath = None self.__zoneForTests = zone self.__parsedConfig = None + self.__hypervisorType = hypervisor_type def __parseConfig(self): ''' @@ -74,8 +67,7 @@ class MarvinInit: if not os.path.isfile(self.__configFile): print "\n=== Marvin Parse Config Init Failed ===" return FAILED - self.__parsedConfig = configGenerator.\ - getSetupConfig(self.__configFile) + self.__parsedConfig = getSetupConfig(self.__configFile) print "\n=== Marvin Parse Config Successful ===" return SUCCESS except Exception as e: @@ -107,6 +99,26 @@ class MarvinInit: "/results.txt", "w") return self.__tcResultFile + def __setHypervisorAndZoneInfo(self): + ''' + @Name : __setHypervisorAndZoneInfo + @Desc: Set the HyperVisor and Zone details; + default to XenServer + ''' + try: + if not self.__hypervisorType: + self.__hypervisorType = XEN_SERVER + if not self.__zoneForTests: + if self.__parsedConfig: + for zone in self.__parsedConfig.zones: + self.__zoneForTests = zone.name + break + return SUCCESS + except Exception as e: + print "\n Exception Occurred Under init " \ + "%s" % GetDetailExceptionInfo(e) + return FAILED + def init(self): ''' @Name : init @@ -120,6 +132,7 @@ class MarvinInit: ''' try: if ((self.__parseConfig() != FAILED) and + (self.__setHypervisorAndZoneInfo())and (self.__setTestDataPath() != FAILED) and (self.__initLogging() != FAILED) and (self.__createTestClient() != FAILED) and @@ -153,7 +166,7 @@ class MarvinInit: if ret != FAILED: self.__logFolderPath = log_obj.getLogFolderPath() self.__tcRunLogger = log_obj.getLogger() - print "\n=== Marvin Init Logging Sccessful===" + print "\n=== Marvin Init Logging Successful===" return SUCCESS return FAILED except Exception as e: @@ -175,11 +188,12 @@ class MarvinInit: logger=self.__tcRunLogger, test_data_filepath= self.__testDataFilePath, - zone=self.__zoneForTests) + zone=self.__zoneForTests, + hypervisor_type= + self.__hypervisorType) if self.__testClient: return self.__testClient.createTestClient() - else: - return FAILED + return FAILED except Exception as e: print "\n Exception Occurred Under __createTestClient : %s" % \ GetDetailExceptionInfo(e) @@ -195,7 +209,7 @@ class MarvinInit: if ((self.__parsedConfig.TestData is not None) and (self.__parsedConfig.TestData.Path is not None)): self.__testDataFilePath = self.__parsedConfig.TestData.Path - print "\n=== Marvin TestData Successful===" + print "\n=== Marvin Setting TestData Successful===" return SUCCESS except Exception as e: print "\nException Occurred Under __setTestDataPath : %s" % \ diff --git a/tools/marvin/marvin/marvinLog.py b/tools/marvin/marvin/marvinLog.py index f62c35a9593..075f33a5f2b 100644 --- a/tools/marvin/marvin/marvinLog.py +++ b/tools/marvin/marvin/marvinLog.py @@ -28,6 +28,7 @@ from marvin.cloudstackException import GetDetailExceptionInfo class MarvinLog: + ''' @Name : MarvinLog @Desc : provides interface for logging to marvin @@ -89,7 +90,7 @@ class MarvinLog: stream.setLevel(log_level) self.__logger.addHandler(stream) return SUCCESS - except Exception, e: + except Exception as e: print "\nException Occurred Under " \ "__setLogHandler %s" % GetDetailExceptionInfo(e) return FAILED @@ -104,7 +105,7 @@ class MarvinLog: try: if os.path.isdir(logfolder_to_remove): os.rmdir(logfolder_to_remove) - except Exception, e: + except Exception as e: print "\n Exception Occurred Under __cleanPreviousLogs :%s" % \ GetDetailExceptionInfo(e) return FAILED @@ -151,8 +152,8 @@ class MarvinLog: log_cfg.__dict__.get('LogFolderPath') + "/MarvinLogs" self.__logFolderDir = temp_dir + "//" + temp_path - print "\n*********Log Folder Path: %s. " \ - "All logs will be available here **************" \ + print "\n==== Log Folder Path: %s. " \ + "All logs will be available here ====" \ % str(self.__logFolderDir) os.makedirs(self.__logFolderDir) @@ -171,7 +172,7 @@ class MarvinLog: log_level=logging.FATAL) return SUCCESS return FAILED - except Exception, e: + except Exception as e: print "\n Exception Occurred Under createLogs :%s" % \ GetDetailExceptionInfo(e) return FAILED diff --git a/tools/marvin/marvin/marvinPlugin.py b/tools/marvin/marvin/marvinPlugin.py index 6525cd2cb3c..4fee27aedcb 100644 --- a/tools/marvin/marvin/marvinPlugin.py +++ b/tools/marvin/marvin/marvinPlugin.py @@ -61,7 +61,8 @@ class MarvinPlugin(Plugin): self.__startTime = None self.__testName = None self.__tcRunLogger = None - self.__testModName = None + self.__testModName = '' + self.__hypervisorType = None Plugin.__init__(self) def configure(self, options, conf): @@ -70,15 +71,15 @@ class MarvinPlugin(Plugin): self.enabled (True|False) determines whether marvin's tests will run. By default non-default plugins like marvin will be disabled """ + self.enabled = True if hasattr(options, self.enableOpt): if not getattr(options, self.enableOpt): self.enabled = False return - else: - self.enabled = True self.__configFile = options.configFile self.__deployDcFlag = options.deployDc self.__zoneForTests = options.zone + self.__hypervisorType = options.hypervisor_type self.conf = conf if self.startMarvin() == FAILED: print "\nStarting Marvin Failed, exiting. Please Check" @@ -105,6 +106,11 @@ class MarvinPlugin(Plugin): default=None, dest="zone", help="Runs all tests against this specified zone") + parser.add_option("--hypervisor", action="store", + default=None, + dest="hypervisor_type", + help="Runs all tests against the specified " + "zone and hypervisor Type") Plugin.options(self, parser, env) def wantClass(self, cls): @@ -148,9 +154,10 @@ class MarvinPlugin(Plugin): self._injectClients(cls) def beforeTest(self, test): - #self.__testModName = test.__str__() + self.__testModName = test.__str__() self.__testName = test.__str__().split()[0] - self.__testClient.identifier = '-'.join([self.__identifier, self.__testName]) + self.__testClient.identifier = '-'.\ + join([self.__identifier, self.__testName]) if self.__tcRunLogger: self.__tcRunLogger.name = test.__str__() @@ -199,19 +206,6 @@ class MarvinPlugin(Plugin): self.printMsg(FAILED, self.__testName, GetDetailExceptionInfo(err)) self.__testResult = FAILED - def __getModName(self, inp, type='file'): - ''' - @Desc : Returns the module name from the path - @Output: trimmed down module name, used for logging - @Input: type:Whether the type is file or dir - inp:input element - ''' - if type == 'file': - temp = os.path.splitext(inp)[0] - return os.path.split(temp)[-1] - if type == 'dir': - return os.path.split(inp)[-1] - def startMarvin(self): ''' @Name : startMarvin @@ -225,7 +219,8 @@ class MarvinPlugin(Plugin): obj_marvininit = MarvinInit(self.__configFile, self.__deployDcFlag, None, - self.__zoneForTests) + self.__zoneForTests, + self.__hypervisorType) if obj_marvininit and obj_marvininit.init() == SUCCESS: self.__testClient = obj_marvininit.getTestClient() self.__tcRunLogger = obj_marvininit.getLogger() diff --git a/tools/marvin/marvin/sshClient.py b/tools/marvin/marvin/sshClient.py index c24477cb999..fb4e18b4608 100644 --- a/tools/marvin/marvin/sshClient.py +++ b/tools/marvin/marvin/sshClient.py @@ -28,19 +28,21 @@ import time from marvin.cloudstackException import ( internalError, GetDetailExceptionInfo - ) +) import contextlib import logging from marvin.codes import ( SUCCESS, FAILED, INVALID_INPUT, EXCEPTION_OCCURRED - ) +) from contextlib import closing class SshClient(object): + ''' Added timeout flag for ssh connect calls.Default to 3.0 seconds ''' + def __init__(self, host, port, user, passwd, retries=20, delay=30, log_lvl=logging.DEBUG, keyPairFiles=None, timeout=10.0): self.host = None @@ -58,8 +60,8 @@ class SshClient(object): ch.setLevel(log_lvl) self.logger.addHandler(ch) - #Check invalid host value and raise exception - #Atleast host is required for connection + # Check invalid host value and raise exception + # Atleast host is required for connection if host is not None and host != '': self.host = host if retries is not None and retries > 0: @@ -126,15 +128,15 @@ class SshClient(object): % (str(self.host), str(self.port))) ret = SUCCESS break - except BadHostKeyException, e: + except BadHostKeyException as e: except_msg = GetDetailExceptionInfo(e) - except AuthenticationException, e: + except AuthenticationException as e: except_msg = GetDetailExceptionInfo(e) - except SSHException, e: + except SSHException as e: except_msg = GetDetailExceptionInfo(e) - except socket.error, e: + except socket.error as e: except_msg = GetDetailExceptionInfo(e) - except Exception, e: + except Exception as e: except_msg = GetDetailExceptionInfo(e) finally: if self.retryCnt == 0 or ret == SUCCESS: @@ -188,7 +190,7 @@ class SshClient(object): sftp = SFTPClient.from_transport(transport) try: sftp.put(srcFile, destPath) - except IOError, e: + except IOError as e: raise e def __del__(self): diff --git a/tools/marvin/marvin/tcExecuteEngine.py b/tools/marvin/marvin/tcExecuteEngine.py index c4373372e62..e2f4d114b79 100644 --- a/tools/marvin/marvin/tcExecuteEngine.py +++ b/tools/marvin/marvin/tcExecuteEngine.py @@ -23,6 +23,7 @@ from functools import partial class TestCaseExecuteEngine(object): + def __init__(self, testclient, config, tc_logger=None, debug_stream=None): """ Initialize the testcase execution engine, just the basics here @@ -53,7 +54,7 @@ class TestCaseExecuteEngine(object): if isinstance(test, unittest.BaseTestSuite): self.injectTestCase(test) else: - #inject testclient and logger into each unittest + # inject testclient and logger into each unittest self.tcRunLogger.name = test.__str__() setattr(test, "testClient", self.testclient) setattr(test, "config", self.config) diff --git a/tools/marvin/marvin/testSetupSuccess.py b/tools/marvin/marvin/testSetupSuccess.py index 1701626a820..8b000f9e97c 100644 --- a/tools/marvin/marvin/testSetupSuccess.py +++ b/tools/marvin/marvin/testSetupSuccess.py @@ -23,6 +23,7 @@ from time import sleep as delay class TestSetupSuccess(cloudstackTestCase): + """ Test to verify if the cloudstack is ready to launch tests upon 1. Verify that system VMs are up and running in all zones