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:
parent
f109e72ced
commit
56da15ad6d
@ -15,6 +15,7 @@
|
|||||||
|
|
||||||
|
|
||||||
import subprocess
|
import subprocess
|
||||||
|
import sys
|
||||||
|
|
||||||
from rally.benchmark.scenarios import base
|
from rally.benchmark.scenarios import base
|
||||||
from rally.benchmark import utils as bench_utils
|
from rally.benchmark import utils as bench_utils
|
||||||
@ -80,7 +81,11 @@ class VMScenario(base.Scenario):
|
|||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def ping_ip_address(host, should_succeed=True):
|
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,
|
proc = subprocess.Popen(cmd,
|
||||||
stdout=subprocess.PIPE,
|
stdout=subprocess.PIPE,
|
||||||
stderr=subprocess.PIPE)
|
stderr=subprocess.PIPE)
|
||||||
|
@ -91,18 +91,36 @@ class VMScenarioTestCase(test.TestCase):
|
|||||||
}
|
}
|
||||||
vm_scenario.check_network(fake_server, "private_1")
|
vm_scenario.check_network(fake_server, "private_1")
|
||||||
|
|
||||||
|
@mock.patch(VMTASKS_UTILS + ".sys")
|
||||||
@mock.patch("subprocess.Popen")
|
@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 = mock.MagicMock()
|
||||||
ping_process.returncode = 0
|
ping_process.returncode = 0
|
||||||
mock_subprocess.return_value = ping_process
|
mock_subprocess.return_value = ping_process
|
||||||
|
mock_sys.platform = 'linux2'
|
||||||
|
|
||||||
vm_scenario = utils.VMScenario()
|
vm_scenario = utils.VMScenario()
|
||||||
host_ip = "1.2.3.4"
|
host_ip = "1.2.3.4"
|
||||||
self.assertTrue(vm_scenario.ping_ip_address(host_ip))
|
self.assertTrue(vm_scenario.ping_ip_address(host_ip))
|
||||||
|
|
||||||
mock_subprocess.assert_called_once_with(
|
mock_subprocess.assert_called_once_with(
|
||||||
['ping', '-c1', '-w1', host_ip],
|
['ping', '-c1', '-w1', host_ip],
|
||||||
stderr=subprocess.PIPE, stdout=subprocess.PIPE)
|
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()
|
ping_process.wait.assert_called_once_with()
|
||||||
|
Loading…
Reference in New Issue
Block a user