Add support for single server ping test 33/833/2
authorHans Feldt <hans.feldt@ericsson.com>
Tue, 16 Jun 2015 07:27:31 +0000 (09:27 +0200)
committerHans Feldt <hans.feldt@ericsson.com>
Tue, 16 Jun 2015 13:56:12 +0000 (13:56 +0000)
A simple test case is added that will ping an external server on
the internet. See samples/ping-ext-ip.yaml

Change-Id: I15eb3cb6ab9e5c1cf280f2aade2bf4c9646d6cd4
JIRA: -
Signed-off-by: Hans Feldt <hans.feldt@ericsson.com>
samples/ping-ext-ip.yaml [new file with mode: 0644]
samples/ping.yaml
setup.py
yardstick/benchmark/scenarios/networking/ping.py
yardstick/main.py

diff --git a/samples/ping-ext-ip.yaml b/samples/ping-ext-ip.yaml
new file mode 100644 (file)
index 0000000..82cd02c
--- /dev/null
@@ -0,0 +1,36 @@
+---
+# Sample benchmark task config file
+# Measure network latency using ping, destination is an external server
+# Make sure servers have internet access before running this test.
+# For example using virtual MOS do something this on the host:
+# sudo iptables -t nat -A POSTROUTING -s 172.16.0.0/24 \! -d 172.16.0.0/24 -j MASQUERADE
+#
+
+schema: "yardstick:task:0.1"
+
+scenarios:
+-
+  type: Ping
+  host: client.demo
+  target: 8.8.8.8
+  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:
+    client:
+      floating_ip: true
+  networks:
+    test:
+      cidr: '10.0.1.0/24'
+      external_network: "net04_ext"
+
index 9a06fc4..3bc1081 100644 (file)
@@ -26,7 +26,6 @@ context:
   image: cirros-0.3.3
   flavor: m1.tiny
   user: cirros
-  anti_affinity: true
 
   placement_groups:
     pgrp1:
index ff415ae..742192c 100644 (file)
--- a/setup.py
+++ b/setup.py
@@ -10,7 +10,8 @@ setup(
     include_package_data=True,
     package_data={'yardstick': ['benchmark/scenarios/networking/*.bash']},
     url="https://www.opnfv.org",
-    install_requires=["flake8",
+    install_requires=["backport_ipaddress",  # remove with python3
+                      "flake8",
                       "PyYAML>=3.10",
                       "pbr!=0.7,<1.0,>=0.6",
                       "python-glanceclient>=0.12.0",
@@ -18,14 +19,14 @@ setup(
                       "python-keystoneclient>=0.11.1",
                       "python-neutronclient>=2.3.9",
                       "python-novaclient>=2.24.1",
-                      "mock>=1.0.1",
+                      "mock>=1.0.1",  # remove with python3
                       "paramiko",
                       "six"
                       ],
-    entry_points = {
+    entry_points={
         'console_scripts': [
             'yardstick=yardstick.main:main',
         ],
     },
-    scripts =['tools/yardstick-img-modify']
+    scripts=['tools/yardstick-img-modify']
 )
index a027c81..1b87c74 100644 (file)
@@ -40,13 +40,17 @@ class Ping(base.Scenario):
     def run(self, args):
         """execute the benchmark"""
 
-        self.options = "-s %s" % args['options'].get("packetsize", '56')
-        self.ipaddr = args.get("ipaddr", '127.0.0.1')
+        if "options" in args:
+            options = "-s %s" % args['options'].get("packetsize", '56')
+        else:
+            options = ""
 
-        LOG.debug("ping %s %s", self.options, self.ipaddr)
+        destination = args.get("ipaddr", '127.0.0.1')
+
+        LOG.debug("ping '%s' '%s'", options, destination)
 
         exit_status, stdout, stderr = self.connection.execute(
-            "/bin/sh -s {0} {1}".format(self.ipaddr, self.options),
+            "/bin/sh -s {0} {1}".format(options, destination),
             stdin=open(self.target_script, "r"))
 
         if exit_status != 0:
@@ -56,6 +60,7 @@ class Ping(base.Scenario):
 
         if "sla" in args:
             sla_max_rtt = int(args["sla"]["max_rtt"])
-            assert rtt <= sla_max_rtt, "rtt %f > sla_max_rtt" % rtt
+            assert rtt <= sla_max_rtt, "rtt %f > sla:max_rtt(%f)" % \
+                (rtt, sla_max_rtt)
 
         return rtt
index 942b46b..8f01743 100755 (executable)
@@ -43,6 +43,7 @@ import sys
 import yaml
 import atexit
 import pkg_resources
+import ipaddress
 
 from yardstick.benchmark.context.model import Context
 from yardstick.benchmark.runners import base as base_runner
@@ -93,6 +94,15 @@ def atexit_handler():
             context.undeploy()
 
 
+def is_ip_addr(addr):
+    '''check if string addr is an IP address'''
+    try:
+        ipaddress.ip_address(addr)
+        return True
+    except ValueError:
+        return False
+
+
 def run_one_scenario(scenario_cfg, output_file):
     '''run one scenario using context'''
     key_filename = pkg_resources.resource_filename(
@@ -107,19 +117,22 @@ def run_one_scenario(scenario_cfg, output_file):
     runner_cfg['output_filename'] = output_file
 
     if "target" in scenario_cfg:
-        target = Context.get_server(scenario_cfg["target"])
-
-        # get public IP for target server, some scenarios require it
-        if target.public_ip:
-            runner_cfg['target'] = target.public_ip
-
-        # TODO scenario_cfg["ipaddr"] is bad naming
-        if host.context != target.context:
-            # target is in another context, get its public IP
-            scenario_cfg["ipaddr"] = target.public_ip
+        if is_ip_addr(scenario_cfg["target"]):
+            scenario_cfg["ipaddr"] = scenario_cfg["target"]
         else:
-            # target is in the same context, get its private IP
-            scenario_cfg["ipaddr"] = target.private_ip
+            target = Context.get_server(scenario_cfg["target"])
+
+            # get public IP for target server, some scenarios require it
+            if target.public_ip:
+                runner_cfg['target'] = target.public_ip
+
+            # TODO scenario_cfg["ipaddr"] is bad naming
+            if host.context != target.context:
+                # target is in another context, get its public IP
+                scenario_cfg["ipaddr"] = target.public_ip
+            else:
+                # target is in the same context, get its private IP
+                scenario_cfg["ipaddr"] = target.private_ip
 
     runner = base_runner.Runner.get(runner_cfg)