From 56da15ad6d89096b32141defb85ec91b7f185c09 Mon Sep 17 00:00:00 2001 From: Tzanetos Balitsaris Date: Mon, 15 Sep 2014 14:58:22 +0300 Subject: [PATCH] Fix ping_ip_address method in order to be run under BSDs Modify the ping command used in the ping_ip_address static method in order to be run also under BSD systems. Closes-Bug: 1369527 Change-Id: Iac9ef4ab26fca6ca628159569a86c5af089a225a --- rally/benchmark/scenarios/vm/utils.py | 7 +++++- tests/benchmark/scenarios/vm/test_utils.py | 26 ++++++++++++++++++---- 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/rally/benchmark/scenarios/vm/utils.py b/rally/benchmark/scenarios/vm/utils.py index 3d7a71d367..be77ba239b 100644 --- a/rally/benchmark/scenarios/vm/utils.py +++ b/rally/benchmark/scenarios/vm/utils.py @@ -15,6 +15,7 @@ import subprocess +import sys from rally.benchmark.scenarios import base from rally.benchmark import utils as bench_utils @@ -80,7 +81,11 @@ class VMScenario(base.Scenario): @staticmethod def ping_ip_address(host, should_succeed=True): - cmd = ['ping', '-c1', '-w1', host] + if sys.platform.startswith('linux'): + cmd = ['ping', '-c1', '-w1', host] + else: + cmd = ['ping', '-c1', host] + proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) diff --git a/tests/benchmark/scenarios/vm/test_utils.py b/tests/benchmark/scenarios/vm/test_utils.py index d8f6fbddbb..640e568d05 100644 --- a/tests/benchmark/scenarios/vm/test_utils.py +++ b/tests/benchmark/scenarios/vm/test_utils.py @@ -91,18 +91,36 @@ class VMScenarioTestCase(test.TestCase): } vm_scenario.check_network(fake_server, "private_1") + @mock.patch(VMTASKS_UTILS + ".sys") @mock.patch("subprocess.Popen") - def test_ping_ip_address(self, mock_subprocess): - + def test_ping_ip_address_linux(self, mock_subprocess, mock_sys): ping_process = mock.MagicMock() ping_process.returncode = 0 mock_subprocess.return_value = ping_process + mock_sys.platform = 'linux2' vm_scenario = utils.VMScenario() host_ip = "1.2.3.4" self.assertTrue(vm_scenario.ping_ip_address(host_ip)) mock_subprocess.assert_called_once_with( - ['ping', '-c1', '-w1', host_ip], - stderr=subprocess.PIPE, stdout=subprocess.PIPE) + ['ping', '-c1', '-w1', host_ip], + stderr=subprocess.PIPE, stdout=subprocess.PIPE) + ping_process.wait.assert_called_once_with() + + @mock.patch(VMTASKS_UTILS + ".sys") + @mock.patch("subprocess.Popen") + def test_ping_ip_address_other_os(self, mock_subprocess, mock_sys): + ping_process = mock.MagicMock() + ping_process.returncode = 0 + mock_subprocess.return_value = ping_process + mock_sys.platform = 'freebsd10' + + vm_scenario = utils.VMScenario() + host_ip = "1.2.3.4" + self.assertTrue(vm_scenario.ping_ip_address(host_ip)) + + mock_subprocess.assert_called_once_with( + ['ping', '-c1', host_ip], + stderr=subprocess.PIPE, stdout=subprocess.PIPE) ping_process.wait.assert_called_once_with()