From 0bae841b2a97a2b5f73dcdd54587a9ab35009ddc Mon Sep 17 00:00:00 2001 From: Stanislav Zubov Date: Fri, 23 Oct 2015 17:26:41 +0600 Subject: [PATCH] Sleep in wait_for_generator and refactor ping_vm in clone --- core/utils/__init__.py | 2 ++ vmpool/clone.py | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/core/utils/__init__.py b/core/utils/__init__.py index 8ef8295f..5fd5b60a 100644 --- a/core/utils/__init__.py +++ b/core/utils/__init__.py @@ -156,9 +156,11 @@ def wait_for(condition, timeout=5): return condition() + def generator_wait_for(condition, timeout=5): start = time.time() while not condition() and time.time() - start < timeout: + time.sleep(0.1) yield None yield condition() diff --git a/vmpool/clone.py b/vmpool/clone.py index 0825fc39..00ec7342 100644 --- a/vmpool/clone.py +++ b/vmpool/clone.py @@ -58,8 +58,10 @@ def rebuild(self): def ping_vm(self): ports = [config.SELENIUM_PORT, config.VMMASTER_AGENT_PORT] + result = [False, False] timeout = config.PING_TIMEOUT start = time.time() + log.info("Starting ping vm {clone}: {ip}:{port}".format( clone=self.name, ip=self.ip, port=ports)) _ping = partial(network_utils.ping, self.ip) @@ -72,7 +74,6 @@ def ping_vm(self): break time.sleep(0.1) - result = map(_ping, ports) if not all(result): fails = [port for port, res in zip(ports, result) if res is False] log.info("Failed ping for {clone} with {ip}:{ports}".format(