From 34bf59ac4cbbad5009c735e852f578f2e979fe93 Mon Sep 17 00:00:00 2001 From: Henry Finucane Date: Mon, 12 May 2014 23:21:55 -0700 Subject: [PATCH 1/2] Allow wait_for to wait on non-traditional files Use os.path.exists to check for file existence, instead of "can we open this file for reading". Fixes #6710 --- utilities/wait_for | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/utilities/wait_for b/utilities/wait_for index 3a381f06944..2a43ecf16a6 100644 --- a/utilities/wait_for +++ b/utilities/wait_for @@ -176,21 +176,24 @@ def main(): end = start + datetime.timedelta(seconds=timeout) while datetime.datetime.now() < end: if path: - try: - f = open(path) - try: - if search_regex: - if re.search(search_regex, f.read(), re.MULTILINE): - break - else: - time.sleep(1) - else: - break - finally: - f.close() - except IOError: + if os.path.exists(path): + if search_regex: + try: + f = open(path) + try: + if re.search(search_regex, f.read(), re.MULTILINE): + break + else: + time.sleep(1) + finally: + f.close() + except IOError: + time.sleep(1) + pass + else: + break + else: time.sleep(1) - pass elif port: s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.settimeout(connect_timeout) From 898ebf73581bfa922527aa157f211cd0ed38e6ab Mon Sep 17 00:00:00 2001 From: Henry Finucane Date: Tue, 13 May 2014 09:43:47 -0700 Subject: [PATCH 2/2] Fail fast in the presence of permissions issues --- utilities/wait_for | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/utilities/wait_for b/utilities/wait_for index 2a43ecf16a6..8111d319169 100644 --- a/utilities/wait_for +++ b/utilities/wait_for @@ -176,7 +176,8 @@ def main(): end = start + datetime.timedelta(seconds=timeout) while datetime.datetime.now() < end: if path: - if os.path.exists(path): + try: + os.stat(path) if search_regex: try: f = open(path) @@ -192,8 +193,13 @@ def main(): pass else: break - else: - time.sleep(1) + except OSError, e: + # File not present + if os.errno == 2: + time.sleep(1) + else: + elapsed = datetime.datetime.now() - start + module.fail_json(msg="Failed to stat %s, %s" % (path, e.strerror), elapsed=elapsed.seconds) elif port: s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.settimeout(connect_timeout)