Skip to content

Commit

Permalink
Fix typing: Strict type checks raised issues
Browse files Browse the repository at this point in the history
  • Loading branch information
hoh committed Apr 9, 2024
1 parent c2b540c commit 7e11125
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/aleph/vm/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class VmExecution:
@property
def is_running(self) -> bool:
return (
self.times.starting_at and not self.times.stopping_at
bool(self.times.starting_at and not self.times.stopping_at)
if not self.persistent
else self.systemd_manager.is_service_active(self.controller_service)
)
Expand Down Expand Up @@ -130,7 +130,11 @@ def uses_payment_stream(self) -> bool:
@property
def has_resources(self) -> bool:
assert self.vm, "The VM attribute has to be set before calling has_resources()"
return self.vm.resources_path.exists() if self.hypervisor == HypervisorType.firecracker else True
if isinstance(self.vm, AlephFirecrackerExecutable):
assert self.hypervisor == HypervisorType.firecracker
return self.vm.resources_path.exists()
else:
return True

def __init__(
self,
Expand Down Expand Up @@ -173,14 +177,18 @@ async def prepare(self) -> None:
return

self.times.preparing_at = datetime.now(tz=timezone.utc)
resources = None
resources: Union[AlephProgramResources, AlephInstanceResources, AlephQemuResources]
if self.is_program:
resources = AlephProgramResources(self.message, namespace=self.vm_hash)
elif self.is_instance:
if self.hypervisor == HypervisorType.firecracker:
resources = AlephInstanceResources(self.message, namespace=self.vm_hash)
elif self.hypervisor == HypervisorType.qemu:
resources = AlephQemuResources(self.message, namespace=self.vm_hash)
else:
raise ValueError(f"Unknown hypervisor type {self.hypervisor}")
else:
raise ValueError("Unknown executable message type")

if not resources:
msg = "Unknown executable message type"
Expand Down

0 comments on commit 7e11125

Please sign in to comment.