From be0248817d14eac91b284bf20d931b2db6c22493 Mon Sep 17 00:00:00 2001 From: Shay Arbov Date: Mon, 8 May 2017 12:59:02 +0300 Subject: [PATCH] Use the host's docker client --- skipper/runner.py | 3 +++ tests/test_runner.py | 23 ++++++++++++++--------- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/skipper/runner.py b/skipper/runner.py index de792bf..4ba5445 100644 --- a/skipper/runner.py +++ b/skipper/runner.py @@ -5,6 +5,8 @@ import subprocess from contextlib import contextmanager +DOCKER_PATH_ON_HOST = subprocess.check_output('which docker', shell=True).strip() + def run(command, fqdn_image=None, environment=None, interactive=False, net='host', volumes=None, workdir=None): if fqdn_image is not None: @@ -55,6 +57,7 @@ def _run_nested(fqdn_image, environment, command, interactive, net='host', volum '%(workspace)s:%(workspace)s:rw,Z' % dict(workspace=workspace), '/var/lib/osmosis:/var/lib/osmosis:rw,Z' % dict(workspace=workspace), '/var/run/docker.sock:/var/run/docker.sock:Z', + '{docker_path_on_host}:/usr/bin/docker:ro'.format(docker_path_on_host=DOCKER_PATH_ON_HOST), '/opt/skipper/skipper-entrypoint.sh:/opt/skipper/skipper-entrypoint.sh:Z', ]) for volume in volumes: diff --git a/tests/test_runner.py b/tests/test_runner.py index cb68fe7..a84c73c 100644 --- a/tests/test_runner.py +++ b/tests/test_runner.py @@ -1,9 +1,8 @@ -import mock import os -import subprocess +import mock import unittest from skipper import runner - +from skipper.runner import DOCKER_PATH_ON_HOST USER_ID = 1000 GROUP_ID = 2000 @@ -63,13 +62,14 @@ def test_run_simple_command_nested_network_exist(self, check_output_mock, popen_ '-v', '%(workdir)s:%(workdir)s:rw,Z' % dict(workdir=WORKDIR), '-v', '/var/lib/osmosis:/var/lib/osmosis:rw,Z', '-v', '/var/run/docker.sock:/var/run/docker.sock:Z', + '-v', '{docker_path_on_host}:/usr/bin/docker:ro'.format(docker_path_on_host=DOCKER_PATH_ON_HOST), '-v', '/opt/skipper/skipper-entrypoint.sh:/opt/skipper/skipper-entrypoint.sh:Z', '-w', PROJECT_DIR, '--entrypoint', '/opt/skipper/skipper-entrypoint.sh', FQDN_IMAGE, command[0] ] - popen_mock.assert_called_once_with(expected_nested_command) + popen_mock.assert_called_with(expected_nested_command) @mock.patch('getpass.getuser', autospec=True, return_value='testuser') @mock.patch('os.getcwd', autospec=True, return_value=PROJECT_DIR) @@ -97,13 +97,14 @@ def test_run_simple_command_nested_network_not_exist(self, check_output_mock, po '-v', '%(workdir)s:%(workdir)s:rw,Z' % dict(workdir=WORKDIR), '-v', '/var/lib/osmosis:/var/lib/osmosis:rw,Z', '-v', '/var/run/docker.sock:/var/run/docker.sock:Z', + '-v', '{docker_path_on_host}:/usr/bin/docker:ro'.format(docker_path_on_host=DOCKER_PATH_ON_HOST), '-v', '/opt/skipper/skipper-entrypoint.sh:/opt/skipper/skipper-entrypoint.sh:Z', '-w', PROJECT_DIR, '--entrypoint', '/opt/skipper/skipper-entrypoint.sh', FQDN_IMAGE, command[0] ] - popen_mock.assert_called_once_with(expected_nested_command) + popen_mock.assert_called_with(expected_nested_command) @mock.patch('getpass.getuser', autospec=True, return_value='testuser') @mock.patch('os.getcwd', autospec=True, return_value=PROJECT_DIR) @@ -133,13 +134,14 @@ def test_run_simple_command_nested_with_env(self, check_output_mock, popen_mock, '-v', '%(workdir)s:%(workdir)s:rw,Z' % dict(workdir=WORKDIR), '-v', '/var/lib/osmosis:/var/lib/osmosis:rw,Z', '-v', '/var/run/docker.sock:/var/run/docker.sock:Z', + '-v', '{docker_path_on_host}:/usr/bin/docker:ro'.format(docker_path_on_host=DOCKER_PATH_ON_HOST), '-v', '/opt/skipper/skipper-entrypoint.sh:/opt/skipper/skipper-entrypoint.sh:Z', '-w', PROJECT_DIR, '--entrypoint', '/opt/skipper/skipper-entrypoint.sh', FQDN_IMAGE, command[0] ] - popen_mock.assert_called_once_with(expected_docker_command) + popen_mock.assert_called_with(expected_docker_command) @mock.patch('getpass.getuser', autospec=True, return_value='testuser') @mock.patch('os.getcwd', autospec=True, return_value=PROJECT_DIR) @@ -168,13 +170,14 @@ def test_run_simple_command_nested_interactive(self, check_output_mock, popen_mo '-v', '%(workdir)s:%(workdir)s:rw,Z' % dict(workdir=WORKDIR), '-v', '/var/lib/osmosis:/var/lib/osmosis:rw,Z', '-v', '/var/run/docker.sock:/var/run/docker.sock:Z', + '-v', '{docker_path_on_host}:/usr/bin/docker:ro'.format(docker_path_on_host=DOCKER_PATH_ON_HOST), '-v', '/opt/skipper/skipper-entrypoint.sh:/opt/skipper/skipper-entrypoint.sh:Z', '-w', PROJECT_DIR, '--entrypoint', '/opt/skipper/skipper-entrypoint.sh', FQDN_IMAGE, command[0] ] - popen_mock.assert_called_once_with(expected_nested_command) + popen_mock.assert_called_with(expected_nested_command) @mock.patch('getpass.getuser', autospec=True, return_value='testuser') @mock.patch('os.getcwd', autospec=True, return_value=PROJECT_DIR) @@ -202,13 +205,14 @@ def test_run_complex_command_nested(self, check_output_mock, popen_mock, grp_get '-v', '%(workdir)s:%(workdir)s:rw,Z' % dict(workdir=WORKDIR), '-v', '/var/lib/osmosis:/var/lib/osmosis:rw,Z', '-v', '/var/run/docker.sock:/var/run/docker.sock:Z', + '-v', '{docker_path_on_host}:/usr/bin/docker:ro'.format(docker_path_on_host=DOCKER_PATH_ON_HOST), '-v', '/opt/skipper/skipper-entrypoint.sh:/opt/skipper/skipper-entrypoint.sh:Z', '-w', PROJECT_DIR, '--entrypoint', '/opt/skipper/skipper-entrypoint.sh', FQDN_IMAGE, ' '.join(command) ] - popen_mock.assert_called_once_with(expected_nested_command) + popen_mock.assert_called_with(expected_nested_command) @mock.patch('getpass.getuser', autospec=True, return_value='testuser') @mock.patch('os.getcwd', autospec=True, return_value=PROJECT_DIR) @@ -238,10 +242,11 @@ def test_run_complex_command_nested_with_env(self, check_output_mock, popen_mock '-v', '%(workdir)s:%(workdir)s:rw,Z' % dict(workdir=WORKDIR), '-v', '/var/lib/osmosis:/var/lib/osmosis:rw,Z', '-v', '/var/run/docker.sock:/var/run/docker.sock:Z', + '-v', '{docker_path_on_host}:/usr/bin/docker:ro'.format(docker_path_on_host=DOCKER_PATH_ON_HOST), '-v', '/opt/skipper/skipper-entrypoint.sh:/opt/skipper/skipper-entrypoint.sh:Z', '-w', PROJECT_DIR, '--entrypoint', '/opt/skipper/skipper-entrypoint.sh', FQDN_IMAGE, ' '.join(command) ] - popen_mock.assert_called_once_with(expected_nested_command) + popen_mock.assert_called_with(expected_nested_command)