Merge "Enable vnf/tg instantiate as blocking call."
[yardstick.git] / yardstick / network_services / traffic_profile / http_ixload.py
index 8a4f97f..3480565 100644 (file)
@@ -18,6 +18,7 @@ from __future__ import print_function
 import sys
 import os
 import logging
+import collections
 
 # ixload uses its own py2. So importing jsonutils fails. So adding below
 # workaround to support call from yardstick
@@ -26,8 +27,16 @@ try:
 except ImportError:
     import json as jsonutils
 
-from yardstick.common.utils import join_non_strings
-from yardstick.common.utils import ErrorClass
+
+class ErrorClass(object):
+
+    def __init__(self, *args, **kwargs):
+        if 'test' not in kwargs:
+            raise RuntimeError
+
+    def __getattr__(self, item):
+        raise AttributeError
+
 
 try:
     from IxLoad import IxLoad, StatCollectorUtils
@@ -80,11 +89,25 @@ Incoming stats: Time interval: %s
 """
 
 
+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 IXLOADHttpTest(object):
 
     def __init__(self, test_input):
-        self.test_input = jsonutils.loads(test_input)
-        self.parse_run_test()
         self.ix_load = None
         self.stat_utils = None
         self.remote_server = None
@@ -94,6 +117,8 @@ class IXLOADHttpTest(object):
         self.chassis = None
         self.card = None
         self.ports_to_reassign = None
+        self.test_input = jsonutils.loads(test_input)
+        self.parse_run_test()
 
     @staticmethod
     def format_ports_for_reassignment(ports):
@@ -291,4 +316,5 @@ def main(args):
         ixload_obj.start_http_test()
 
 if __name__ == '__main__':
+    LOG.info("Start http_ixload test")
     main(sys.argv)