CLOUDSTACk-5674: Added few misc changes to make it work.

This commit is contained in:
Santhosh Edukulla 2014-02-12 17:33:13 +05:30 committed by Girish Shilamkar
parent c1d34369aa
commit 7cc9423b8d
10 changed files with 110 additions and 86 deletions

View File

@ -16,7 +16,7 @@
# under the License. # under the License.
import threading import threading
import cloudstackException from marvin import cloudstackException
import time import time
import Queue import Queue
import copy import copy

View File

@ -38,7 +38,7 @@ from requests import (
Timeout, Timeout,
RequestException RequestException
) )
from cloudstackException import GetDetailExceptionInfo from marvin.cloudstackException import GetDetailExceptionInfo
class CSConnection(object): class CSConnection(object):

View File

@ -26,26 +26,24 @@ from codes import (FAILED, PASS, ADMIN, DOMAIN_ADMIN,
USER, SUCCESS, XEN_SERVER) USER, SUCCESS, XEN_SERVER)
from configGenerator import ConfigManager from configGenerator import ConfigManager
from marvin.lib import utils from marvin.lib import utils
from cloudstackException import GetDetailExceptionInfo from marvin.cloudstackException import GetDetailExceptionInfo
from marvin.lib.utils import (random_gen, validateList) from marvin.lib.utils import (random_gen, validateList)
from marvin.cloudstackAPI.cloudstackAPIClient import CloudStackAPIClient from marvin.cloudstackAPI.cloudstackAPIClient import CloudStackAPIClient
''' class CSTestClient(object):
@Desc : CloudStackTestClient is encapsulated entity for creating and '''
@Desc : CloudStackTestClient is encapsulated entity for creating and
getting various clients viz., apiclient, getting various clients viz., apiclient,
user api client, dbconnection, test Data parsed user api client, dbconnection, test Data parsed
information etc information etc
@Input : mgmtDetails : Management Server Details @Input : mgmtDetails : Management Server Details
dbSvrDetails: Database Server details of Management \ dbSvrDetails: Database Server details of Management \
Server. Retrieved from configuration file. Server. Retrieved from configuration file.
asyncTimeout : Timeout for Async queries asyncTimeout : Timeout for Async queries
defaultWorkerThreads : Number of worker threads defaultWorkerThreads : Number of worker threads
logger : provides logging facilities for this library logger : provides logging facilities for this library
zone : The zone on which test suites using this test client will run zone : The zone on which test suites using this test client will run
''' '''
class CSTestClient(object):
def __init__(self, mgmt_details, def __init__(self, mgmt_details,
dbsvr_details, dbsvr_details,
async_timeout=3600, async_timeout=3600,

View File

@ -20,7 +20,7 @@ import contextlib
from mysql import connector from mysql import connector
from mysql.connector import errors from mysql.connector import errors
from contextlib import closing from contextlib import closing
import cloudstackException from marvin import cloudstackException
import sys import sys
import os import os

View File

@ -686,7 +686,7 @@ if __name__ == "__main__":
log_check = False log_check = False
if log_obj is not None: if log_obj is not None:
log_check = True log_check = True
ret = log_obj.createLogs("DataCenter", ret = log_obj.createLogs("DeployDataCenter",
cfg.logger) cfg.logger)
if ret != FAILED: if ret != FAILED:
log_folder_path = log_obj.getLogFolderPath() log_folder_path = log_obj.getLogFolderPath()

View File

@ -30,7 +30,7 @@ import urlparse
import datetime import datetime
from platform import system from platform import system
from marvin.cloudstackAPI import cloudstackAPIClient, listHosts from marvin.cloudstackAPI import cloudstackAPIClient, listHosts
from cloudstackException import GetDetailExceptionInfo from marvin.cloudstackException import GetDetailExceptionInfo
from marvin.sshClient import SshClient from marvin.sshClient import SshClient
from marvin.codes import ( from marvin.codes import (
SUCCESS, SUCCESS,

View File

@ -15,7 +15,7 @@
# specific language governing permissions and limitations # specific language governing permissions and limitations
# under the License. # under the License.
''' '''
@Desc: Initializes the marvin and does required prerequisites Initializes the marvin and does required prerequisites
for starting it. for starting it.
1. Parses the configuration file passed to marvin and creates a 1. Parses the configuration file passed to marvin and creates a
parsed config parsed config
@ -25,8 +25,7 @@ for starting it.
''' '''
from marvin import configGenerator from marvin.configGenerator import getSetupConfig
from marvin import cloudstackException
from marvin.marvinLog import MarvinLog from marvin.marvinLog import MarvinLog
from marvin.deployDataCenter import DeployDataCenters from marvin.deployDataCenter import DeployDataCenters
from marvin.cloudstackTestClient import CSTestClient from marvin.cloudstackTestClient import CSTestClient
@ -49,7 +48,8 @@ from marvin.codegenerator import CodeGenerator
class MarvinInit: class MarvinInit:
def __init__(self, config_file, load_api_flag=None, def __init__(self, config_file,
load_api_flag=None,
deploy_dc_flag=None, deploy_dc_flag=None,
test_module_name=None, test_module_name=None,
zone=None): zone=None):
@ -67,14 +67,14 @@ class MarvinInit:
def __parseConfig(self): def __parseConfig(self):
''' '''
@Name: __parseConfig
@Desc : Parses the configuration file passed and assigns @Desc : Parses the configuration file passed and assigns
the parsed configuration the parsed configuration
@Output : SUCCESS or FAILED
''' '''
try: try:
if self.__configFile is None: self.__parsedConfig = getSetupConfig(self.__configFile)
return FAILED
self.__parsedConfig = configGenerator.\
getSetupConfig(self.__configFile)
return SUCCESS return SUCCESS
except Exception, e: except Exception, e:
print "\nException Occurred Under __parseConfig : " \ print "\nException Occurred Under __parseConfig : " \
@ -94,6 +94,11 @@ class MarvinInit:
return self.__tcRunLogger return self.__tcRunLogger
def getDebugFile(self): def getDebugFile(self):
'''
@Name : getDebugFile
@Desc : Returns the Result file to be used for writing
test outputs
'''
if self.__logFolderPath is not None: if self.__logFolderPath is not None:
self.__tcResultFile = open(self.__logFolderPath + self.__tcResultFile = open(self.__logFolderPath +
"/results.txt", "w") "/results.txt", "w")
@ -108,6 +113,7 @@ class MarvinInit:
2. Creates a timestamped log folder and provides all logs 2. Creates a timestamped log folder and provides all logs
to be dumped there to be dumped there
3. Creates the DataCenter based upon configuration provided 3. Creates the DataCenter based upon configuration provided
@Output : SUCCESS or FAILED
''' '''
try: try:
if ((self.__parseConfig() != FAILED) and if ((self.__parseConfig() != FAILED) and
@ -125,9 +131,9 @@ class MarvinInit:
return FAILED return FAILED
def __initLogging(self): def __initLogging(self):
try: '''
''' @Name : __initLogging
@Desc : 1. Initializes the logging for marvin and so provides @Desc : 1. Initializes the logging for marvin and so provides
various log features for automation run. various log features for automation run.
2. Initializes all logs to be available under 2. Initializes all logs to be available under
given Folder Path,where all test run logs given Folder Path,where all test run logs
@ -135,18 +141,21 @@ class MarvinInit:
3. All logging like exception log,results, run info etc 3. All logging like exception log,results, run info etc
for a given test run are available under a given for a given test run are available under a given
timestamped folder timestamped folder
''' @Output : SUCCESS or FAILED
'''
try:
log_obj = MarvinLog("CSLog") log_obj = MarvinLog("CSLog")
if log_obj is None: if log_obj is None:
return FAILED return FAILED
else: else:
ret = log_obj.\ ret = log_obj.\
getLogs(self.__testModuleName, createLogs(self.__testModuleName,
self.__parsedConfig.logger) self.__parsedConfig.logger)
if ret != FAILED: if ret != FAILED:
self.__logFolderPath = log_obj.getLogFolderPath() self.__logFolderPath = log_obj.getLogFolderPath()
self.__tcRunLogger = log_obj.getLogger() self.__tcRunLogger = log_obj.getLogger()
return SUCCESS return SUCCESS
return FAILED
except Exception, e: except Exception, e:
print "\n Exception Occurred Under __initLogging " \ print "\n Exception Occurred Under __initLogging " \
":%s" % GetDetailExceptionInfo(e) ":%s" % GetDetailExceptionInfo(e)
@ -157,6 +166,7 @@ class MarvinInit:
@Name : __createTestClient @Name : __createTestClient
@Desc : Creates the TestClient during init @Desc : Creates the TestClient during init
based upon the parameters provided based upon the parameters provided
@Output: Returns SUCCESS or FAILED
''' '''
try: try:
mgt_details = self.__parsedConfig.mgtSvr[0] mgt_details = self.__parsedConfig.mgtSvr[0]
@ -176,7 +186,12 @@ class MarvinInit:
return FAILED return FAILED
def __loadNewApiFromXml(self): def __loadNewApiFromXml(self):
'''
@Desc: Kept for future usage
Will enhance later.
'''
try: try:
return SUCCESS
if self.__loadApiFlag: if self.__loadApiFlag:
apiLoadCfg = self.__parsedConfig.apiLoadCfg apiLoadCfg = self.__parsedConfig.apiLoadCfg
api_dst_dir = apiLoadCfg.ParsedApiDestFolder + "/cloudstackAPI" api_dst_dir = apiLoadCfg.ParsedApiDestFolder + "/cloudstackAPI"
@ -189,7 +204,7 @@ class MarvinInit:
print "Failed to create folder %s, " \ print "Failed to create folder %s, " \
"due to %s" % (api_dst_dir, "due to %s" % (api_dst_dir,
GetDetailExceptionInfo(e)) GetDetailExceptionInfo(e))
exit(1) return FAILED
mgt_details = self.__parsedConfig.mgtSvr[0] mgt_details = self.__parsedConfig.mgtSvr[0]
cg = CodeGenerator(api_dst_dir) cg = CodeGenerator(api_dst_dir)
if os.path.exists(api_spec_file): if os.path.exists(api_spec_file):
@ -206,6 +221,11 @@ class MarvinInit:
return FAILED return FAILED
def __setTestDataPath(self): def __setTestDataPath(self):
'''
@Name : __setTestDataPath
@Desc: Sets the TestData Path for tests to run
@Output: Returns SUCCESS or FAILED
'''
try: try:
if ((self.__parsedConfig.TestData is not None) and if ((self.__parsedConfig.TestData is not None) and
(self.__parsedConfig.TestData.Path is not None)): (self.__parsedConfig.TestData.Path is not None)):
@ -217,14 +237,23 @@ class MarvinInit:
return FAILED return FAILED
def __deployDC(self): def __deployDC(self):
'''
@Name : __deployDC
@Desc : Deploy the DataCenter and returns accordingly.
@Output : SUCCESS or FAILED
'''
try: try:
''' ret = SUCCESS
Deploy the DataCenter and retrieves test client. if self.__deployFlag:
''' deploy_obj = DeployDataCenters(self.__testClient,
deploy_obj = DeployDataCenters(self.__testClient,
self.__parsedConfig, self.__parsedConfig,
self.__tcRunLogger) self.__tcRunLogger)
return deploy_obj.deploy() if self.__deployFlag else FAILED ret = deploy_obj.deploy()
if ret == SUCCESS:
print "Deploy DC Successful"
else:
print "Deploy DC Failed"
return ret
except Exception, e: except Exception, e:
print "\n Exception Occurred Under __deployDC : %s" % \ print "\n Exception Occurred Under __deployDC : %s" % \
GetDetailExceptionInfo(e) GetDetailExceptionInfo(e)

View File

@ -68,6 +68,7 @@ class MarvinLog:
def __setLogHandler(self, log_file_path, log_format=None, def __setLogHandler(self, log_file_path, log_format=None,
log_level=logging.DEBUG): log_level=logging.DEBUG):
''' '''
@Name : __setLogHandler
@Desc: Adds the given Log handler to the current logger @Desc: Adds the given Log handler to the current logger
@Input: log_file_path: Log File Path as where to store the logs @Input: log_file_path: Log File Path as where to store the logs
log_format : Format of log messages to be dumped log_format : Format of log messages to be dumped
@ -100,7 +101,8 @@ class MarvinLog:
@Input: logfolder_to_remove: Path of Log to remove @Input: logfolder_to_remove: Path of Log to remove
''' '''
try: try:
os.rmdir(logfolder_to_remove) if os.path.isdir(logfolder_to_remove):
os.rmdir(logfolder_to_remove)
except Exception, e: except Exception, e:
print "\n Exception Occurred Under __cleanPreviousLogs :%s" % \ print "\n Exception Occurred Under __cleanPreviousLogs :%s" % \
GetDetailExceptionInfo(e) GetDetailExceptionInfo(e)
@ -131,21 +133,15 @@ class MarvinLog:
@Output : SUCCESS\FAILED @Output : SUCCESS\FAILED
''' '''
try: try:
if log_cfg is None: temp_ts = time.strftime("%b_%d_%Y_%H_%M_%S",
print "\nInvalid Log Folder Configuration." \
"Please Check Config File"
return FAILED
if test_module_name is None:
temp_path = time.strftime("%b_%d_%Y_%H_%M_%S",
time.localtime()) time.localtime())
if test_module_name is None:
temp_path = temp_ts
else: else:
temp_path = str(test_module_name.split(".py")[0]) temp_path = str(test_module_name) + "__" + str(temp_ts)
if (('LogFolderPath' in log_cfg.__dict__.keys()) and if ((log_cfg is not None) and ('LogFolderPath' in log_cfg.__dict__.keys()) and
(log_cfg.__dict__.get('LogFolderPath') is not None)): (log_cfg.__dict__.get('LogFolderPath') is not None)):
self.__cleanPreviousLogs(log_cfg.
__dict__.
get('LogFolderPath') + "/MarvinLogs")
temp_dir = \ temp_dir = \
log_cfg.__dict__.get('LogFolderPath') + "/MarvinLogs" log_cfg.__dict__.get('LogFolderPath') + "/MarvinLogs"
else: else:

View File

@ -14,7 +14,6 @@
# KIND, either express or implied. See the License for the # KIND, either express or implied. See the License for the
# specific language governing permissions and limitations # specific language governing permissions and limitations
# under the License. # under the License.
import marvin import marvin
import sys import sys
import logging import logging
@ -25,7 +24,7 @@ from nose.plugins.base import Plugin
from marvin.codes import (SUCCESS, from marvin.codes import (SUCCESS,
FAILED, FAILED,
EXCEPTION) EXCEPTION)
from marvin.cloudstackException import GetDetailExceptionInfo from marvin.cloudstackException import GetDetailExceptionInfo
import time import time
import os import os
@ -56,7 +55,7 @@ class MarvinPlugin(Plugin):
''' '''
Signifies the flag whether to deploy the New DC or Not Signifies the flag whether to deploy the New DC or Not
''' '''
self.__deployDcFlag self.__deployDcFlag = None
self.conf = None self.conf = None
self.debugStream = sys.stdout self.debugStream = sys.stdout
self.testRunner = None self.testRunner = None
@ -79,11 +78,26 @@ class MarvinPlugin(Plugin):
else: else:
self.enabled = True self.enabled = True
self.__configFile = options.config_file self.__configFile = options.configFile
self.__loadNewApiFlag = options.loadNewApiFlag self.__loadNewApiFlag = options.loadNewApiFlag
self.__deployDcFlag = options.deployDc self.__deployDcFlag = options.deployDc
self.__zoneForTests = options.zone self.__zoneForTests = options.zone
self.conf = conf self.conf = conf
test_mod_name = None
if self.startMarvin(test_mod_name) == FAILED:
print "\nExiting Marvin"
exit(1)
def getModName(self):
if len(self.conf.testNames) == 0:
dir_path = getattr(self.conf.options,'where')
if dir_path is not None:
temp = os.path.split(dir_path[0].strip())
return temp
else:
first_entry = self.conf.testNames[0]
temp = os.path.split(first_entry)
return os.path.splitext(temp)[0]
def options(self, parser, env): def options(self, parser, env):
""" """
@ -92,7 +106,7 @@ class MarvinPlugin(Plugin):
parser.add_option("--marvin-config", action="store", parser.add_option("--marvin-config", action="store",
default=env.get('MARVIN_CONFIG', default=env.get('MARVIN_CONFIG',
'./datacenter.cfg'), './datacenter.cfg'),
dest="config_file", dest="configFile",
help="Marvin's configuration file is required." help="Marvin's configuration file is required."
"The config file containing the datacenter and " "The config file containing the datacenter and "
"other management server " "other management server "
@ -102,7 +116,7 @@ class MarvinPlugin(Plugin):
dest="deployDc", dest="deployDc",
help="Deploys the DC with Given Configuration." help="Deploys the DC with Given Configuration."
"Requires only when DC needs to be deployed") "Requires only when DC needs to be deployed")
parser.add_option("--zone", action="zone_tests", parser.add_option("--zone", action="store_true",
default=None, default=None,
dest="zone", dest="zone",
help="Runs all tests against this specified zone") help="Runs all tests against this specified zone")
@ -111,13 +125,6 @@ class MarvinPlugin(Plugin):
dest="loadNewApiFlag", dest="loadNewApiFlag",
help="Loads the New Apis with Given Api Xml File." help="Loads the New Apis with Given Api Xml File."
"Creates the new Api's from commands.xml File") "Creates the new Api's from commands.xml File")
'''
Check if the configuration file is not valid,print and exit
'''
(options, args) = parser.parse_args()
if options.config_file is None:
parser.print_usage()
sys.exit(1)
Plugin.options(self, parser, env) Plugin.options(self, parser, env)
def wantClass(self, cls): def wantClass(self, cls):
@ -127,17 +134,10 @@ class MarvinPlugin(Plugin):
return True return True
return None return None
def prepareTest(self, test):
'''
@Desc : Initializes the marvin with required settings
'''
test_module_name = test.__str__()
if self.startMarvin(test_module_name) == FAILED:
print "Starting Marvin FAILED. Please Check Config and " \
"Arguments Supplied"
def __checkImport(self, filename): def __checkImport(self, filename):
''' '''
@Name : __checkImport
@Desc : Verifies to Import the test Module before running and check @Desc : Verifies to Import the test Module before running and check
whether if it is importable. whether if it is importable.
This will check for test modules which has some issues to be This will check for test modules which has some issues to be
@ -146,6 +146,7 @@ class MarvinPlugin(Plugin):
''' '''
try: try:
__import__(filename) __import__(filename)
print "\n*******************", filename
return True return True
except ImportError, e: except ImportError, e:
self.tcRunLogger.exception("Module : %s Import " self.tcRunLogger.exception("Module : %s Import "
@ -157,14 +158,13 @@ class MarvinPlugin(Plugin):
''' '''
@Desc : Only python files will be used as test modules @Desc : Only python files will be used as test modules
''' '''
if filename is None or filename == '': print "\n*******************", filename
return False if os.path.isfile(filename):
parts = filename.split(os.path.sep) if os.path.splitext(filename) != ".py":
base, ext = os.path.splitext(parts[-1]) return False
if ext != '.py': else:
return False return self.__checkImport(filename)
else: return False
return self.__checkImport(filename)
def loadTestsFromTestCase(self, cls): def loadTestsFromTestCase(self, cls):
if cls.__name__ != 'cloudstackTestCase': if cls.__name__ != 'cloudstackTestCase':
@ -192,34 +192,33 @@ class MarvinPlugin(Plugin):
''' '''
Adds Exception throwing test cases and information to log. Adds Exception throwing test cases and information to log.
''' '''
err_msg = GetDetailExceptionInfo(err)
self.tcRunLogger.fatal("%s: %s: %s" % self.tcRunLogger.fatal("%s: %s: %s" %
(EXCEPTION, self.testName, err_msg)) (EXCEPTION, self.testName, GetDetailExceptionInfo(err)))
self.testResult = EXCEPTION self.testResult = EXCEPTION
def handleFailure(self, test, err): def handleFailure(self, test, err):
''' '''
Adds Failing test cases and information to log. Adds Failing test cases and information to log.
''' '''
err_msg = GetDetailExceptionInfo(err)
self.tcRunLogger.fatal("%s: %s: %s" % self.tcRunLogger.fatal("%s: %s: %s" %
(FAILED, self.testName, err_msg)) (FAILED, self.testName, GetDetailExceptionInfo(err)))
self.testResult = FAILED self.testResult = FAILED
def startMarvin(self, test_module_name): def startMarvin(self, test_module_name):
''' '''
Initializes the Marvin @Name : startMarvin
creates the test Client @Desc : Initializes the Marvin
creates the runlogger for logging creates the test Client
Parses the config and creates a parsedconfig creates the runlogger for logging
Creates a debugstream for tc debug log Parses the config and creates a parsedconfig
Creates a debugstream for tc debug log
''' '''
try: try:
obj_marvininit = MarvinInit(self.__configFile, obj_marvininit = MarvinInit(self.__configFile,
self.__loadNewApiFlag, self.__loadNewApiFlag,
self.__deployDcFlag, self.__deployDcFlag,
test_module_name, test_module_name,
self.__zoneForoTests) self.__zoneForTests)
if obj_marvininit.init() == SUCCESS: if obj_marvininit.init() == SUCCESS:
self.testClient = obj_marvininit.getTestClient() self.testClient = obj_marvininit.getTestClient()
self.tcRunLogger = obj_marvininit.getLogger() self.tcRunLogger = obj_marvininit.getLogger()
@ -230,8 +229,10 @@ class MarvinPlugin(Plugin):
descriptions=True, descriptions=True,
verbosity=2, verbosity=2,
config=self.conf) config=self.conf)
print "\nMarvin Initialization Successful"
return SUCCESS return SUCCESS
else: else:
print "\nMarvin Initialization Failed"
return FAILED return FAILED
except Exception, e: except Exception, e:
print "Exception Occurred under startMarvin: %s" % \ print "Exception Occurred under startMarvin: %s" % \

View File

@ -25,7 +25,7 @@ from paramiko import (BadHostKeyException,
SFTPClient) SFTPClient)
import socket import socket
import time import time
from cloudstackException import ( from marvin.cloudstackException import (
internalError, internalError,
GetDetailExceptionInfo GetDetailExceptionInfo
) )