From 5038f9068c70bfe2ef5241c5d88fa14067287daf Mon Sep 17 00:00:00 2001 From: John O Loughlin Date: Fri, 18 Jan 2019 11:27:03 +0000 Subject: Fix exception handling ixload Ixload uses its own version of python By default it will fail to import yardstick.common exceptions. For this reason for this reason ixload exceptions should be kept in http_ixload.py JIRA: YARDSTICK-1587 Change-Id: I5673fb5b89bbcdf4d3c60c283231d44d770999ec Signed-off-by: John O Loughlin --- .../traffic_profile/http_ixload.py | 38 ++++++++++++---------- 1 file changed, 21 insertions(+), 17 deletions(-) (limited to 'yardstick/network_services') diff --git a/yardstick/network_services/traffic_profile/http_ixload.py b/yardstick/network_services/traffic_profile/http_ixload.py index b88aadff7..ec0762500 100644 --- a/yardstick/network_services/traffic_profile/http_ixload.py +++ b/yardstick/network_services/traffic_profile/http_ixload.py @@ -1,4 +1,4 @@ -# Copyright (c) 2016-2017 Intel Corporation +# Copyright (c) 2016-2019 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -16,14 +16,6 @@ import sys import os import logging import collections -import subprocess -try: - libs = subprocess.check_output( - 'python -c "import site; print(site.getsitepackages())"', shell=True) - - sys.path.extend(libs[1:-1].replace("'", "").split(',')) -except subprocess.CalledProcessError: - pass # ixload uses its own py2. So importing jsonutils fails. So adding below # workaround to support call from yardstick @@ -32,14 +24,26 @@ try: except ImportError: import json as jsonutils -from yardstick.common import exceptions #pylint: disable=wrong-import-position + +class ErrorClass(object): + + def __init__(self, *args, **kwargs): + if 'test' not in kwargs: + raise RuntimeError + + def __getattr__(self, item): + raise AttributeError + + +class InvalidRxfFile(Exception): + message = 'Loaded rxf file has unexpected format' + try: from IxLoad import IxLoad, StatCollectorUtils except ImportError: - IxLoad = exceptions.ErrorClass - StatCollectorUtils = exceptions.ErrorClass - + IxLoad = ErrorClass + StatCollectorUtils = ErrorClass LOG = logging.getLogger(__name__) CSV_FILEPATH_NAME = 'IxL_statResults.csv' @@ -205,7 +209,7 @@ class IXLOADHttpTest(object): ipAddress=address, gatewayAddress=gateway) except Exception: - raise exceptions.InvalidRxfFile + raise InvalidRxfFile def update_network_mac_address(self, net_traffic, mac): """Update MACaddress for net_traffic object @@ -233,7 +237,7 @@ class IXLOADHttpTest(object): "MacRange") mac_range.config(mac=mac) except Exception: - raise exceptions.InvalidRxfFile + raise InvalidRxfFile def update_network_param(self, net_traffic, param): """Update net_traffic by parameters specified in param""" @@ -301,7 +305,7 @@ class IXLOADHttpTest(object): ix_http_command = activity.agent.actionList[0] ix_http_command.config(pageObject=page_object) except Exception: - raise exceptions.InvalidRxfFile + raise InvalidRxfFile def update_user_count(self, net_traffic, user_count): """Update userObjectiveValue field in activity object in net_traffic @@ -318,7 +322,7 @@ class IXLOADHttpTest(object): activity = net_traffic.activityList[0] activity.config(userObjectiveValue=user_count) except Exception: - raise exceptions.InvalidRxfFile + raise InvalidRxfFile def start_http_test(self): self.ix_load = IxLoad() -- cgit 1.2.3-korg