Integrate vsperf in Tgen mode
[yardstick.git] / yardstick / benchmark / scenarios / networking / pktgen_dpdk.py
index 503ea97..ce8a7f4 100644 (file)
@@ -6,13 +6,16 @@
 # which accompanies this distribution, and is available at
 # http://www.apache.org/licenses/LICENSE-2.0
 ##############################################################################
+from __future__ import absolute_import
 import pkg_resources
 import logging
 import time
 
 import yardstick.ssh as ssh
+import yardstick.common.utils as utils
 from yardstick.benchmark.scenarios import base
 
+
 LOG = logging.getLogger(__name__)
 
 
@@ -36,7 +39,7 @@ class PktgenDPDKLatency(base.Scenario):
         self.setup_done = False
 
     def setup(self):
-        '''scenario setup'''
+        """scenario setup"""
         self.pktgen_dpdk_script = pkg_resources.resource_filename(
             'yardstick.benchmark.scenarios.networking',
             PktgenDPDKLatency.PKTGEN_DPDK_SCRIPT)
@@ -44,28 +47,16 @@ class PktgenDPDKLatency(base.Scenario):
             'yardstick.benchmark.scenarios.networking',
             PktgenDPDKLatency.TESTPMD_SCRIPT)
         host = self.context_cfg['host']
-        host_user = host.get('user', 'ubuntu')
-        host_ssh_port = host.get('ssh_port', ssh.DEFAULT_PORT)
-        host_ip = host.get('ip', None)
-        host_key_filename = host.get('key_filename', '~/.ssh/id_rsa')
         target = self.context_cfg['target']
-        target_user = target.get('user', 'ubuntu')
-        target_ssh_port = target.get('ssh_port', ssh.DEFAULT_PORT)
-        target_ip = target.get('ip', None)
-        target_key_filename = target.get('key_filename', '~/.ssh/id_rsa')
-        LOG.info("user:%s, target:%s", target_user, target_ip)
-        self.server = ssh.SSH(target_user, target_ip,
-                              key_filename=target_key_filename,
-                              port=target_ssh_port)
+        LOG.info("user:%s, target:%s", target['user'], target['ip'])
+        self.server = ssh.SSH.from_node(target, defaults={"user": "ubuntu"})
         self.server.wait(timeout=600)
 
         # copy script to host
         self.server._put_file_shell(self.testpmd_script, '~/testpmd_fwd.sh')
 
-        LOG.info("user:%s, host:%s", host_user, host_ip)
-        self.client = ssh.SSH(host_user, host_ip,
-                              key_filename=host_key_filename,
-                              port=host_ssh_port)
+        LOG.info("user:%s, host:%s", host['user'], host['ip'])
+        self.client = ssh.SSH.from_node(host, defaults={"user": "ubuntu"})
         self.client.wait(timeout=600)
 
         # copy script to host
@@ -76,29 +67,6 @@ class PktgenDPDKLatency(base.Scenario):
         self.testpmd_args = ''
         self.pktgen_args = []
 
-    @staticmethod
-    def get_port_mac(sshclient, port):
-        cmd = "ifconfig |grep HWaddr |grep %s |awk '{print $5}' " % port
-        LOG.debug("Executing command: %s", cmd)
-        status, stdout, stderr = sshclient.execute(cmd)
-
-        if status:
-            raise RuntimeError(stderr)
-        else:
-            return stdout.rstrip()
-
-    @staticmethod
-    def get_port_ip(sshclient, port):
-        cmd = "ifconfig %s |grep 'inet addr' |awk '{print $2}' \
-            |cut -d ':' -f2 " % port
-        LOG.debug("Executing command: %s", cmd)
-        status, stdout, stderr = sshclient.execute(cmd)
-
-        if status:
-            raise RuntimeError(stderr)
-        else:
-            return stdout.rstrip()
-
     def run(self, result):
         """execute the benchmark"""
 
@@ -106,13 +74,13 @@ class PktgenDPDKLatency(base.Scenario):
             self.setup()
 
         if not self.testpmd_args:
-            self.testpmd_args = self.get_port_mac(self.client, 'eth2')
+            self.testpmd_args = utils.get_port_mac(self.client, 'eth2')
 
         if not self.pktgen_args:
-            server_rev_mac = self.get_port_mac(self.server, 'eth1')
-            server_send_mac = self.get_port_mac(self.server, 'eth2')
-            client_src_ip = self.get_port_ip(self.client, 'eth1')
-            client_dst_ip = self.get_port_ip(self.client, 'eth2')
+            server_rev_mac = utils.get_port_mac(self.server, 'eth1')
+            server_send_mac = utils.get_port_mac(self.server, 'eth2')
+            client_src_ip = utils.get_port_ip(self.client, 'eth1')
+            client_dst_ip = utils.get_port_ip(self.client, 'eth2')
 
             self.pktgen_args = [client_src_ip, client_dst_ip,
                                 server_rev_mac, server_send_mac]
@@ -136,10 +104,12 @@ class PktgenDPDKLatency(base.Scenario):
         # wait for finishing test
         time.sleep(1)
 
-        cmd = "cat ~/result.log -vT \
-               |awk '{match($0,/\[8;40H +[0-9]+/)} \
-               {print substr($0,RSTART,RLENGTH)}' \
-               |grep -v ^$ |awk '{if ($2 != 0) print $2}'"
+        cmd = r"""\
+cat ~/result.log -vT \
+|awk '{match($0,/\[8;40H +[0-9]+/)} \
+{print substr($0,RSTART,RLENGTH)}' \
+|grep -v ^$ |awk '{if ($2 != 0) print $2}'\
+"""
         client_status, client_stdout, client_stderr = self.client.execute(cmd)
 
         if client_status: