Merge "Change logic of wait_for_ping"
This commit is contained in:
commit
b3563501e9
@ -29,6 +29,9 @@ from rally import exceptions
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
ICMP_UP_STATUS = "ICMP UP"
|
||||
ICMP_DOWN_STATUS = "ICMP DOWN"
|
||||
|
||||
|
||||
class VMScenario(base.Scenario):
|
||||
"""Base class for VM scenarios with basic atomic actions.
|
||||
@ -124,9 +127,11 @@ class VMScenario(base.Scenario):
|
||||
|
||||
@base.atomic_action_timer("vm.wait_for_ping")
|
||||
def _wait_for_ping(self, server_ip):
|
||||
server_ip = netaddr.IPAddress(server_ip)
|
||||
bench_utils.wait_for(
|
||||
server_ip,
|
||||
is_ready=self._ping_ip_address,
|
||||
is_ready=bench_utils.resource_is(ICMP_UP_STATUS,
|
||||
self._ping_ip_address),
|
||||
timeout=120
|
||||
)
|
||||
|
||||
@ -156,13 +161,16 @@ class VMScenario(base.Scenario):
|
||||
script, is_file)
|
||||
|
||||
@staticmethod
|
||||
def _ping_ip_address(host, should_succeed=True):
|
||||
ip = netaddr.IPAddress(host)
|
||||
ping = "ping" if ip.version == 4 else "ping6"
|
||||
def _ping_ip_address(host):
|
||||
"""Check ip address that it is pingable.
|
||||
|
||||
:param host: instance of `netaddr.IPAddress`
|
||||
"""
|
||||
ping = "ping" if host.version == 4 else "ping6"
|
||||
if sys.platform.startswith("linux"):
|
||||
cmd = [ping, "-c1", "-w1", host]
|
||||
cmd = [ping, "-c1", "-w1", str(host)]
|
||||
else:
|
||||
cmd = [ping, "-c1", host]
|
||||
cmd = [ping, "-c1", str(host)]
|
||||
|
||||
proc = subprocess.Popen(cmd,
|
||||
stdout=subprocess.PIPE,
|
||||
@ -170,4 +178,4 @@ class VMScenario(base.Scenario):
|
||||
proc.wait()
|
||||
LOG.debug("Host %s is ICMP %s"
|
||||
% (host, proc.returncode and "down" or "up"))
|
||||
return (proc.returncode == 0) == should_succeed
|
||||
return ICMP_UP_STATUS if (proc.returncode == 0) else ICMP_DOWN_STATUS
|
||||
|
@ -17,6 +17,7 @@
|
||||
import subprocess
|
||||
|
||||
import mock
|
||||
import netaddr
|
||||
from oslotest import mockpatch
|
||||
import six
|
||||
|
||||
@ -64,14 +65,17 @@ class VMScenarioTestCase(test.TestCase):
|
||||
vm_scenario._wait_for_ssh(ssh)
|
||||
ssh.wait.assert_called_once_with()
|
||||
|
||||
@mock.patch(VMTASKS_UTILS + ".bench_utils.resource_is")
|
||||
@mock.patch(VMTASKS_UTILS + ".VMScenario._ping_ip_address",
|
||||
return_value=True)
|
||||
def test__wait_for_ping(self, mock__ping):
|
||||
def test__wait_for_ping(self, mock__ping, mock_resource_is):
|
||||
vm_scenario = utils.VMScenario()
|
||||
vm_scenario._wait_for_ping("1.2.3.4")
|
||||
self.wait_for.mock.assert_called_once_with("1.2.3.4",
|
||||
is_ready=mock__ping,
|
||||
vm_scenario._wait_for_ping(netaddr.IPAddress("1.2.3.4"))
|
||||
self.wait_for.mock.assert_called_once_with(
|
||||
netaddr.IPAddress("1.2.3.4"),
|
||||
is_ready=mock_resource_is.return_value,
|
||||
timeout=120)
|
||||
mock_resource_is.assert_called_once_with("ICMP UP", mock__ping)
|
||||
|
||||
@mock.patch(VMTASKS_UTILS + ".VMScenario._run_command_over_ssh")
|
||||
@mock.patch("rally.common.sshutils.SSH")
|
||||
@ -120,11 +124,11 @@ class VMScenarioTestCase(test.TestCase):
|
||||
mock_sys.platform = "linux2"
|
||||
|
||||
vm_scenario = utils.VMScenario()
|
||||
host_ip = "1.2.3.4"
|
||||
host_ip = netaddr.IPAddress("1.2.3.4")
|
||||
self.assertTrue(vm_scenario._ping_ip_address(host_ip))
|
||||
|
||||
mock_subprocess.assert_called_once_with(
|
||||
["ping", "-c1", "-w1", host_ip],
|
||||
["ping", "-c1", "-w1", str(host_ip)],
|
||||
stderr=subprocess.PIPE, stdout=subprocess.PIPE)
|
||||
ping_process.wait.assert_called_once_with()
|
||||
|
||||
@ -137,11 +141,11 @@ class VMScenarioTestCase(test.TestCase):
|
||||
mock_sys.platform = "linux2"
|
||||
|
||||
vm_scenario = utils.VMScenario()
|
||||
host_ip = "1ce:c01d:bee2:15:a5:900d:a5:11fe"
|
||||
host_ip = netaddr.IPAddress("1ce:c01d:bee2:15:a5:900d:a5:11fe")
|
||||
self.assertTrue(vm_scenario._ping_ip_address(host_ip))
|
||||
|
||||
mock_subprocess.assert_called_once_with(
|
||||
["ping6", "-c1", "-w1", host_ip],
|
||||
["ping6", "-c1", "-w1", str(host_ip)],
|
||||
stderr=subprocess.PIPE, stdout=subprocess.PIPE)
|
||||
ping_process.wait.assert_called_once_with()
|
||||
|
||||
@ -154,11 +158,11 @@ class VMScenarioTestCase(test.TestCase):
|
||||
mock_sys.platform = "freebsd10"
|
||||
|
||||
vm_scenario = utils.VMScenario()
|
||||
host_ip = "1.2.3.4"
|
||||
host_ip = netaddr.IPAddress("1.2.3.4")
|
||||
self.assertTrue(vm_scenario._ping_ip_address(host_ip))
|
||||
|
||||
mock_subprocess.assert_called_once_with(
|
||||
["ping", "-c1", host_ip],
|
||||
["ping", "-c1", str(host_ip)],
|
||||
stderr=subprocess.PIPE, stdout=subprocess.PIPE)
|
||||
ping_process.wait.assert_called_once_with()
|
||||
|
||||
@ -171,11 +175,11 @@ class VMScenarioTestCase(test.TestCase):
|
||||
mock_sys.platform = "freebsd10"
|
||||
|
||||
vm_scenario = utils.VMScenario()
|
||||
host_ip = "1ce:c01d:bee2:15:a5:900d:a5:11fe"
|
||||
host_ip = netaddr.IPAddress("1ce:c01d:bee2:15:a5:900d:a5:11fe")
|
||||
self.assertTrue(vm_scenario._ping_ip_address(host_ip))
|
||||
|
||||
mock_subprocess.assert_called_once_with(
|
||||
["ping6", "-c1", host_ip],
|
||||
["ping6", "-c1", str(host_ip)],
|
||||
stderr=subprocess.PIPE, stdout=subprocess.PIPE)
|
||||
ping_process.wait.assert_called_once_with()
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user