|
@@ -11,6 +11,7 @@ from threading import Thread
|
|
|
from toolset.utils import setup_util
|
|
|
from toolset.utils.output_helper import tee_output
|
|
|
from toolset.utils.metadata_helper import gather_tests
|
|
|
+from toolset.utils.ordered_set import OrderedSet
|
|
|
|
|
|
|
|
|
def clean():
|
|
@@ -50,10 +51,11 @@ def build(benchmarker_config, test_names, out):
|
|
|
"docker_files in benchmark_config.json must be an array")
|
|
|
|
|
|
for test_docker_file in test_docker_files:
|
|
|
- deps = list(
|
|
|
- reversed(
|
|
|
- gather_dependencies(
|
|
|
- os.path.join(test.directory, test_docker_file))))
|
|
|
+ deps = OrderedSet(
|
|
|
+ list(
|
|
|
+ reversed(
|
|
|
+ __gather_dependencies(
|
|
|
+ os.path.join(test.directory, test_docker_file)))))
|
|
|
|
|
|
docker_dir = os.path.join(setup_util.get_fwroot(), "toolset",
|
|
|
"setup", "docker")
|
|
@@ -121,7 +123,7 @@ def build(benchmarker_config, test_names, out):
|
|
|
return 0
|
|
|
|
|
|
|
|
|
-def run(benchmarker_config, docker_files, out):
|
|
|
+def run(benchmarker_config, docker_files, database_container_id, out):
|
|
|
'''
|
|
|
Run the given Docker container(s)
|
|
|
'''
|
|
@@ -147,6 +149,7 @@ def run(benchmarker_config, docker_files, out):
|
|
|
privileged=True,
|
|
|
stderr=True,
|
|
|
detach=True,
|
|
|
+ init=True,
|
|
|
extra_hosts=extra_hosts)
|
|
|
|
|
|
watch_thread = Thread(target=watch_container, args=(container, ))
|
|
@@ -159,6 +162,20 @@ def run(benchmarker_config, docker_files, out):
|
|
|
print(e)
|
|
|
return 1
|
|
|
|
|
|
+ running_container_length = len(
|
|
|
+ client.containers.list(filters={'status': 'running'}))
|
|
|
+ expected_length = len(docker_files)
|
|
|
+ if database_container_id is not None:
|
|
|
+ expected_length = expected_length + 1
|
|
|
+ if (running_container_length != expected_length):
|
|
|
+ tee_output(out, "Running Containers (id, name):" + os.linesep)
|
|
|
+ for running_container in client.containers.list():
|
|
|
+ tee_output(out, "%s, %s%s" % (running_container.short_id,
|
|
|
+ running_container.image, os.linesep))
|
|
|
+ tee_output(out, "Excepted %s running containers; saw %s%s" %
|
|
|
+ (running_container_length, expected_length, os.linesep))
|
|
|
+ return 1
|
|
|
+
|
|
|
return 0
|
|
|
|
|
|
|
|
@@ -200,38 +217,6 @@ def find(path, pattern):
|
|
|
return os.path.join(root, name)
|
|
|
|
|
|
|
|
|
-def gather_dependencies(docker_file):
|
|
|
- '''
|
|
|
- Gathers all the known docker dependencies for the given docker image.
|
|
|
- '''
|
|
|
- # Avoid setting up a circular import
|
|
|
- from toolset.utils import setup_util
|
|
|
- deps = []
|
|
|
-
|
|
|
- docker_dir = os.path.join(setup_util.get_fwroot(), "toolset", "setup",
|
|
|
- "docker")
|
|
|
-
|
|
|
- if os.path.exists(docker_file):
|
|
|
- with open(docker_file) as fp:
|
|
|
- for line in fp.readlines():
|
|
|
- tokens = line.strip().split(' ')
|
|
|
- if tokens[0] == "FROM":
|
|
|
- # This is magic that our base image points to
|
|
|
- if tokens[1] != "ubuntu:16.04":
|
|
|
- depToken = tokens[1].strip().split(':')[
|
|
|
- 0].strip().split('/')[1]
|
|
|
- deps.append(depToken)
|
|
|
- dep_docker_file = os.path.join(
|
|
|
- os.path.dirname(docker_file),
|
|
|
- depToken + ".dockerfile")
|
|
|
- if not os.path.exists(dep_docker_file):
|
|
|
- dep_docker_file = find(docker_dir,
|
|
|
- depToken + ".dockerfile")
|
|
|
- deps.extend(gather_dependencies(dep_docker_file))
|
|
|
-
|
|
|
- return deps
|
|
|
-
|
|
|
-
|
|
|
def start_database(config, database):
|
|
|
'''
|
|
|
Sets up a container for the given database and port, and starts said docker
|
|
@@ -304,4 +289,40 @@ def start_database(config, database):
|
|
|
stdout=subprocess.PIPE,
|
|
|
stderr=subprocess.STDOUT)
|
|
|
out = p.communicate("docker run -d --rm --network=host %s" % database)[0]
|
|
|
- return out.splitlines()[len(out.splitlines()) - 1]
|
|
|
+ return out.splitlines()[len(out.splitlines()) - 1]
|
|
|
+
|
|
|
+
|
|
|
+def __gather_dependencies(docker_file):
|
|
|
+ '''
|
|
|
+ Gathers all the known docker dependencies for the given docker image.
|
|
|
+ '''
|
|
|
+ # Avoid setting up a circular import
|
|
|
+ from toolset.utils import setup_util
|
|
|
+ deps = []
|
|
|
+
|
|
|
+ docker_dir = os.path.join(setup_util.get_fwroot(), "toolset", "setup",
|
|
|
+ "docker")
|
|
|
+
|
|
|
+ if os.path.exists(docker_file):
|
|
|
+ with open(docker_file) as fp:
|
|
|
+ for line in fp.readlines():
|
|
|
+ tokens = line.strip().split(' ')
|
|
|
+ if tokens[0] == "FROM":
|
|
|
+ # This is magic that our base image points to
|
|
|
+ if tokens[1] != "ubuntu:16.04":
|
|
|
+ dep_ref = tokens[1].strip().split(':')[0].strip()
|
|
|
+ if '/' not in dep_ref:
|
|
|
+ raise AttributeError(
|
|
|
+ "Could not find docker FROM dependency: %s" %
|
|
|
+ dep_ref)
|
|
|
+ depToken = dep_ref.split('/')[1]
|
|
|
+ deps.append(depToken)
|
|
|
+ dep_docker_file = os.path.join(
|
|
|
+ os.path.dirname(docker_file),
|
|
|
+ depToken + ".dockerfile")
|
|
|
+ if not os.path.exists(dep_docker_file):
|
|
|
+ dep_docker_file = find(docker_dir,
|
|
|
+ depToken + ".dockerfile")
|
|
|
+ deps.extend(__gather_dependencies(dep_docker_file))
|
|
|
+
|
|
|
+ return deps
|