Ping: Fix TypeError without SLA in timeout scenario 39/68039/1
authorDeepanshu Bhatia <deepanshu@voereir.com>
Mon, 13 May 2019 07:22:17 +0000 (12:52 +0530)
committerDeepanshu Bhatia <deepanshu@voereir.com>
Mon, 13 May 2019 07:22:17 +0000 (12:52 +0530)
In case of no SLA association with scenario, when the commands timeout,
stdout is empty and it gives TypeError.
Reverted the condition to the old one which was used before introduction
of verifySLA()

JIRA: YARDSTICK-1618

Change-Id: Ibd86ba7168f26ae5b15c21fd6129cc737a7038db
Signed-off-by: Deepanshu Bhatia <deepanshu@voereir.com>
yardstick/benchmark/scenarios/networking/ping.py
yardstick/tests/unit/benchmark/scenarios/networking/test_ping.py

index 6caeab5..1c95102 100644 (file)
@@ -103,12 +103,14 @@ class Ping(base.Scenario):
                 rtt_result[target_vm_name] = float(self.PING_ERROR_RTT)
                 # store result before potential AssertionError
                 result.update(utils.flatten_dict_key(ping_result))
-                self.verify_SLA(sla_max_rtt is None,
-                                "packet dropped rtt %f > sla: max_rtt(%f)"
-                                % (rtt_result[target_vm_name], sla_max_rtt))
-                self.verify_SLA(False,
-                                "packet dropped rtt %f"
-                                % (rtt_result[target_vm_name]))
+                if sla_max_rtt is not None:
+                    self.verify_SLA(rtt_result[target_vm_name] <= sla_max_rtt,
+                                    "packet dropped rtt %f > sla: max_rtt(%f)"
+                                    % (rtt_result[target_vm_name], sla_max_rtt))
+                else:
+                    self.verify_SLA(False,
+                                    "packet dropped rtt %f"
+                                    % (rtt_result[target_vm_name]))
 
 
 def _test():    # pragma: no cover
index 559e059..9442026 100644 (file)
@@ -91,3 +91,17 @@ class PingTestCase(unittest.TestCase):
 
         mock_ssh.SSH.from_node().execute.return_value = (1, '', 'FOOBAR')
         self.assertRaises(RuntimeError, p.run, result)
+
+    @mock.patch('yardstick.benchmark.scenarios.networking.ping.ssh')
+    def test_ping_unsuccessful_no_sla(self, mock_ssh):
+
+        args = {
+            'options': {'packetsize': 200},
+            'target': 'ares.demo'
+        }
+        result = {}
+
+        p = ping.Ping(args, self.ctx)
+
+        mock_ssh.SSH.from_node().execute.return_value = (0, '', '')
+        self.assertRaises(y_exc.SLAValidationError, p.run, result)