Skip to content

Commit

Permalink
feat(device): wait until virtual device is online on rapyuta.io
Browse files Browse the repository at this point in the history
This commit adds a field in the device manifest for the apply command to
wait until a virtual device is online on rapyuta.io.
  • Loading branch information
pallabpain committed Oct 15, 2024
1 parent 9e801d2 commit 63f052b
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 0 deletions.
1 change: 1 addition & 0 deletions riocli/apply/manifests/device.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ spec:
os: "ubuntu" # Options: ["ubuntu" (default), "debian" ]
codename: "focal" # Options: ["bionic", "focal" (default), "jammy", "bullseye"]
highperf: False # Optional [True, False (default)]
wait: True # Optional [True, False (default)] Wait until the device is ready.
docker:
enabled: True # Required
rosbagMountPath: "/opt/rapyuta/volumes/rosbag"
Expand Down
4 changes: 4 additions & 0 deletions riocli/device/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from riocli.constants import ApplyResult
from riocli.device.util import (DeviceNotFound, create_hwil_device, delete_hwil_device, execute_onboard_command,
find_device_by_name, make_device_labels_from_hwil_device)
from riocli.device.util import wait_until_online
from riocli.exceptions import ResourceNotFound
from riocli.model import Model

Expand Down Expand Up @@ -79,6 +80,9 @@ def apply(self, *args, **kwargs) -> ApplyResult:
onboard_command = onboard_script.full_command()
execute_onboard_command(hwil_response.id, onboard_command)

if self.spec.get('virtual', {}).get('wait', False):
wait_until_online(device)

return result

def delete(self, *args, **kwargs) -> None:
Expand Down
23 changes: 23 additions & 0 deletions riocli/device/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import functools
import json
import re
import time
import typing
from pathlib import Path

Expand All @@ -22,6 +23,7 @@
from rapyuta_io import Client
from rapyuta_io.clients import LogUploads
from rapyuta_io.clients.device import Device
from rapyuta_io.clients.device import DeviceStatus
from rapyuta_io.utils import RestClient
from rapyuta_io.utils.rest_client import HttpMethod

Expand Down Expand Up @@ -85,6 +87,7 @@ def find_device_guid(client: Client, name: str) -> str:

raise DeviceNotFound()


def find_device_by_name(client: Client, name: str) -> Device:
devices = client.get_all_devices(device_name=name)
if devices:
Expand Down Expand Up @@ -290,3 +293,23 @@ def sanitize_hwil_device_name(name):
r = r + c

return r


def wait_until_online(device: Device, timeout: int = 600) -> None:
"""Wait until the device is online.
This is a helper method that waits until the device is online.
Or, until the timeout is reached. The default timeout is 600 seconds.
"""
counter, interval = 0, 20
failed_states = (DeviceStatus.FAILED, DeviceStatus.REJECTED)

device.refresh()

while not device.is_online() and device.status not in failed_states and counter < timeout:
counter += interval
time.sleep(interval)
device.refresh()

if not device.is_online() and counter >= timeout:
raise Exception('timeout reached while waiting for the device to be online')
3 changes: 3 additions & 0 deletions riocli/jsonschema/schemas/device-schema.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ definitions:
enabled:
enum:
- True
wait:
type: boolean
default: False
product:
type: string
enum:
Expand Down

0 comments on commit 63f052b

Please sign in to comment.