Merge "Fix ping_ip_address method in order to be run under BSDs"
This commit is contained in:
commit
130b355061
@ -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):
|
||||||
|
if sys.platform.startswith('linux'):
|
||||||
cmd = ['ping', '-c1', '-w1', host]
|
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,12 +91,13 @@ 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"
|
||||||
@ -106,3 +107,20 @@ class VMScenarioTestCase(test.TestCase):
|
|||||||
['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()
|
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()
|
||||||
|
Loading…
Reference in New Issue
Block a user