Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Apr 24, 2023
1 parent f93869c commit 11c6f6c
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 22 deletions.
9 changes: 5 additions & 4 deletions platform_monitoring/kube_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -588,7 +588,10 @@ async def get_pod_container_gpu_stats(
if e.status == 401 and not doing_retry:
await self._recreate_http_client()
return await self.get_pod_container_gpu_stats(
node_name, pod_name, container_name, doing_retry=True,
node_name,
pod_name,
container_name,
doing_retry=True,
)
except aiohttp.ClientError as e:
logger.exception(e)
Expand Down Expand Up @@ -678,9 +681,7 @@ def _assert_resource_kind(
elif kind != expected_kind:
raise ValueError(f"unknown kind: {kind}")

def _raise_for_status(
self, payload: dict[str, Any], job_id: Optional[str]
) -> None:
def _raise_for_status(self, payload: dict[str, Any], job_id: Optional[str]) -> None:
if payload["code"] == 400:
if "ContainerCreating" in payload["message"]:
raise JobNotFoundException(f"job '{job_id}' was not created yet")
Expand Down
4 changes: 1 addition & 3 deletions tests/integration/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,9 +246,7 @@ def _f(**kwargs: Any) -> Config:
platform_api=platform_api_config,
platform_config=platform_config,
s3=s3_config,
logs=LogsConfig(
storage_type=LogsStorageType.S3, cleanup_interval_sec=0.5
),
logs=LogsConfig(storage_type=LogsStorageType.S3, cleanup_interval_sec=0.5),
kube=kube_config,
registry=registry_config,
container_runtime=container_runtime_config,
Expand Down
3 changes: 2 additions & 1 deletion tests/integration/conftest_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,12 @@ async def _wait_for_platform_api_config(
) -> None:
while True:
import warnings

with warnings.catch_warnings():
warnings.filterwarnings("ignore", category=DeprecationWarning)
try:
async with create_platform_api_client(
platform_api_config.url, platform_api_config.token
platform_api_config.url, platform_api_config.token
):
return
except Exception:
Expand Down
1 change: 0 additions & 1 deletion tests/integration/conftest_kube.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@


class MyKubeClient(KubeClient):

# TODO (A Yushkovskiy, 30-May-2019) delete pods automatically

async def create_pod(self, job_pod_descriptor: dict[str, Any]) -> str:
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -1037,7 +1037,8 @@ async def test_attach_forbidden(
async with client.ws_connect(url):
pass
except WSServerHandshakeError as e:
assert e.headers and e.headers.get("X-Error")
assert e.headers
assert e.headers.get("X-Error")
assert e.message == "Invalid response status"
assert e.status == HTTPUnauthorized.status_code

Expand Down Expand Up @@ -1401,7 +1402,6 @@ async def test_kill(
jobs_client: JobsClient,
infinite_job: str,
) -> None:

headers = jobs_client.headers

url = monitoring_api.generate_kill_url(infinite_job)
Expand Down
3 changes: 2 additions & 1 deletion tests/integration/test_jobs_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,8 @@ async def test_save_commit_fails_with_exception(

async def test_get_available_jobs_count(self, jobs_service: JobsService) -> None:
result = await jobs_service.get_available_jobs_counts()
assert result and "cpu-small" in result
assert result
assert "cpu-small" in result

async def test_mark_logs_dropped(
self,
Expand Down
21 changes: 11 additions & 10 deletions tests/integration/test_kube.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
import logging
import re
import uuid
from pathlib import Path
from collections.abc import AsyncIterator, Callable, Coroutine
from contextlib import AbstractAsyncContextManager
from datetime import datetime, timedelta, timezone
from typing import Any, Union
from pathlib import Path
from typing import Any
from unittest import mock
from uuid import uuid4

Expand All @@ -23,8 +23,8 @@
from platform_monitoring.kube_client import (
JobNotFoundException,
KubeClient,
KubeClientException,
KubeClientAuthType,
KubeClientException,
PodContainerStats,
PodPhase,
)
Expand Down Expand Up @@ -72,15 +72,16 @@ async def _stats_summary(request: web.Request) -> web.Response:
async def _gpu_metrics(request: web.Request) -> web.Response:
return web.Response(content_type="text/plain")

def _unauthorized_gpu_metrics(
) -> Callable[[web.Request], Coroutine[Any, Any, web.Response]]:

def _unauthorized_gpu_metrics() -> (
Callable[[web.Request], Coroutine[Any, Any, web.Response]]
):
async def _inner(request: web.Request) -> web.Response:
auth_header = request.headers.get("Authorization", "")
if auth_header.split(" ")[1] == "authorized":
return web.Response(content_type="text/plain")
else:
return web.Response(status=401)

return _inner

def _create_app() -> web.Application:
Expand Down Expand Up @@ -534,7 +535,7 @@ async def test_get_pods(
[
["authorized", True],
["badtoken", False],
]
],
)
async def test_get_pod_container_gpu_stats_handles_unauthorized(
self,
Expand Down Expand Up @@ -1144,7 +1145,7 @@ async def stop_func() -> bool:
def run_log_reader(
name: str, delay: float = 0, timeout_s: float = 60.0
) -> None:
async def coro() -> Union[bytes, Exception]:
async def coro() -> bytes | Exception:
await asyncio.sleep(delay)
try:
async with timeout(timeout_s):
Expand Down Expand Up @@ -1226,7 +1227,7 @@ async def stop_func() -> bool:
def run_log_reader(
name: str, delay: float = 0, timeout_s: float = 60.0
) -> None:
async def coro() -> Union[bytes, Exception]:
async def coro() -> bytes | Exception:
await asyncio.sleep(delay)
try:
async with timeout(timeout_s):
Expand Down Expand Up @@ -1313,7 +1314,7 @@ async def stop_func() -> bool:
def run_log_reader(
name: str, delay: float = 0, timeout_s: float = 60.0
) -> None:
async def coro() -> Union[bytes, Exception]:
async def coro() -> bytes | Exception:
await asyncio.sleep(delay)
try:
async with timeout(timeout_s):
Expand Down

0 comments on commit 11c6f6c

Please sign in to comment.