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
This commit is contained in:
Tzanetos Balitsaris 2014-09-15 14:58:22 +03:00
parent f109e72ced
commit 56da15ad6d
2 changed files with 28 additions and 5 deletions

View File

@ -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):
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)

View File

@ -91,12 +91,13 @@ 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"
@ -106,3 +107,20 @@ class VMScenarioTestCase(test.TestCase):
['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()