Skip to content
This repository has been archived by the owner on Nov 1, 2023. It is now read-only.

Commit

Permalink
Add node messages to node get (#836)
Browse files Browse the repository at this point in the history
This exposes the node commands that have yet to be processed by the node.  Example use case:  The SDK can now ask "has this node installed my SSH key"
  • Loading branch information
bmc-msft authored Apr 26, 2021
1 parent 541e745 commit ced21b2
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 25 deletions.
5 changes: 4 additions & 1 deletion src/api-service/__app__/node/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from ..onefuzzlib.endpoint_authorization import call_if_user
from ..onefuzzlib.events import get_events
from ..onefuzzlib.request import not_ok, ok, parse_request
from ..onefuzzlib.workers.nodes import Node, NodeTasks
from ..onefuzzlib.workers.nodes import Node, NodeMessage, NodeTasks


def get(req: func.HttpRequest) -> func.HttpResponse:
Expand All @@ -33,6 +33,9 @@ def get(req: func.HttpRequest) -> func.HttpResponse:

node_tasks = NodeTasks.get_by_machine_id(request.machine_id)
node.tasks = [(t.task_id, t.state) for t in node_tasks]
node.messages = [
x.message for x in NodeMessage.get_messages(request.machine_id)
]

return ok(node)

Expand Down
2 changes: 1 addition & 1 deletion src/api-service/__app__/onefuzzlib/workers/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ def key_fields(cls) -> Tuple[str, str]:
return ("pool_name", "machine_id")

def save_exclude(self) -> Optional[MappingIntStrAny]:
return {"tasks": ...}
return {"tasks": ..., "messages": ...}

def telemetry_include(self) -> Optional[MappingIntStrAny]:
return {
Expand Down
47 changes: 24 additions & 23 deletions src/pytypes/onefuzztypes/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -557,13 +557,37 @@ class NodeHeartbeatEntry(BaseModel):
data: List[Dict[str, HeartbeatType]]


class StopNodeCommand(BaseModel):
pass


class StopTaskNodeCommand(BaseModel):
task_id: UUID


class NodeCommandAddSshKey(BaseModel):
public_key: str


class NodeCommand(EnumModel):
stop: Optional[StopNodeCommand]
stop_task: Optional[StopTaskNodeCommand]
add_ssh_key: Optional[NodeCommandAddSshKey]


class NodeCommandEnvelope(BaseModel):
command: NodeCommand
message_id: str


class Node(BaseModel):
timestamp: Optional[datetime] = Field(alias="Timestamp")
pool_name: PoolName
machine_id: UUID
state: NodeState = Field(default=NodeState.init)
scaleset_id: Optional[UUID] = None
tasks: Optional[List[Tuple[UUID, NodeTaskState]]] = None
messages: Optional[List[NodeCommand]] = None
heartbeat: Optional[datetime]
version: str = Field(default="1.0.0")
reimage_requested: bool = Field(default=False)
Expand Down Expand Up @@ -776,29 +800,6 @@ class NodeEventEnvelope(BaseModel):
event: NodeEventShim


class StopNodeCommand(BaseModel):
pass


class StopTaskNodeCommand(BaseModel):
task_id: UUID


class NodeCommandAddSshKey(BaseModel):
public_key: str


class NodeCommand(EnumModel):
stop: Optional[StopNodeCommand]
stop_task: Optional[StopTaskNodeCommand]
add_ssh_key: Optional[NodeCommandAddSshKey]


class NodeCommandEnvelope(BaseModel):
command: NodeCommand
message_id: str


class TaskEvent(BaseModel):
timestamp: Optional[datetime] = Field(alias="Timestamp")
task_id: UUID
Expand Down

0 comments on commit ced21b2

Please sign in to comment.