[Frontend] Move api_server.py out openai folder (#52131)
Signed-off-by: wang.yuqi <yuqi.wang@daocloud.io>
This commit is contained in:
@@ -14,7 +14,7 @@ import pytest
|
||||
from fastapi import HTTPException
|
||||
from prometheus_client import CollectorRegistry
|
||||
|
||||
from vllm.entrypoints.openai.api_server import build_app
|
||||
from vllm.entrypoints.launchers.api_server.entry import build_app
|
||||
from vllm.exceptions import (
|
||||
VLLMNotFoundError,
|
||||
VLLMServerError,
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
|
||||
|
||||
from tempfile import TemporaryDirectory
|
||||
|
||||
import httpx
|
||||
import pytest
|
||||
|
||||
from tests.utils import RemoteOpenAIServer
|
||||
from vllm import envs
|
||||
from vllm.version import __version__ as VLLM_VERSION
|
||||
|
||||
MODEL_NAME = "Qwen/Qwen3-0.6B"
|
||||
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
def server():
|
||||
with TemporaryDirectory() as tmpdir:
|
||||
args = [
|
||||
# use half precision for speed and memory savings in CI environment
|
||||
"--dtype",
|
||||
"bfloat16",
|
||||
"--max-model-len",
|
||||
"8192",
|
||||
"--enforce-eager",
|
||||
"--max-num-seqs",
|
||||
"128",
|
||||
"--uds",
|
||||
f"{tmpdir}/vllm.sock",
|
||||
]
|
||||
|
||||
with RemoteOpenAIServer(MODEL_NAME, args) as remote_server:
|
||||
yield remote_server
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_show_version(server: RemoteOpenAIServer):
|
||||
transport = httpx.HTTPTransport(uds=server.uds)
|
||||
client = httpx.Client(transport=transport)
|
||||
response = client.get(server.url_for("version"))
|
||||
response.raise_for_status()
|
||||
|
||||
payload = response.json()
|
||||
assert payload["version"] == VLLM_VERSION
|
||||
if envs.VLLM_USE_RUST_FRONTEND:
|
||||
assert payload["rust_frontend_version"] == VLLM_VERSION
|
||||
@@ -1,102 +0,0 @@
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
|
||||
import asyncio
|
||||
import tempfile
|
||||
from pathlib import Path
|
||||
from ssl import SSLContext
|
||||
|
||||
import pytest
|
||||
|
||||
from vllm.entrypoints.serve.utils.ssl import SSLCertRefresher
|
||||
|
||||
|
||||
class MockSSLContext(SSLContext):
|
||||
def __init__(self):
|
||||
self.load_cert_chain_count = 0
|
||||
self.load_ca_count = 0
|
||||
|
||||
def load_cert_chain(
|
||||
self,
|
||||
certfile,
|
||||
keyfile=None,
|
||||
password=None,
|
||||
):
|
||||
self.load_cert_chain_count += 1
|
||||
|
||||
def load_verify_locations(
|
||||
self,
|
||||
cafile=None,
|
||||
capath=None,
|
||||
cadata=None,
|
||||
):
|
||||
self.load_ca_count += 1
|
||||
|
||||
|
||||
def create_file() -> str:
|
||||
with tempfile.NamedTemporaryFile(dir="/tmp", delete=False) as f:
|
||||
return f.name
|
||||
|
||||
|
||||
def touch_file(path: str) -> None:
|
||||
Path(path).touch()
|
||||
|
||||
|
||||
async def wait_for_counts(
|
||||
ssl_context: MockSSLContext,
|
||||
*,
|
||||
cert_chain_count: int,
|
||||
ca_count: int,
|
||||
timeout: float = 5.0,
|
||||
) -> None:
|
||||
deadline = asyncio.get_running_loop().time() + timeout
|
||||
while True:
|
||||
if (
|
||||
ssl_context.load_cert_chain_count >= cert_chain_count
|
||||
and ssl_context.load_ca_count >= ca_count
|
||||
):
|
||||
return
|
||||
|
||||
if asyncio.get_running_loop().time() >= deadline:
|
||||
assert ssl_context.load_cert_chain_count >= cert_chain_count
|
||||
assert ssl_context.load_ca_count >= ca_count
|
||||
|
||||
await asyncio.sleep(0.05)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_ssl_refresher():
|
||||
ssl_context = MockSSLContext()
|
||||
key_path = create_file()
|
||||
cert_path = create_file()
|
||||
ca_path = create_file()
|
||||
ssl_refresher = SSLCertRefresher(ssl_context, key_path, cert_path, ca_path)
|
||||
await asyncio.sleep(1)
|
||||
assert ssl_context.load_cert_chain_count == 0
|
||||
assert ssl_context.load_ca_count == 0
|
||||
|
||||
touch_file(key_path)
|
||||
await wait_for_counts(
|
||||
ssl_context,
|
||||
cert_chain_count=1,
|
||||
ca_count=0,
|
||||
)
|
||||
assert ssl_context.load_ca_count == 0
|
||||
|
||||
touch_file(cert_path)
|
||||
touch_file(ca_path)
|
||||
await wait_for_counts(
|
||||
ssl_context,
|
||||
cert_chain_count=2,
|
||||
ca_count=1,
|
||||
)
|
||||
|
||||
ssl_refresher.stop()
|
||||
await asyncio.sleep(0)
|
||||
cert_chain_count = ssl_context.load_cert_chain_count
|
||||
ca_count = ssl_context.load_ca_count
|
||||
|
||||
touch_file(cert_path)
|
||||
touch_file(ca_path)
|
||||
await asyncio.sleep(1)
|
||||
assert ssl_context.load_cert_chain_count == cert_chain_count
|
||||
assert ssl_context.load_ca_count == ca_count
|
||||
Reference in New Issue
Block a user