Skip to content

Commit

Permalink
[FIX] Docker provider - retry docker in docker (#17061)
Browse files Browse the repository at this point in the history
  • Loading branch information
raphaelauv authored Jul 18, 2021
1 parent 16564ca commit b076ac5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
6 changes: 3 additions & 3 deletions airflow/providers/docker/operators/docker.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,12 +247,12 @@ def _run_image(self) -> Optional[str]:
if not self.cli:
raise Exception("The 'cli' should be initialized before!")
if self.mount_tmp_dir:
with TemporaryDirectory(prefix='airflowtmp', dir=self.host_tmp_dir) as host_tmp_dir:
tmp_mount = Mount(self.tmp_dir, host_tmp_dir, "bind")
with TemporaryDirectory(prefix='airflowtmp', dir=self.host_tmp_dir) as host_tmp_dir_generated:
tmp_mount = Mount(self.tmp_dir, host_tmp_dir_generated, "bind")
try:
return self._run_image_with_mounts(self.mounts + [tmp_mount], add_tmp_variable=True)
except APIError as e:
if self.host_tmp_dir in str(e):
if host_tmp_dir_generated in str(e):
self.log.warning(
"Using remote engine or docker-in-docker and mounting temporary "
"volume from host is not supported. Falling back to "
Expand Down
7 changes: 5 additions & 2 deletions tests/providers/docker/operators/test_docker.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,14 @@
pass


TEMPDIR_MOCK_RETURN_VALUE = '/mkdtemp'


class TestDockerOperator(unittest.TestCase):
def setUp(self):
self.tempdir_patcher = mock.patch('airflow.providers.docker.operators.docker.TemporaryDirectory')
self.tempdir_mock = self.tempdir_patcher.start()
self.tempdir_mock.return_value.__enter__.return_value = '/mkdtemp'
self.tempdir_mock.return_value.__enter__.return_value = TEMPDIR_MOCK_RETURN_VALUE

self.client_mock = mock.Mock(spec=APIClient)
self.client_mock.create_container.return_value = {'Id': 'some_id'}
Expand Down Expand Up @@ -185,7 +188,7 @@ def test_execute_no_temp_dir(self):

def test_execute_fallback_temp_dir(self):
self.client_mock.create_container.side_effect = [
APIError(message="wrong path: " + "/host/airflow"),
APIError(message="wrong path: " + TEMPDIR_MOCK_RETURN_VALUE),
{'Id': 'some_id'},
]
operator = DockerOperator(
Expand Down

0 comments on commit b076ac5

Please sign in to comment.