from copy import deepcopy
from itertools import product, chain
+import errno
import mock
from six.moves import configparser
class TestUtils(unittest.TestCase):
+ @mock.patch('yardstick.common.utils.os.makedirs')
+ def test_makedirs(self, *_):
+ self.assertIsNone(utils.makedirs('a/b/c/d'))
+
+ @mock.patch('yardstick.common.utils.os.makedirs')
+ def test_makedirs_exists(self, mock_os_makedirs):
+ mock_os_makedirs.side_effect = OSError(errno.EEXIST, 'exists')
+ self.assertIsNone(utils.makedirs('a/b/c/d'))
+
+ @mock.patch('yardstick.common.utils.os.makedirs')
+ def test_makedirs_busy(self, mock_os_makedirs):
+ mock_os_makedirs.side_effect = OSError(errno.EBUSY, 'busy')
+ with self.assertRaises(OSError):
+ utils.makedirs('a/b/c/d')
+
@mock.patch('yardstick.common.utils.jsonify')
def test_result_handler(self, mock_jsonify):
mock_jsonify.return_value = 432
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'
_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)
##############################################################################
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
# 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:
from oslo_serialization import jsonutils
import yardstick
-from yardstick.common.yaml_loader import yaml_load
logger = logging.getLogger(__name__)
logger.setLevel(logging.DEBUG)
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)