Create a SampleVNF MQ consumer class
[yardstick.git] / yardstick / network_services / vnf_generic / vnf / tg_ixload.py
index 612799f..e0fc47d 100644 (file)
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-from __future__ import absolute_import
+import collections
 import csv
 import glob
 import logging
 import os
 import shutil
+import subprocess
 
-from collections import OrderedDict
-from subprocess import call
-
-from yardstick.common.utils import makedirs
+from yardstick.common import utils
 from yardstick.network_services.vnf_generic.vnf.sample_vnf import SampleVNFTrafficGen
 from yardstick.network_services.vnf_generic.vnf.sample_vnf import ClientResourceHelper
-from yardstick.benchmark.scenarios.networking.vnf_generic import find_relative_file
+
 
 LOG = logging.getLogger(__name__)
 
@@ -65,7 +63,7 @@ class IxLoadResourceHelper(ClientResourceHelper):
 
     RESULTS_MOUNT = "/mnt/Results"
 
-    KPI_LIST = OrderedDict((
+    KPI_LIST = collections.OrderedDict((
         ('http_throughput', 'HTTP Total Throughput (Kbps)'),
         ('simulated_users', 'HTTP Simulated Users'),
         ('concurrent_connections', 'HTTP Concurrent Connections'),
@@ -75,7 +73,8 @@ class IxLoadResourceHelper(ClientResourceHelper):
 
     def __init__(self, setup_helper):
         super(IxLoadResourceHelper, self).__init__(setup_helper)
-        self.result = OrderedDict((key, ResourceDataHelper()) for key in self.KPI_LIST)
+        self.result = collections.OrderedDict((key, ResourceDataHelper())
+                                              for key in self.KPI_LIST)
         self.resource_file_name = ''
         self.data = None
 
@@ -91,19 +90,20 @@ class IxLoadResourceHelper(ClientResourceHelper):
                     self.result[key].append(value)
 
     def setup(self):
-        # TODO: fixupt scenario_helper to hanlde ixia
+        # NOTE: fixup scenario_helper to hanlde ixia
         self.resource_file_name = \
-            find_relative_file(self.scenario_helper.scenario_cfg['ixia_profile'],
-                               self.scenario_helper.scenario_cfg["task_path"])
-        makedirs(self.RESULTS_MOUNT)
+            utils.find_relative_file(
+                self.scenario_helper.scenario_cfg['ixia_profile'],
+                self.scenario_helper.scenario_cfg["task_path"])
+        utils.makedirs(self.RESULTS_MOUNT)
         cmd = MOUNT_CMD.format(self.vnfd_helper.mgmt_interface, self)
         LOG.debug(cmd)
 
         if not os.path.ismount(self.RESULTS_MOUNT):
-            call(cmd, shell=True)
+            subprocess.call(cmd, shell=True)
 
         shutil.rmtree(self.RESULTS_MOUNT, ignore_errors=True)
-        makedirs(self.RESULTS_MOUNT)
+        utils.makedirs(self.RESULTS_MOUNT)
         shutil.copy(self.resource_file_name, self.RESULTS_MOUNT)
 
     def make_aggregates(self):
@@ -113,7 +113,7 @@ class IxLoadResourceHelper(ClientResourceHelper):
     def collect_kpi(self):
         if self.data:
             self._result.update(self.data)
-        LOG.info("Collect {0} KPIs {1}".format(self.RESOURCE_WORD, self._result))
+        LOG.info("Collect %s KPIs %s", self.RESOURCE_WORD, self._result)
         return self._result
 
     def log(self):
@@ -123,12 +123,13 @@ class IxLoadResourceHelper(ClientResourceHelper):
 
 class IxLoadTrafficGen(SampleVNFTrafficGen):
 
-    def __init__(self, name, vnfd, setup_env_helper_type=None, resource_helper_type=None):
+    def __init__(self, name, vnfd, task_id, setup_env_helper_type=None,
+                 resource_helper_type=None):
         if resource_helper_type is None:
             resource_helper_type = IxLoadResourceHelper
 
-        super(IxLoadTrafficGen, self).__init__(name, vnfd, setup_env_helper_type,
-                                               resource_helper_type)
+        super(IxLoadTrafficGen, self).__init__(
+            name, vnfd, task_id, setup_env_helper_type, resource_helper_type)
         self._result = {}
 
     def run_traffic(self, traffic_profile):
@@ -156,7 +157,7 @@ class IxLoadTrafficGen(SampleVNFTrafficGen):
             args="'%s'" % ixload_config)
 
         LOG.debug(cmd)
-        call(cmd, shell=True)
+        subprocess.call(cmd, shell=True)
 
         with open(self.ssh_helper.join_bin_path("ixLoad_HTTP_Client.csv")) as csv_file:
             lines = csv_file.readlines()[10:]
@@ -170,16 +171,6 @@ class IxLoadTrafficGen(SampleVNFTrafficGen):
         self.resource_helper.log()
         self.resource_helper.data = self.resource_helper.make_aggregates()
 
-    def listen_traffic(self, traffic_profile):
-        pass
-
-    def instantiate(self, scenario_cfg, context_cfg):
-        super(IxLoadTrafficGen, self).instantiate(scenario_cfg, context_cfg)
-
-    def wait_for_instantiate(self):
-        # not needed for Ixload
-        pass
-
     def terminate(self):
-        call(["pkill", "-9", "http_ixload.py"])
+        subprocess.call(["pkill", "-9", "http_ixload.py"])
         super(IxLoadTrafficGen, self).terminate()