Sample CGNAPT VNF
[yardstick.git] / yardstick / common / utils.py
index 1059e1c..729bc1d 100644 (file)
@@ -27,7 +27,6 @@ import collections
 import socket
 import random
 import ipaddress
-from functools import reduce
 from contextlib import closing
 
 import yaml
@@ -107,19 +106,6 @@ def parse_yaml(file_path):
         return value
 
 
-def get_param(key, default=''):
-
-    conf_file = os.environ.get('CONF_FILE', '/etc/yardstick/yardstick.yaml')
-
-    conf = parse_yaml(conf_file)
-    try:
-        return reduce(lambda a, b: a[b], key.split('.'), conf)
-    except KeyError:
-        if not default:
-            raise
-        return default
-
-
 def makedirs(d):
     try:
         os.makedirs(d)
@@ -370,3 +356,29 @@ def parse_cpuinfo(cpuinfo):
 def config_to_dict(config):
     return {section: dict(config.items(section)) for section in
             config.sections()}
+
+
+def validate_non_string_sequence(value, default=None, raise_exc=None):
+    if isinstance(value, collections.Sequence) and not isinstance(value, str):
+        return value
+    if raise_exc:
+        raise raise_exc
+    return default
+
+
+def join_non_strings(separator, *non_strings):
+    try:
+        non_strings = validate_non_string_sequence(non_strings[0], raise_exc=RuntimeError)
+    except (IndexError, RuntimeError):
+        pass
+    return str(separator).join(str(non_string) for non_string in non_strings)
+
+
+class ErrorClass(object):
+
+    def __init__(self, *args, **kwargs):
+        if 'test' not in kwargs:
+            raise RuntimeError
+
+    def __getattr__(self, item):
+        raise AttributeError