From f857638c42bb2c60d26f958917608cce6a0cec46 Mon Sep 17 00:00:00 2001 From: Benjamin Bolte Date: Wed, 15 Jan 2025 14:35:24 -0800 Subject: [PATCH] remove kernel stuff for now --- tests/routers/test_robot_class.py | 50 ---------------------- www/routers/robot_class.py | 70 ------------------------------- 2 files changed, 120 deletions(-) diff --git a/tests/routers/test_robot_class.py b/tests/routers/test_robot_class.py index ed82c7f4..8ae0b6fe 100644 --- a/tests/routers/test_robot_class.py +++ b/tests/routers/test_robot_class.py @@ -127,53 +127,3 @@ async def test_urdf(test_client: TestClient) -> None: # Check that the URDF is deleted. response = test_client.get("/robots/urdf/test", headers=HEADERS) assert response.status_code == status.HTTP_404_NOT_FOUND, response.text - - -@pytest.mark.asyncio -async def test_kernel(test_client: TestClient) -> None: - # Adds a robot class. - response = test_client.put("/robots/test", params={"description": "Test description"}, headers=HEADERS) - assert response.status_code == status.HTTP_200_OK, response.text - - # Uploads a kernel for the robot class - response = test_client.put( - "/robots/kernel/test", - params={ - "filename": "kernel.so", - "content_type": "application/x-sharedlib", - }, - headers=HEADERS, - ) - assert response.status_code == status.HTTP_200_OK, response.text - data = response.json() - assert data["url"] is not None - - # Uploads the kernel file using the presigned URL - async with httpx.AsyncClient() as client: - response = await client.put( - url=data["url"], - files={"file": ("kernel.so", b"test", data["content_type"])}, - headers={"Content-Type": data["content_type"]}, - ) - assert response.status_code == status.HTTP_200_OK, response.text - - # Gets the kernel for the robot class - response = test_client.get("/robots/kernel/test", headers=HEADERS) - assert response.status_code == status.HTTP_200_OK, response.text - data = response.json() - assert data["url"] is not None - - # Downloads the kernel from the presigned URL - async with httpx.AsyncClient() as client: - response = await client.get(data["url"]) - assert response.status_code == status.HTTP_200_OK, response.text - content = await response.aread() - assert data["md5_hash"] == f'"{hashlib.md5(content).hexdigest()}"' - - # Deletes the robot class - response = test_client.delete("/robots/test", headers=HEADERS) - assert response.status_code == status.HTTP_200_OK, response.text - - # Check that the kernel is deleted - response = test_client.get("/robots/kernel/test", headers=HEADERS) - assert response.status_code == status.HTTP_404_NOT_FOUND, response.text diff --git a/www/routers/robot_class.py b/www/routers/robot_class.py index c3ead68c..33218327 100644 --- a/www/routers/robot_class.py +++ b/www/routers/robot_class.py @@ -165,73 +165,3 @@ async def delete_urdf_for_robot( router.include_router(urdf_router, prefix="/urdf", dependencies=[Depends(require_permissions({"upload"}))]) - - -kernel_router = APIRouter() - - -class RobotDownloadKernelResponse(BaseModel): - url: str - md5_hash: str - - -@kernel_router.get("/{class_name}") -async def get_kernel_image_for_robot( - robot_class: Annotated[RobotClass, Depends(get_robot_class_by_name)], - fs_crud: Annotated[S3Crud, Depends(s3_crud)], -) -> RobotDownloadKernelResponse: - s3_key = kernel_image_s3_key(robot_class) - url, md5_hash = await asyncio.gather( - fs_crud.generate_presigned_download_url(s3_key), - fs_crud.get_file_hash(s3_key), - ) - return RobotDownloadKernelResponse(url=url, md5_hash=md5_hash) - - -class RobotUploadKernelResponse(BaseModel): - url: str - filename: str - content_type: str - - -@kernel_router.put("/{class_name}") -async def upload_kernel_for_robot( - filename: str, - content_type: str, - robot_class: Annotated[RobotClass, Depends(get_robot_class_by_name)], - fs_crud: Annotated[S3Crud, Depends(s3_crud)], -) -> RobotUploadKernelResponse: - # Checks that the content type is valid. - if content_type not in { - "application/octet-stream", - "application/x-sharedlib", - "application/x-so", - "application/x-elf", - "application/x-executable", - "application/x-object", - "application/x-archive", - "application/x-ar", - "application/x-aout", - "application/x-coff", - "application/x-mach-o", - "application/x-mach-o-executable", - "application/x-mach-o-object", - }: - raise ValueError(f"Invalid content type: {content_type}") - - s3_key = kernel_image_s3_key(robot_class) - url = await fs_crud.generate_presigned_upload_url(filename, s3_key, content_type) - return RobotUploadKernelResponse(url=url, filename=filename, content_type=content_type) - - -@kernel_router.delete("/{class_name}") -async def delete_kernel_for_robot( - robot_class: Annotated[RobotClass, Depends(get_robot_class_by_name)], - fs_crud: Annotated[S3Crud, Depends(s3_crud)], -) -> bool: - s3_key = kernel_image_s3_key(robot_class) - await fs_crud.delete_from_s3(s3_key) - return True - - -router.include_router(kernel_router, prefix="/kernel", dependencies=[Depends(require_permissions({"upload"}))])