diff options
author | Joffrey F <joffrey@docker.com> | 2017-03-02 16:59:00 -0800 |
---|---|---|
committer | Joffrey F <joffrey@docker.com> | 2017-03-06 18:13:16 -0800 |
commit | bf7c2bc0f885fbbcf33d6ed964bafaf41b28d3c4 (patch) | |
tree | 46347f528df8cb6fc79cfa9259af696e6aa302f0 /tests/helpers.py | |
parent | 83388ec31ae0e81fec0c6904f74e04345f1fb069 (diff) |
Use create_host_file in run -v tests to ensure file availability
Signed-off-by: Joffrey F <joffrey@docker.com>
Diffstat (limited to 'tests/helpers.py')
-rw-r--r-- | tests/helpers.py | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/tests/helpers.py b/tests/helpers.py index 4b422a6a..59efd255 100644 --- a/tests/helpers.py +++ b/tests/helpers.py @@ -1,6 +1,8 @@ from __future__ import absolute_import from __future__ import unicode_literals +import os + from compose.config.config import ConfigDetails from compose.config.config import ConfigFile from compose.config.config import load @@ -15,3 +17,30 @@ def build_config_details(contents, working_dir='working_dir', filename='filename working_dir, [ConfigFile(filename, contents)], ) + + +def create_host_file(client, filename): + dirname = os.path.dirname(filename) + + with open(filename, 'r') as fh: + content = fh.read() + + container = client.create_container( + 'busybox:latest', + ['sh', '-c', 'echo -n "{}" > {}'.format(content, filename)], + volumes={dirname: {}}, + host_config=client.create_host_config( + binds={dirname: {'bind': dirname, 'ro': False}}, + network_mode='none', + ), + ) + try: + client.start(container) + exitcode = client.wait(container) + + if exitcode != 0: + output = client.logs(container) + raise Exception( + "Container exited with code {}:\n{}".format(exitcode, output)) + finally: + client.remove_container(container, force=True) |