Merge "Add "securityContext" parameter in Kubernetes context"
[yardstick.git] / yardstick / network_services / traffic_profile / http_ixload.py
index 8a4f97f..6cbdb8a 100644 (file)
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-from __future__ import absolute_import
-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,14 +24,14 @@ try:
 except ImportError:
     import json as jsonutils
 
-from yardstick.common.utils import join_non_strings
-from yardstick.common.utils import ErrorClass
+from yardstick.common import exceptions
 
 try:
     from IxLoad import IxLoad, StatCollectorUtils
 except ImportError:
-    IxLoad = ErrorClass
-    StatCollectorUtils = ErrorClass
+    IxLoad = exceptions.ErrorClass
+    StatCollectorUtils = exceptions.ErrorClass
+
 
 LOG = logging.getLogger(__name__)
 CSV_FILEPATH_NAME = 'IxL_statResults.csv'
@@ -80,11 +78,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  # pylint: disable=raising-bad-type
+    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 +106,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):
@@ -193,7 +207,7 @@ class IXLOADHttpTest(object):
         #  ---- Remap ports ----
         try:
             self.reassign_ports(test, repository, self.ports_to_reassign)
-        except Exception:
+        except Exception:  # pylint: disable=broad-except
             LOG.exception("Exception occurred during reassign_ports")
 
         # -----------------------------------------------------------------------
@@ -291,4 +305,5 @@ def main(args):
         ixload_obj.start_http_test()
 
 if __name__ == '__main__':
+    LOG.info("Start http_ixload test")
     main(sys.argv)