You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by po...@apache.org on 2022/07/05 10:43:53 UTC
[airflow] branch main updated: `DockerOperator` fix cli.logs giving character array instead of string (#24726)
This is an automated email from the ASF dual-hosted git repository.
potiuk pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow.git
The following commit(s) were added to refs/heads/main by this push:
new cc6a44bdc3 `DockerOperator` fix cli.logs giving character array instead of string (#24726)
cc6a44bdc3 is described below
commit cc6a44bdc396a305fd53c7236427c578e9d4d0b7
Author: Sachin Pasalkar <pa...@gmail.com>
AuthorDate: Tue Jul 5 16:13:43 2022 +0530
`DockerOperator` fix cli.logs giving character array instead of string (#24726)
---
airflow/providers/docker/operators/docker.py | 13 ++++---------
tests/providers/docker/operators/test_docker.py | 13 +------------
2 files changed, 5 insertions(+), 21 deletions(-)
diff --git a/airflow/providers/docker/operators/docker.py b/airflow/providers/docker/operators/docker.py
index 340285dcca..612008bc1d 100644
--- a/airflow/providers/docker/operators/docker.py
+++ b/airflow/providers/docker/operators/docker.py
@@ -331,18 +331,13 @@ class DockerOperator(BaseOperator):
if self.retrieve_output:
return self._attempt_to_retrieve_result()
elif self.do_xcom_push:
- log_parameters = {
- 'container': self.container['Id'],
- 'stdout': True,
- 'stderr': True,
- 'stream': True,
- }
+ if len(log_lines) == 0:
+ return None
try:
if self.xcom_all:
- return [stringify(line).strip() for line in self.cli.logs(**log_parameters)]
+ return log_lines
else:
- lines = [stringify(line).strip() for line in self.cli.logs(**log_parameters, tail=1)]
- return lines[-1] if lines else None
+ return log_lines[-1]
except StopIteration:
# handle the case when there is not a single line to iterate on
return None
diff --git a/tests/providers/docker/operators/test_docker.py b/tests/providers/docker/operators/test_docker.py
index ec30df979a..d03839d727 100644
--- a/tests/providers/docker/operators/test_docker.py
+++ b/tests/providers/docker/operators/test_docker.py
@@ -129,9 +129,6 @@ class TestDockerOperator(unittest.TestCase):
self.client_mock.attach.assert_called_once_with(
container='some_id', stdout=True, stderr=True, stream=True
)
- self.client_mock.logs.assert_called_once_with(
- container='some_id', stdout=True, stderr=True, stream=True, tail=1
- )
self.client_mock.pull.assert_called_once_with('ubuntu:latest', stream=True, decode=True)
self.client_mock.wait.assert_called_once_with('some_id')
assert (
@@ -195,9 +192,6 @@ class TestDockerOperator(unittest.TestCase):
self.client_mock.attach.assert_called_once_with(
container='some_id', stdout=True, stderr=True, stream=True
)
- self.client_mock.logs.assert_called_once_with(
- container='some_id', stdout=True, stderr=True, stream=True, tail=1
- )
self.client_mock.pull.assert_called_once_with('ubuntu:latest', stream=True, decode=True)
self.client_mock.wait.assert_called_once_with('some_id')
assert (
@@ -304,9 +298,6 @@ class TestDockerOperator(unittest.TestCase):
self.client_mock.attach.assert_called_once_with(
container='some_id', stdout=True, stderr=True, stream=True
)
- self.client_mock.logs.assert_called_once_with(
- container='some_id', stdout=True, stderr=True, stream=True, tail=1
- )
self.client_mock.pull.assert_called_once_with('ubuntu:latest', stream=True, decode=True)
self.client_mock.wait.assert_called_once_with('some_id')
assert (
@@ -471,7 +462,7 @@ class TestDockerOperator(unittest.TestCase):
self.client_mock.pull.return_value = [b'{"status":"pull log"}']
self.client_mock.attach.return_value = iter([b'container log 1 ', b'container log 2'])
# Make sure the logs side effect is updated after the change
- self.client_mock.logs.side_effect = (
+ self.client_mock.attach.side_effect = (
lambda **kwargs: iter(self.log_messages[-kwargs['tail'] :])
if 'tail' in kwargs
else iter(self.log_messages)
@@ -511,8 +502,6 @@ class TestDockerOperator(unittest.TestCase):
self.log_messages = []
self.client_mock.pull.return_value = [b'{"status":"pull log"}']
self.client_mock.attach.return_value = iter([])
- # Make sure the logs side effect is updated after the change
- self.client_mock.logs.side_effect = iter([])
kwargs = {
'api_version': '1.19',