Skip to content
This repository was archived by the owner on Jan 23, 2026. It is now read-only.

Commit 55f3456

Browse files
committed
Use new get_device
1 parent 9896633 commit 55f3456

3 files changed

Lines changed: 6 additions & 46 deletions

File tree

packages/jumpstarter-driver-corellium/jumpstarter_driver_corellium/corellium/api.py

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -68,22 +68,17 @@ async def get_project(self, project_ref: str = "Default Project") -> Optional[Pr
6868

6969
return None
7070

71-
def get_device(self, model: str) -> Optional[Device]:
71+
async def get_device(self, model: str) -> Optional[Device]:
7272
"""
7373
Get a device spec from Corellium's list based on the model name.
7474
7575
A device object is used to create a new virtual instance.
7676
"""
77-
try:
78-
res = self.req.get(f"{self.baseurl}/v1/models")
79-
data = res.json()
80-
res.raise_for_status()
81-
except requests.exceptions.RequestException as e:
82-
raise CorelliumApiException(data.get("error", str(e))) from e
8377

84-
for device in data:
85-
if device["model"] == model:
86-
return Device(**device)
78+
models = await self.api.v1_get_models()
79+
for device in models:
80+
if device.model == model:
81+
return device
8782

8883
return None
8984

packages/jumpstarter-driver-corellium/jumpstarter_driver_corellium/corellium/api_test.py

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -54,41 +54,6 @@ async def test_login_error(requests_mock, status_code, data, msg):
5454
assert api.session is None
5555

5656

57-
@pytest.mark.parametrize(
58-
"model,data,has_results",
59-
[("rpi4b", fixture("http/get-models-200.json"), True), ("notfound", fixture("http/get-models-200.json"), False)],
60-
)
61-
async def test_get_device_ok(requests_mock, model, data, has_results):
62-
requests_mock.get("https://api-host/api/v1/models", status_code=200, text=data)
63-
api = ApiClient("api-host", "api-token")
64-
api.session = Session("session-token", "2022-03-20T01:50:10.000Z")
65-
66-
device = api.get_device(model)
67-
68-
if has_results:
69-
assert device is not None
70-
assert device.model == model
71-
else:
72-
assert device is None
73-
74-
75-
@pytest.mark.parametrize(
76-
"status_code,data,msg",
77-
[
78-
(403, fixture("http/403.json"), "Invalid or missing authorization token"),
79-
],
80-
)
81-
async def test_get_device_error(requests_mock, status_code, data, msg):
82-
requests_mock.get("https://api-host/api/v1/models", status_code=status_code, text=data)
83-
api = ApiClient("api-host", "api-token")
84-
api.session = Session("session-token", "2022-03-20T01:50:10.000Z")
85-
86-
with pytest.raises(CorelliumApiException) as e:
87-
api.get_device("mymodel")
88-
89-
assert msg in str(e.value)
90-
91-
9257
async def test_create_instance_ok(requests_mock):
9358
data = fixture("http/create-instance-200.json")
9459
requests_mock.post("https://api-host/api/v1/instances", status_code=200, text=data)

packages/jumpstarter-driver-corellium/jumpstarter_driver_corellium/driver.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ async def on(self) -> None:
158158
raise ValueError(f"Unable to fetch project: {self.parent.project_id}")
159159
self.logger.info(f"Using project: {project.name}")
160160

161-
device = self.parent.api.get_device(self.parent.device_flavor)
161+
device = await self.parent.api.get_device(self.parent.device_flavor)
162162
if device is None:
163163
raise ValueError("Unable to find a device for this model: {self.parent.device_model}")
164164
self.logger.info(f"Using device spec: {device.name}")

0 commit comments

Comments
 (0)