Add support for multiple VMs 41/15041/11
authorJingLu5 <lvjing5@huawei.com>
Fri, 1 Jul 2016 03:05:51 +0000 (11:05 +0800)
committerJingLu5 <lvjing5@huawei.com>
Mon, 4 Jul 2016 07:07:38 +0000 (15:07 +0800)
Verify and add support for multiple target VMs.
This is related to further work with SDNVPN project.

In the task configration file, use 'target' for specifying one target VM and use 'targets' for specifying multiple target VMs.

Change-Id: I682188ef4c2c2c012d5ab00417b69f5b31b87137
Signed-off-by: JingLu5 <lvjing5@huawei.com>
samples/ping-multiple-vm.yaml [new file with mode: 0644]
tests/unit/benchmark/scenarios/networking/test_ping.py
yardstick/benchmark/scenarios/networking/ping.py
yardstick/cmd/commands/task.py

diff --git a/samples/ping-multiple-vm.yaml b/samples/ping-multiple-vm.yaml
new file mode 100644 (file)
index 0000000..4055af1
--- /dev/null
@@ -0,0 +1,42 @@
+---
+# Sample benchmark task config file measure network latency using ping
+# between mutiple virtual machines
+
+
+schema: "yardstick:task:0.1"
+
+scenarios:
+-
+  type: Ping
+  options:
+    packetsize: 200
+  host: athena.demo
+  # key 'targets' for multiple targets
+  targets:
+  - ares.demo
+  - kratos.demo
+
+  runner:
+    type: Duration
+    duration: 60
+    interval: 1
+
+  sla:
+    max_rtt: 10
+    action: monitor
+
+context:
+  name: demo
+  image: cirros-0.3.3
+  flavor: m1.tiny
+  user: cirros
+
+  servers:
+    athena:
+      floating_ip: true
+    ares:
+    kratos:
+
+  networks:
+    test:
+      cidr: '10.0.1.0/24'
index 3a897d0..6009745 100644 (file)
@@ -43,7 +43,7 @@ class PingTestCase(unittest.TestCase):
 
         mock_ssh.SSH().execute.return_value = (0, '100', '')
         p.run(result)
-        self.assertEqual(result, {'rtt': 100.0})
+        self.assertEqual(result, {'rtt': {'10.229.17.105': 100.0}})
 
     @mock.patch('yardstick.benchmark.scenarios.networking.ping.ssh')
     def test_ping_successful_sla(self, mock_ssh):
@@ -58,7 +58,7 @@ class PingTestCase(unittest.TestCase):
 
         mock_ssh.SSH().execute.return_value = (0, '100', '')
         p.run(result)
-        self.assertEqual(result, {'rtt': 100.0})
+        self.assertEqual(result, {'rtt': {'10.229.17.105': 100.0}})
 
     @mock.patch('yardstick.benchmark.scenarios.networking.ping.ssh')
     def test_ping_unsuccessful_sla(self, mock_ssh):
index ae21666..3af3548 100644 (file)
@@ -57,29 +57,32 @@ class Ping(base.Scenario):
         else:
             options = ""
 
-        destination = self.context_cfg['target'].get("ipaddr", '127.0.0.1')
+        destination = self.context_cfg['target'].get('ipaddr', '127.0.0.1')
+        dest_list = [s.strip() for s in destination.split(',')]
 
-        LOG.debug("ping '%s' '%s'", options, destination)
+        result["rtt"] = {}
+        rtt_result = result["rtt"]
 
-        exit_status, stdout, stderr = self.connection.execute(
-            "/bin/sh -s {0} {1}".format(destination, options),
-            stdin=open(self.target_script, "r"))
+        for dest in dest_list:
+            LOG.debug("ping '%s' '%s'", options, dest)
+            exit_status, stdout, stderr = self.connection.execute(
+                "/bin/sh -s {0} {1}".format(dest, options),
+                stdin=open(self.target_script, "r"))
 
-        if exit_status != 0:
-            raise RuntimeError(stderr)
+            if exit_status != 0:
+                raise RuntimeError(stderr)
 
-        if stdout:
-            result["rtt"] = float(stdout)
-
-            if "sla" in self.scenario_cfg:
-                sla_max_rtt = int(self.scenario_cfg["sla"]["max_rtt"])
-                assert result["rtt"] <= sla_max_rtt, \
-                    "rtt %f > sla:max_rtt(%f); " % (result["rtt"], sla_max_rtt)
-        else:
-            LOG.error("ping '%s' '%s' timeout", options, destination)
+            if stdout:
+                rtt_result[dest] = float(stdout)
+                if "sla" in self.scenario_cfg:
+                    sla_max_rtt = int(self.scenario_cfg["sla"]["max_rtt"])
+                    assert rtt_result[dest] <= sla_max_rtt, "rtt %f > sla:\
+                    max_rtt(%f); " % (rtt_result[dest], sla_max_rtt)
+            else:
+                LOG.error("ping '%s' '%s' timeout", options, dest)
 
 
-def _test():
+def _test():    # pragma: no cover
     '''internal test function'''
     key_filename = pkg_resources.resource_filename("yardstick.resources",
                                                    "files/yardstick_key")
@@ -104,5 +107,5 @@ def _test():
     p.run(result)
     print result
 
-if __name__ == '__main__':
+if __name__ == '__main__':    # pragma: no cover
     _test()
index 55898e1..2bc5abe 100644 (file)
@@ -374,6 +374,20 @@ def run_one_scenario(scenario_cfg, output_file):
                 context_cfg["target"]["ipaddr"] = \
                     context_cfg["target"]["ip"]
 
+    if "targets" in scenario_cfg:
+        ip_list = []
+        for target in scenario_cfg["targets"]:
+            if is_ip_addr(target):
+                ip_list.append(target)
+                context_cfg['target'] = {}
+            else:
+                context_cfg['target'] = Context.get_server(target)
+                if _is_same_heat_context(scenario_cfg["host"], target):
+                    ip_list.append(context_cfg["target"]["private_ip"])
+                else:
+                    ip_list.append(context_cfg["target"]["ip"])
+        context_cfg['target']['ipaddr'] = ','.join(ip_list)
+
     if "nodes" in scenario_cfg:
         context_cfg["nodes"] = parse_nodes_with_context(scenario_cfg)
     runner = base_runner.Runner.get(runner_cfg)