Skip to content
This repository has been archived by the owner on Dec 5, 2023. It is now read-only.

Commit

Permalink
Merge pull request #6 from microservices-demo/test/container-stability
Browse files Browse the repository at this point in the history
Improve container test stability
  • Loading branch information
Phil Winder authored Sep 23, 2016
2 parents 24ba473 + ef628b4 commit 88d4525
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions test/util/Docker.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import re
from subprocess import Popen, PIPE
from random import random
import time

# From http://blog.bordage.pro/avoid-docker-py/
class Docker:
Expand All @@ -20,6 +21,7 @@ def random_container_name(self, prefix):
return retstr

def get_container_ip(self, ctr_name):
self.waitForContainerToStart(ctr_name)
command = ['docker', 'inspect',
'--format', '\'{{.NetworkSettings.IPAddress}}\'',
ctr_name]
Expand All @@ -37,3 +39,13 @@ def execute(self, command, dump_streams=False):
def start_container(self, container_name="", image="", cmd="", host=""):
command = ['docker', 'run', '-d', '-h', host, '--name', container_name, image]
self.execute(command)

def waitForContainerToStart(self, ctr_name):
command = ['docker', 'inspect',
'--format', '\'{{.State.Status}}\'',
ctr_name]
status = re.sub(r'[^a-z]*', '', self.execute(command))
while status != "running":
time.sleep(1)
print("Status: " + status + ". Waiting for container to start.")
status = re.sub(r'[^a-z]*', '', self.execute(command))

0 comments on commit 88d4525

Please sign in to comment.