From 4a28136293a210b9da725c7dc0a5f0eca37370ee Mon Sep 17 00:00:00 2001 From: Deepanshu Bhatia Date: Mon, 13 May 2019 12:52:17 +0530 Subject: Ping: Fix TypeError without SLA in timeout scenario 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 --- yardstick/benchmark/scenarios/networking/ping.py | 14 ++++++++------ .../tests/unit/benchmark/scenarios/networking/test_ping.py | 14 ++++++++++++++ 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/yardstick/benchmark/scenarios/networking/ping.py b/yardstick/benchmark/scenarios/networking/ping.py index 6caeab5ef..1c9510220 100644 --- a/yardstick/benchmark/scenarios/networking/ping.py +++ b/yardstick/benchmark/scenarios/networking/ping.py @@ -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 diff --git a/yardstick/tests/unit/benchmark/scenarios/networking/test_ping.py b/yardstick/tests/unit/benchmark/scenarios/networking/test_ping.py index 559e0599e..944202658 100644 --- a/yardstick/tests/unit/benchmark/scenarios/networking/test_ping.py +++ b/yardstick/tests/unit/benchmark/scenarios/networking/test_ping.py @@ -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) -- cgit 1.2.3-korg