From a9d96aff066f42ee981b2cdbd5dea0cae625b4b7 Mon Sep 17 00:00:00 2001 From: SrikanteswaraRao Talluri Date: Wed, 11 Dec 2013 01:52:34 +0530 Subject: [PATCH] CLOUDSTACK-5449: fix the log creation failure case and added an option for user to provide --log-folder-path= Signed-off-by: SrikanteswaraRao Talluri --- tools/marvin/marvin/marvinInit.py | 22 +++++++++++++++------- tools/marvin/marvin/marvinPlugin.py | 6 +++++- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/tools/marvin/marvin/marvinInit.py b/tools/marvin/marvin/marvinInit.py index 17ee9bd7481..2bbf11903a0 100644 --- a/tools/marvin/marvin/marvinInit.py +++ b/tools/marvin/marvin/marvinInit.py @@ -39,14 +39,16 @@ import sys import time import os import logging +import string +import random class MarvinInit: - def __init__(self, config_file, load_flag): + def __init__(self, config_file, load_flag, log_folder_path=None): self.__configFile = config_file self.__loadFlag = load_flag self.__parsedConfig = None - self.__logFolderPath = None + self.__logFolderPath = log_folder_path self.__tcRunLogger = None self.__testClient = None self.__tcRunDebugFile = None @@ -111,15 +113,21 @@ class MarvinInit: for a given test run are available under a given timestamped folder ''' - log_config = self.__parsedConfig.logger temp_path = "".join(str(time.time()).split(".")) - if log_config is not None: - if log_config.LogFolderPath is not None: - self.logFolderPath = log_config.LogFolderPath + temp_path + if self.__logFolderPath is None: + log_config = self.__parsedConfig.logger + if log_config is not None: + if log_config.LogFolderPath is not None: + self.logFolderPath = log_config.LogFolderPath + '/' + temp_path + else: + self.logFolderPath = temp_path else: self.logFolderPath = temp_path else: - self.logFolderPath = temp_path + self.logFolderPath = self.__logFolderPath + '/' + temp_path + if os.path.exists(self.logFolderPath): + self.logFolderPath = self.logFolderPath \ + + ''.join(random.choice(string.ascii_uppercase + string.digits) for x in range(3)) os.makedirs(self.logFolderPath) ''' Log File Paths diff --git a/tools/marvin/marvin/marvinPlugin.py b/tools/marvin/marvin/marvinPlugin.py index 540ede96d63..1353352bbcc 100644 --- a/tools/marvin/marvin/marvinPlugin.py +++ b/tools/marvin/marvin/marvinPlugin.py @@ -68,6 +68,7 @@ class MarvinPlugin(Plugin): self.enabled = True self.configFile = options.config_file self.loadFlag = options.load + self.logFolderPath = options.log_folder_path self.conf = conf ''' Initializes the marvin with required settings @@ -87,6 +88,9 @@ class MarvinPlugin(Plugin): parser.add_option("--load", action="store_true", default=False, dest="load", help="Only load the deployment configuration given") + parser.add_option("--log-folder-path", action="store", default=None, + dest="log_folder_path", + help="Path to the folder where log files will be stored") Plugin.options(self, parser, env) def wantClass(self, cls): @@ -165,7 +169,7 @@ class MarvinPlugin(Plugin): Creates a debugstream for tc debug log ''' try: - obj_marvininit = MarvinInit(self.configFile, self.loadFlag) + obj_marvininit = MarvinInit(self.configFile, self.loadFlag, self.logFolderPath) if obj_marvininit.init() == SUCCESS: self.testClient = obj_marvininit.getTestClient() self.tcRunLogger = obj_marvininit.getLogger()