aboutsummaryrefslogtreecommitdiffstats
path: root/yardstick
diff options
context:
space:
mode:
authorRoss Brattain <ross.b.brattain@intel.com>2017-10-03 17:56:25 +0000
committerGerrit Code Review <gerrit@opnfv.org>2017-10-03 17:56:25 +0000
commitdd57115618caa299f6dd1eb350b55ecf062ca92e (patch)
tree69294b88cbae3f7cd8e9b5ac1c9120196a8b1329 /yardstick
parente8cf6a76c346806b53fa0c802374327ddc4956d1 (diff)
parent3de95504a9a329cefcdec2ea9508709118bbf94e (diff)
Merge "Ensure that at least one handler is available"
Diffstat (limited to 'yardstick')
-rw-r--r--yardstick/__init__.py16
-rw-r--r--yardstick/common/constants.py21
-rw-r--r--yardstick/common/utils.py14
3 files changed, 33 insertions, 18 deletions
diff --git a/yardstick/__init__.py b/yardstick/__init__.py
index b673e7c4a..f95b0a906 100644
--- a/yardstick/__init__.py
+++ b/yardstick/__init__.py
@@ -10,11 +10,22 @@
from __future__ import absolute_import
import logging
import os
+import errno
+# this module must only import other modules that do
+# not require loggers to be created, so this cannot
+# include yardstick.common.utils
from yardstick.common import constants
-from yardstick.common import utils as yardstick_utils
-yardstick_utils.makedirs(constants.LOG_DIR)
+try:
+ # do not use yardstick.common.utils.makedirs
+ # since yardstick.common.utils creates a logger
+ # and so it cannot be imported before this code
+ os.makedirs(constants.LOG_DIR)
+except OSError as e:
+ if e.errno != errno.EEXIST:
+ raise
+
LOG_FILE = os.path.join(constants.LOG_DIR, 'yardstick.log')
LOG_FORMATTER = '%(asctime)s [%(levelname)s] %(name)s %(filename)s:%(lineno)d %(message)s'
@@ -34,6 +45,7 @@ def _init_logging():
_LOG_STREAM_HDLR.setLevel(logging.DEBUG)
else:
_LOG_STREAM_HDLR.setLevel(logging.INFO)
+
# don't append to log file, clobber
_LOG_FILE_HDLR.setFormatter(_LOG_FORMATTER)
_LOG_FILE_HDLR.setLevel(logging.DEBUG)
diff --git a/yardstick/common/constants.py b/yardstick/common/constants.py
index b416f42b9..32ed746df 100644
--- a/yardstick/common/constants.py
+++ b/yardstick/common/constants.py
@@ -8,11 +8,16 @@
##############################################################################
from __future__ import absolute_import
import os
+import errno
+
from functools import reduce
import pkg_resources
-from yardstick.common.utils import parse_yaml
+# this module must only import other modules that do
+# not require loggers to be created, so this cannot
+# include yardstick.common.utils
+from yardstick.common.yaml_loader import yaml_load
dirname = os.path.dirname
abspath = os.path.abspath
@@ -29,7 +34,19 @@ def get_param(key, default=''):
# don't re-parse yaml for each lookup
if not CONF:
- CONF.update(parse_yaml(conf_file))
+ # do not use yardstick.common.utils.parse_yaml
+ # since yardstick.common.utils creates a logger
+ # and so it cannot be imported before this code
+ try:
+ with open(conf_file) as f:
+ value = yaml_load(f)
+ except IOError:
+ pass
+ except OSError as e:
+ if e.errno != errno.EEXIST:
+ raise
+ else:
+ CONF.update(value)
try:
return reduce(lambda a, b: a[b], key.split('.'), CONF)
except KeyError:
diff --git a/yardstick/common/utils.py b/yardstick/common/utils.py
index 68c9ed63f..6ac99a5a9 100644
--- a/yardstick/common/utils.py
+++ b/yardstick/common/utils.py
@@ -37,7 +37,6 @@ from oslo_utils import importutils
from oslo_serialization import jsonutils
import yardstick
-from yardstick.common.yaml_loader import yaml_load
logger = logging.getLogger(__name__)
logger.setLevel(logging.DEBUG)
@@ -94,19 +93,6 @@ def import_modules_from_package(package):
logger.exception("unable to import %s", module_name)
-def parse_yaml(file_path):
- try:
- with open(file_path) as f:
- value = yaml_load(f)
- except IOError:
- return {}
- except OSError as e:
- if e.errno != errno.EEXIST:
- raise
- else:
- return value
-
-
def makedirs(d):
try:
os.makedirs(d)