Skip to content

Commit

Permalink
Use unified logging system for confidential
Browse files Browse the repository at this point in the history
  • Loading branch information
olethanh committed Jun 26, 2024
1 parent ddec01b commit be4aa9d
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/aleph/vm/controllers/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ async def execute_persistent_vm(config: Configuration):
process = await execution.start(config.vm_configuration.config_file_path)
elif isinstance(config.vm_configuration, QemuConfidentialVMConfiguration): # FIXME
assert isinstance(config.vm_configuration, QemuConfidentialVMConfiguration)
execution = QemuConfidentialVM(config.vm_configuration)
execution = QemuConfidentialVM(config.vm_hash, config.vm_configuration)
process = await execution.start()
else:
assert isinstance(config.vm_configuration, QemuVMConfiguration)
Expand Down
2 changes: 1 addition & 1 deletion src/aleph/vm/controllers/qemu/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class QemuVmClient:
def __init__(self, vm):
self.vm = vm
if not (vm.qmp_socket_path and vm.qmp_socket_path.exists()):
raise Exception
raise Exception("VM is not running")
client = qmp.QEMUMonitorProtocol(str(vm.qmp_socket_path))
client.connect()

Expand Down
10 changes: 6 additions & 4 deletions src/aleph/vm/controllers/qemu_confidential/instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,7 @@ def __init__(
hardware_resources: MachineResources = MachineResources(),
tap_interface: Optional[TapInterface] = None,
):
super().__init__(
vm_id, vm_hash, resources, enable_networking, enable_console, hardware_resources, tap_interface
)
super().__init__(vm_id, vm_hash, resources, enable_networking, hardware_resources, tap_interface)

async def setup(self):
pass
Expand Down Expand Up @@ -106,7 +104,11 @@ async def configure(self):
)

configuration = Configuration(
vm_id=self.vm_id, settings=settings, vm_configuration=vm_configuration, hypervisor=HypervisorType.qemu
vm_id=self.vm_id,
vm_hash=self.vm_hash,
settings=settings,
vm_configuration=vm_configuration,
hypervisor=HypervisorType.qemu,
)
logger.debug(configuration)

Expand Down
3 changes: 2 additions & 1 deletion src/aleph/vm/hypervisors/qemu/qemuvm.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class QemuVM:
vcpu_count: int
mem_size_mb: int
interface_name: str
qemu_process = None
qemu_process: Optional[Process] = None

def __repr__(self) -> str:
if self.qemu_process:
Expand Down Expand Up @@ -95,6 +95,7 @@ async def start(
if self.cloud_init_drive_path:
args += ["-cdrom", f"{self.cloud_init_drive_path}"]
print(*args)

self.qemu_process = proc = await asyncio.create_subprocess_exec(
*args,
stdin=asyncio.subprocess.DEVNULL,
Expand Down
16 changes: 11 additions & 5 deletions src/aleph/vm/hypervisors/qemu_confidential/qemuvm.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import asyncio
from asyncio.subprocess import Process
from pathlib import Path
from typing import TextIO

from cpuid.features import secure_encryption_info
from systemd import journal

from aleph.vm.controllers.configuration import QemuConfidentialVMConfiguration
from aleph.vm.controllers.qemu.instance import logger
Expand All @@ -21,8 +23,8 @@ def __repr__(self) -> str:
else:
return "<QemuConfidentialVM: not running>"

def __init__(self, config: QemuConfidentialVMConfiguration):
super().__init__(config)
def __init__(self, vm_hash, config: QemuConfidentialVMConfiguration):
super().__init__(vm_hash, config)
self.qemu_bin_path = config.qemu_bin_path
self.cloud_init_drive_path = config.cloud_init_drive_path
self.image_path = config.image_path
Expand All @@ -47,6 +49,8 @@ async def start(
# -net tap,ifname=tap0,script=no,downscript=no -drive file=alpine.qcow2,media=disk,if=virtio -nographic
# hardware_resources.published ports -> not implemented at the moment
# hardware_resources.seconds -> only for microvm
journal_stdout: TextIO = journal.stream(self._journal_stdout_name)
journal_stderr: TextIO = journal.stream(self._journal_stderr_name)

# TODO : ensure this is ok at launch
sev_info = secure_encryption_info()
Expand Down Expand Up @@ -114,9 +118,11 @@ async def start(
self.qemu_process = proc = await asyncio.create_subprocess_exec(
*args,
stdin=asyncio.subprocess.DEVNULL,
stdout=asyncio.subprocess.PIPE,
stderr=asyncio.subprocess.PIPE,
stdout=journal_stdout,
stderr=journal_stderr,
)

logger.debug(f"started QemuConfidentialVM vm {self}, {proc}")
print(
f"Started QemuVm {self}, {proc}. Log available with: journalctl -t {self._journal_stdout_name} -t {self._journal_stderr_name}"
)
return proc
2 changes: 2 additions & 0 deletions src/aleph/vm/orchestrator/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,8 @@ async def start_persistent_vm(vm_hash: ItemHash, pubsub: Optional[PubSub], pool:
if not execution:
logger.info(f"Starting persistent virtual machine with id: {vm_hash}")
execution = await create_vm_execution(vm_hash=vm_hash, pool=pool, persistent=True)
else:
logger.info(f"{vm_hash} is already running")

await execution.becomes_ready()

Expand Down

0 comments on commit be4aa9d

Please sign in to comment.