Skip to content

Commit

Permalink
Add increased logging to docker start command
Browse files Browse the repository at this point in the history
  • Loading branch information
jefflester committed Jun 11, 2024
1 parent 4d71b57 commit 1c267cb
Showing 1 changed file with 22 additions and 10 deletions.
32 changes: 22 additions & 10 deletions src/test/src/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)."""
Expand All @@ -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}")
Expand Down

0 comments on commit 1c267cb

Please sign in to comment.