Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix how GKEPodAsyncHook.service_file_as_context is used #37306

Merged
merged 1 commit into from
Feb 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions airflow/providers/google/cloud/hooks/kubernetes_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,7 @@ async def get_pod(self, name: str, namespace: str) -> V1Pod:
:param name: Name of the pod.
:param namespace: Name of the pod's namespace.
"""
async with self.service_file_as_context() as service_file: # type: ignore[attr-defined]
with await self.service_file_as_context() as service_file: # type: ignore[attr-defined]
async with Token(scopes=self.scopes, service_file=service_file) as token:
async with self.get_conn(token) as connection:
v1_api = async_client.CoreV1Api(connection)
Expand All @@ -524,7 +524,7 @@ async def delete_pod(self, name: str, namespace: str):
:param name: Name of the pod.
:param namespace: Name of the pod's namespace.
"""
async with self.service_file_as_context() as service_file: # type: ignore[attr-defined]
with await self.service_file_as_context() as service_file: # type: ignore[attr-defined]
async with Token(scopes=self.scopes, service_file=service_file) as token, self.get_conn(
token
) as connection:
Expand All @@ -551,7 +551,7 @@ async def read_logs(self, name: str, namespace: str):
:param name: Name of the pod.
:param namespace: Name of the pod's namespace.
"""
async with self.service_file_as_context() as service_file: # type: ignore[attr-defined]
with await self.service_file_as_context() as service_file: # type: ignore[attr-defined]
async with Token(scopes=self.scopes, service_file=service_file) as token, self.get_conn(
token
) as connection:
Expand Down
12 changes: 6 additions & 6 deletions tests/providers/google/cloud/hooks/test_kubernetes_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -324,8 +324,8 @@ def async_hook(self):
async def test_get_pod(
self, read_namespace_pod_mock, get_conn_mock, mock_token, async_hook, mock_service_file
):
async_hook.service_file_as_context = mock.MagicMock()
async_hook.service_file_as_context.return_value.__aenter__.return_value = mock_service_file
async_hook.service_file_as_context = mock.AsyncMock()
async_hook.service_file_as_context.return_value.__enter__.return_value = mock_service_file

self.make_mock_awaitable(read_namespace_pod_mock)

Expand All @@ -347,8 +347,8 @@ async def test_get_pod(
async def test_delete_pod(
self, delete_namespaced_pod, get_conn_mock, mock_token, async_hook, mock_service_file
):
async_hook.service_file_as_context = mock.MagicMock()
async_hook.service_file_as_context.return_value.__aenter__.return_value = mock_service_file
async_hook.service_file_as_context = mock.AsyncMock()
async_hook.service_file_as_context.return_value.__enter__.return_value = mock_service_file

self.make_mock_awaitable(delete_namespaced_pod)

Expand All @@ -372,8 +372,8 @@ async def test_delete_pod(
async def test_read_logs(
self, read_namespaced_pod_log, get_conn_mock, mock_token, async_hook, mock_service_file, caplog
):
async_hook.service_file_as_context = mock.MagicMock()
async_hook.service_file_as_context.return_value.__aenter__.return_value = mock_service_file
async_hook.service_file_as_context = mock.AsyncMock()
async_hook.service_file_as_context.return_value.__enter__.return_value = mock_service_file

self.make_mock_awaitable(read_namespaced_pod_log, result="Test string #1\nTest string #2\n")

Expand Down