From 1c267cb218e9a5ad6c145b73f197d858ee595958 Mon Sep 17 00:00:00 2001 From: Jeffrey Lester Date: Tue, 11 Jun 2024 10:20:01 -0700 Subject: [PATCH] Add increased logging to docker start command --- src/test/src/common.py | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/src/test/src/common.py b/src/test/src/common.py index d5879b08..7906c6f7 100644 --- a/src/test/src/common.py +++ b/src/test/src/common.py @@ -51,33 +51,45 @@ def log_status(msg): + "\n" ) - def start_docker_daemon(): """Starts the Docker daemon (works on MacOS/Ubuntu).""" + print(f"Starting Docker daemon on {sys.platform}...") + if sys.platform.lower() == "darwin": - return_code = subprocess.call("open --background -a Docker", shell=True) + command = "open --background -a Docker" elif "linux" in sys.platform.lower(): - return_code = subprocess.call( - "sudo service docker start; sudo systemctl start docker.socket", shell=True - ) + command = "service docker start; systemctl start docker.socket" else: raise RuntimeError(f"Incompatible testing platform: {sys.platform}") - if return_code != 0: + + print(f"Executing command: {command}") + process = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + stdout, stderr = process.communicate() + + if process.returncode != 0: + print(f"Command failed with return code {process.returncode}") + print(f"Stdout: {stdout.decode()}") + print(f"Stderr: {stderr.decode()}") raise RuntimeError("Failed to start Docker daemon.") + print("Command executed successfully. Checking if Docker daemon is running...") + counter = 0 while counter < 61: - if counter == 61: - raise TimeoutError("Docker daemon failed to start after one minute.") try: docker_client = docker.from_env() docker_client.ping() + print("Docker daemon is running.") break - except: + except Exception as e: + print(f"Attempt {counter}: Docker daemon is not running. Error: {str(e)}") counter += 1 sleep(1) + if counter == 61: + raise TimeoutError("Docker daemon failed to start after one minute.") + def stop_docker_daemon(): """Stops the Docker daemon (works on MacOS/Ubuntu).""" @@ -86,7 +98,7 @@ def stop_docker_daemon(): return_code = subprocess.call("osascript -e 'quit app \"Docker\"'", shell=True) elif "linux" in sys.platform.lower(): return_code = subprocess.call( - "sudo service docker stop; sudo systemctl stop docker.socket", shell=True + "service docker stop; systemctl stop docker.socket", shell=True ) else: raise RuntimeError(f"Incompatible testing platform: {sys.platform}")