From a6e207c16430055eba8bcc8586b09a7081db3d04 Mon Sep 17 00:00:00 2001 From: tomsou Date: Tue, 24 Oct 2017 17:37:37 +0300 Subject: Fix instance boot when metadata exists The way that a instance is considered as UP is pretty strict and returns ERROR in case of instances with userdata This patch differentiates the instances that are supposed to boot till login prompt and those with userdata parameter JIRA: SDNVPN-177 Change-Id: Ic4755366df006669475c90cc0693ac802256f379 Signed-off-by: tomsou --- sdnvpn/lib/utils.py | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) (limited to 'sdnvpn/lib/utils.py') diff --git a/sdnvpn/lib/utils.py b/sdnvpn/lib/utils.py index e241d79..f5cd9dc 100644 --- a/sdnvpn/lib/utils.py +++ b/sdnvpn/lib/utils.py @@ -247,13 +247,10 @@ def get_instance_ip(instance): return instance_ip -def wait_for_instance(instance): - logger.info("Waiting for instance %s to get a DHCP lease and " - "prompt for login..." % instance.id) - # The sleep this function replaced waited for 80s +def wait_for_instance(instance, pattern=".* login:"): + logger.info("Waiting for instance %s to boot up" % instance.id) tries = 40 sleep_time = 2 - pattern = ".* login:" expected_regex = re.compile(pattern) console_log = "" while tries > 0 and not expected_regex.search(console_log): @@ -262,14 +259,20 @@ def wait_for_instance(instance): tries -= 1 if not expected_regex.search(console_log): - logger.error("Instance %s seems not to boot up properly." + logger.error("Instance %s does not boot up properly." % instance.id) return False return True -def wait_for_instances_up(*args): - check = [wait_for_instance(instance) for instance in args] +def wait_for_instances_up(*instances): + check = [wait_for_instance(instance) for instance in instances] + return all(check) + + +def wait_for_instances_get_dhcp(*instances): + check = [wait_for_instance(instance, "Lease of .* obtained") + for instance in instances] return all(check) -- cgit 1.2.3-korg