X-Git-Url: https://gerrit.opnfv.org/gerrit/gitweb?a=blobdiff_plain;f=yardstick%2Fcommon%2Futils.py;h=d2be8000ebf7333d637ebe166a22318d1e003e40;hb=8fe8ab2cc3b0814291cec3579aff267e042f4d6b;hp=3c5895f1e1c9cea089fc35367f974ad7febeb1cd;hpb=501175fbb095a771f5f1b9fb80dcf729192214d2;p=yardstick.git diff --git a/yardstick/common/utils.py b/yardstick/common/utils.py index 3c5895f1e..d2be8000e 100644 --- a/yardstick/common/utils.py +++ b/yardstick/common/utils.py @@ -26,6 +26,7 @@ import sys from functools import reduce import yaml +from six.moves import configparser from oslo_utils import importutils from oslo_serialization import jsonutils @@ -133,7 +134,9 @@ def source_env(env_file): def read_json_from_file(path): with open(path, 'r') as f: - return jsonutils.load(f) + j = f.read() + # don't use jsonutils.load() it conflicts with already decoded input + return jsonutils.loads(j) def write_json_to_file(path, data, mode='w'): @@ -144,3 +147,19 @@ def write_json_to_file(path, data, mode='w'): def write_file(path, data, mode='w'): with open(path, mode) as f: f.write(data) + + +def parse_ini_file(path): + parser = configparser.ConfigParser() + parser.read(path) + + try: + default = {k: v for k, v in parser.items('DEFAULT')} + except configparser.NoSectionError: + default = {} + + config = dict(DEFAULT=default, + **{s: {k: v for k, v in parser.items( + s)} for s in parser.sections()}) + + return config