From 407a748f3e94800efdc7b42c3196aaec1288e07c Mon Sep 17 00:00:00 2001 From: Sonic Build Admin Date: Thu, 19 Feb 2026 23:05:43 +0000 Subject: [PATCH] Added misc_utils.py forgotten in PR 21362 ### Description of PR The followup on https://github.com/sonic-net/sonic-mgmt/pull/21362 to add the missing file Summary: Fixes # (issue) ### Type of change - [X] Bug fix - [ ] Testbed and Framework(new/improvement) - [ ] New Test case - [ ] Skipped for non-supported platforms - [ ] Test case improvement ### Back port request - [ ] 202205 - [ ] 202305 - [ ] 202311 - [ ] 202405 - [ ] 202411 - [ ] 202505 - [X] 202511 ### Approach #### What is the motivation for this PR? Forgotten file #### How did you do it? #### How did you verify/test it? #### Any platform specific information? #### Supported testbed topology if it's a new test case? ### Documentation --- ansible/module_utils/misc_utils.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 ansible/module_utils/misc_utils.py diff --git a/ansible/module_utils/misc_utils.py b/ansible/module_utils/misc_utils.py new file mode 100644 index 0000000000..40df94d049 --- /dev/null +++ b/ansible/module_utils/misc_utils.py @@ -0,0 +1,18 @@ +import time + + +def wait_for_path(ssh, host_ip, path_to_check, empty_ok=False, tries=1, delay=5): + with ssh.open_sftp() as sftp: + for _ in range(tries): + try: + stat_result = sftp.stat(path_to_check) + if empty_ok or stat_result.st_size > 0: + return + except FileNotFoundError: + pass + time.sleep(delay) + raise FileNotFoundError( + "Failed to find {}path {} on host {} after {} retries.".format( + "" if empty_ok else "not empty ", path_to_check, host_ip, tries + ) + )