Skip to content

Commit

Permalink
remove kernel stuff for now
Browse files Browse the repository at this point in the history
  • Loading branch information
codekansas committed Jan 15, 2025
1 parent 6b45dc0 commit f857638
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 120 deletions.
50 changes: 0 additions & 50 deletions tests/routers/test_robot_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
70 changes: 0 additions & 70 deletions www/routers/robot_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"}))])

0 comments on commit f857638

Please sign in to comment.