Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

716 updating pydantic version #721

Open
wants to merge 104 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
Show all changes
104 commits
Select commit Hold shift + click to select a range
418589d
Feat: Starting upgrading Pydantic using dump-pyndatic
Antonyjin Oct 31, 2024
998a0d4
fix: Missing type annotation after pydantic update
Antonyjin Oct 31, 2024
ea51db4
fix settings
olethanh Oct 31, 2024
d17a2ee
Fix: error handling in `get_signed_pubkey` for improved JSON and vali…
Antonyjin Nov 4, 2024
543b9f4
Fix: Migration to pydantic 2 rose some warnings
Antonyjin Nov 4, 2024
c5bd2cd
Fix: Pydantic 2 is strict with typing annotation
Antonyjin Nov 4, 2024
64b93d1
Fix: Adapt test mocks to Pydantic v2 by replacing `.json` with `.mode…
Antonyjin Nov 4, 2024
2d66051
Fix: Pydantic 2 add more information in return error
Antonyjin Nov 4, 2024
9ffdbb2
Style: black, isort and mypy
Antonyjin Nov 4, 2024
bf26b1b
Style: black n vm_connector
Antonyjin Nov 4, 2024
37363d8
Style: black pyproject
Antonyjin Nov 4, 2024
aac48cc
Style: black pyproject
Antonyjin Nov 4, 2024
1a22d1e
style: Mypy detected some error about model_dump_json
Antonyjin Nov 8, 2024
4f33457
fix: Additional slash not needed in the url
Antonyjin Nov 11, 2024
9fd949d
fix: Forcing the version 2 of pydantic
Antonyjin Nov 11, 2024
b756687
fix: yamlfix and pydantic are incompatible
Antonyjin Nov 11, 2024
7db1e35
Fix: HttpUrl no longer need scheme value
Antonyjin Nov 12, 2024
6acdc3c
Fix: revert changes about json
Antonyjin Nov 12, 2024
c1bdd96
Fix: Pydantic 2 handle differently the errors
Antonyjin Nov 12, 2024
9604e70
Style: isortwq
Antonyjin Nov 12, 2024
17cd07e
Refactor: update validation for Pydantic v2
Antonyjin Nov 12, 2024
249c322
Fix: Correct import statement from '__futures__' to '__future__' for …
Antonyjin Nov 12, 2024
e82fe24
style: black
Antonyjin Nov 12, 2024
9b75411
style: isort
Antonyjin Nov 12, 2024
87f7a4c
Fix: Missing dependency in the debian Makefile
Antonyjin Nov 14, 2024
35f1ed8
Fix: Wrong version of aleph-message inside the Makefile
Antonyjin Nov 14, 2024
755680a
Fix: Wrong name for aleph-message inside the Makefile
Antonyjin Nov 14, 2024
74847bc
fix: dump_wargs arg don't work the same in pydantic 2
Antonyjin Nov 14, 2024
68cbc6e
style: isort
Antonyjin Nov 14, 2024
070841d
fix: datetime not seriazable
Antonyjin Nov 18, 2024
5881ee1
fix: datetime not seriazable
Antonyjin Nov 18, 2024
6807106
Fix: Adaptations for Pydantic v2 migration and stricter validation
Antonyjin Nov 4, 2024
c140d59
fix: Forcing the version 2 of pydantic
Antonyjin Nov 11, 2024
37c4f81
fix: yamlfix and pydantic are incompatible
Antonyjin Nov 11, 2024
08e2d65
Fix: HttpUrl no longer need scheme value
Antonyjin Nov 12, 2024
cef0708
Refactor: update validation for Pydantic v2
Antonyjin Nov 12, 2024
fac5b92
Fix: Missing dependency in the debian Makefile
Antonyjin Nov 14, 2024
06bc7ad
fix: datetime not seriazable
Antonyjin Nov 18, 2024
2ed6a78
Merge branch 'main' into 716-updating-pydantic-version
Antonyjin Nov 19, 2024
3a3213f
Merge branch '716-updating-pydantic-version' of github.com:aleph-im/a…
Antonyjin Nov 19, 2024
c773f2d
Fix: Pydantic is more strick about validation rules
Antonyjin Nov 19, 2024
a9cf0e7
Fix: Pydantic 2 add more information in return error and style issue
Antonyjin Nov 4, 2024
0c32286
fix: Additional slash not needed in the url
Antonyjin Nov 11, 2024
c703d92
fix: Forcing the version 2 of pydantic
Antonyjin Nov 11, 2024
b8e037f
Refactor: update validation for Pydantic v2
Antonyjin Nov 12, 2024
8b79511
Fix: Missing dependency in the debian Makefile
Antonyjin Nov 14, 2024
a400233
fix: dump_wargs arg don't work the same in pydantic 2
Antonyjin Nov 14, 2024
e2ea33a
Fix: Adaptations for Pydantic v2 migration and stricter validation
Antonyjin Nov 4, 2024
d94ef5f
Fix: HttpUrl no longer need scheme value
Antonyjin Nov 12, 2024
d321d5a
Make vm_id assignment more robust (#714)
olethanh Oct 31, 2024
61ef25c
Implement new EVM chains (#717)
nesitor Nov 4, 2024
ebb37d4
Feature: allow IPv6 DNS (#455)
olethanh Nov 5, 2024
3f8b2ac
Problem: IGNORE_TRACEBACK_FROM_DIAGNOSTICS broken (#713)
olethanh Nov 6, 2024
9487639
Problem: error Too many open files (#720)
olethanh Nov 8, 2024
b88f13a
Update PULL_REQUEST_TEMPLATE.md for dependencies check (#722)
olethanh Nov 14, 2024
52e94ee
Fix: Pydantic is more strick about validation rules
Antonyjin Nov 19, 2024
1d89d30
Merge branch 'main' into 716-updating-pydantic-version
Antonyjin Nov 19, 2024
7f4e04a
Merge branch '716-updating-pydantic-version' of github.com:aleph-im/a…
Antonyjin Nov 19, 2024
0232124
Fix: Config no longer accepted in Pydantic 2
Antonyjin Nov 19, 2024
a88bcf1
style: black
Antonyjin Nov 19, 2024
90f4b27
fix: model_config is now a dict no longer a class
Antonyjin Nov 19, 2024
ad5df33
Style: black, isort and mypy
Antonyjin Nov 4, 2024
047dc04
fix: Additional slash not needed in the url
Antonyjin Nov 11, 2024
1fb8901
fix: Forcing the version 2 of pydantic
Antonyjin Nov 11, 2024
4e54444
Fix: HttpUrl no longer need scheme value
Antonyjin Nov 12, 2024
3067750
Fix: Pydantic 2 handle differently the errors
Antonyjin Nov 12, 2024
19666b9
Refactor: update validation for Pydantic v2
Antonyjin Nov 12, 2024
40d7b7e
Fix: Missing dependency in the debian Makefile
Antonyjin Nov 14, 2024
9a50916
fix: datetime not seriazable
Antonyjin Nov 18, 2024
9d0e30e
Fix: Adaptations for Pydantic v2 migration and stricter validation
Antonyjin Nov 4, 2024
330dfd6
Make vm_id assignment more robust (#714)
olethanh Oct 31, 2024
e98c2a8
Implement new EVM chains (#717)
nesitor Nov 4, 2024
e08a478
Feature: allow IPv6 DNS (#455)
olethanh Nov 5, 2024
60132a4
Problem: IGNORE_TRACEBACK_FROM_DIAGNOSTICS broken (#713)
olethanh Nov 6, 2024
5a7240c
Problem: error Too many open files (#720)
olethanh Nov 8, 2024
cb8f660
Update PULL_REQUEST_TEMPLATE.md for dependencies check (#722)
olethanh Nov 14, 2024
bf324dc
Fix: Pydantic is more strick about validation rules
Antonyjin Nov 19, 2024
7911a64
Fix: Adaptations for Pydantic v2 migration and stricter validation
Antonyjin Nov 4, 2024
950d1cd
fix: model_config is now a dict no longer a class
Antonyjin Nov 19, 2024
bf133c7
Merge branch 'main' into 716-updating-pydantic-version
Antonyjin Nov 19, 2024
4175ee2
Merge branch 'main' into 716-updating-pydantic-version
Antonyjin Nov 21, 2024
28ce743
Merge branch '716-updating-pydantic-version' of github.com:aleph-im/a…
Antonyjin Nov 21, 2024
8942722
Fix: Duplicate line in pyproject and missing type annotation
Antonyjin Nov 21, 2024
ed09137
style mypy
Antonyjin Nov 21, 2024
93678f0
style mypy
Antonyjin Nov 21, 2024
7726eea
Fix `os.makedirs` calls for optional Path variables
Antonyjin Nov 22, 2024
8064e05
fix: wrong name
Antonyjin Nov 22, 2024
f8ce889
ignore url in test_allocation_fails_on_invalid_item_hash
Antonyjin Nov 22, 2024
0ed3520
Fix: Duplicate line in pyproject and missing type annotation
Antonyjin Nov 21, 2024
cd88144
Fix `os.makedirs` calls for optional Path variables
Antonyjin Nov 22, 2024
d96e9ca
ignore url in test_allocation_fails_on_invalid_item_hash
Antonyjin Nov 22, 2024
a74b126
Merge branch 'main' into 716-updating-pydantic-version
Antonyjin Nov 29, 2024
5a5a735
merging main
Antonyjin Dec 2, 2024
5143f3d
Merge branch 'main' into 716-updating-pydantic-version
Antonyjin Dec 5, 2024
40c2f97
Merge branch 'main' into 716-updating-pydantic-version
Antonyjin Jan 21, 2025
8cc028c
Merge branch 'main' into 716-updating-pydantic-version
Antonyjin Feb 25, 2025
d5856db
Fix: parse_raw_as has been removed from pydantic2
Antonyjin Feb 25, 2025
d433e03
Style: isort
Antonyjin Feb 25, 2025
631401e
Fix: wrong version of aiohttp_cors
Antonyjin Feb 25, 2025
e3ac123
Merge branch 'main' into 716-updating-pydantic-version
Antonyjin Mar 4, 2025
8047d87
Merge branch 'main' into 716-updating-pydantic-version
Antonyjin Mar 12, 2025
072dec8
Style: mypy
Antonyjin Mar 12, 2025
8e300ed
Merge branch 'main' into 716-updating-pydantic-version
Antonyjin Mar 18, 2025
592c45f
Merge branch 'main' into 716-updating-pydantic-version
Antonyjin Mar 19, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions examples/example_fastapi/main.py
Original file line number Diff line number Diff line change
@@ -216,9 +216,9 @@ async def check_url(internet_host: HttpUrl, timeout_seconds: int = 5, socket_fam
async def read_internet():
"""Check Internet connectivity of the system, requiring IP connectivity, domain resolution and HTTPS/TLS."""
internet_hosts: list[HttpUrl] = [
HttpUrl(url="https://aleph.im/", scheme="https"),
HttpUrl(url="https://ethereum.org", scheme="https"),
HttpUrl(url="https://ipfs.io/", scheme="https"),
HttpUrl(url="https://aleph.im/"),
HttpUrl(url="https://ethereum.org/"),
HttpUrl(url="https://ipfs.io/"),
]
timeout_seconds = 5

2 changes: 1 addition & 1 deletion packaging/Makefile
Original file line number Diff line number Diff line change
@@ -19,7 +19,7 @@ debian-package-code:
python3 -m venv build_venv
build_venv/bin/pip install --progress-bar off --upgrade pip setuptools wheel
# Fixing this protobuf dependency version to avoid getting CI errors as version 5.29.0 have this compilation issue
build_venv/bin/pip install --no-cache-dir --progress-bar off --target ./aleph-vm/opt/aleph-vm/ 'aleph-message==0.6.1' 'eth-account==0.10' 'sentry-sdk==1.31.0' 'qmp==1.1.0' 'aleph-superfluid~=0.2.1' 'sqlalchemy[asyncio]>=2.0' 'aiosqlite==0.19.0' 'alembic==1.13.1' 'aiohttp_cors==0.7.0' 'pyroute2==0.7.12' 'python-cpuid==0.1.0' 'solathon==1.0.2' 'protobuf==5.28.3'
build_venv/bin/pip install --no-cache-dir --progress-bar off --target ./aleph-vm/opt/aleph-vm/ 'git+https://github.com/aleph-im/aleph-message@108-upgrade-pydantic-version#egg=aleph-message' 'eth-account==0.10' 'sentry-sdk==1.31.0' 'qmp==1.1.0' 'aleph-superfluid~=0.2.1' 'sqlalchemy[asyncio]>=2.0' 'aiosqlite==0.19.0' 'alembic==1.13.1' 'aiohttp_cors==0.7.0' 'pydantic-settings==2.6.1' 'pyroute2==0.7.12' 'python-cpuid==0.1.0' 'solathon==1.0.2' 'protobuf==5.28.3'
build_venv/bin/python3 -m compileall ./aleph-vm/opt/aleph-vm/

debian-package-resources: firecracker-bins vmlinux download-ipfs-kubo target/bin/sevctl
9 changes: 6 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -36,7 +36,7 @@ dependencies = [
"aioredis==1.3.1",
"aiosqlite==0.19",
"alembic==1.13.1",
"aleph-message==0.6.1",
"aleph-message @ git+https://github.com/aleph-im/aleph-message@108-upgrade-pydantic-version#egg=main",
"aleph-superfluid~=0.2.1",
"dbus-python==1.3.2",
"eth-account~=0.10",
@@ -49,9 +49,11 @@ dependencies = [
"protobuf==5.28.3",
"psutil==5.9.5",
"py-cpuinfo==9",
"pydantic[dotenv]~=1.10.13",
"pydantic>=2",
"pydantic-settings==2.6.1",
"pyroute2==0.7.12",
"python-cpuid==0.1.1",
"python-dotenv",
"pyyaml==6.0.1",
"qmp==1.1",
"schedule==1.2.1",
@@ -120,8 +122,9 @@ dependencies = [
"mypy==1.8.0",
"ruff==0.4.6",
"isort==5.13.2",
"yamlfix==1.16.1",
"yamlfix==1.17.0",
"pyproject-fmt==2.2.1",
"pydantic>=2",
]
[tool.hatch.envs.linting.scripts]
typing = "mypy {args:src/aleph/vm/ tests/ examples/example_fastapi runtimes/aleph-debian-12-python}"
49 changes: 30 additions & 19 deletions src/aleph/vm/conf.py
Original file line number Diff line number Diff line change
@@ -13,8 +13,9 @@

from aleph_message.models import Chain
from aleph_message.models.execution.environment import HypervisorType
from pydantic import BaseSettings, Field, HttpUrl
from pydantic.env_settings import DotenvType, env_file_sentinel
from dotenv import load_dotenv
from pydantic import Field, HttpUrl
from pydantic_settings import BaseSettings, SettingsConfigDict

from aleph.vm.orchestrator.chain import STREAM_CHAINS
from aleph.vm.utils import (
@@ -24,6 +25,8 @@
is_command_available,
)

load_dotenv()

logger = logging.getLogger(__name__)

Url = NewType("Url", str)
@@ -165,7 +168,7 @@
default=True,
description="Enable IPv6 forwarding on the host. Required for IPv6 connectivity in VMs.",
)
NFTABLES_CHAIN_PREFIX = "aleph"
NFTABLES_CHAIN_PREFIX: str = "aleph"
USE_NDP_PROXY: bool = Field(
default=True,
description="Use the Neighbor Discovery Protocol Proxy to respond to Router Solicitation for instances on IPv6",
@@ -176,16 +179,16 @@
description="Method used to resolve the dns server if DNS_NAMESERVERS is not present.",
)
DNS_NAMESERVERS: list[str] | None = None
DNS_NAMESERVERS_IPV4: list[str] | None
DNS_NAMESERVERS_IPV6: list[str] | None
DNS_NAMESERVERS_IPV4: list[str] | None = None
DNS_NAMESERVERS_IPV6: list[str] | None = None

FIRECRACKER_PATH: Path = Path("/opt/firecracker/firecracker")
JAILER_PATH: Path = Path("/opt/firecracker/jailer")
SEV_CTL_PATH: Path = Path("/opt/sevctl")
LINUX_PATH: Path = Path("/opt/firecracker/vmlinux.bin")
INIT_TIMEOUT: float = 20.0

CONNECTOR_URL = Url("http://localhost:4021")
CONNECTOR_URL: HttpUrl = HttpUrl("http://localhost:4021")

CACHE_ROOT: Path = Path("/var/cache/aleph/vm")
MESSAGE_CACHE: Optional[Path] = Field(
@@ -206,10 +209,10 @@
None, description="Location of executions log. Default to EXECUTION_ROOT/executions/"
)

PERSISTENT_VOLUMES_DIR: Path = Field(
PERSISTENT_VOLUMES_DIR: Optional[Path] = Field(
None, description="Persistent volumes location. Default to EXECUTION_ROOT/volumes/persistent/"
)
JAILER_BASE_DIR: Path = Field(None)
JAILER_BASE_DIR: Optional[Path] = Field(None)

MAX_PROGRAM_ARCHIVE_SIZE: int = 10_000_000 # 10 MB
MAX_DATA_ARCHIVE_SIZE: int = 10_000_000 # 10 MB
@@ -308,8 +311,10 @@
description="Identifier used for the 'fake instance' message defined in "
"examples/instance_message_from_aleph.json",
)
FAKE_INSTANCE_MESSAGE = Path(abspath(join(__file__, "../../../../examples/instance_message_from_aleph.json")))
FAKE_INSTANCE_QEMU_MESSAGE = Path(abspath(join(__file__, "../../../../examples/qemu_message_from_aleph.json")))
FAKE_INSTANCE_MESSAGE: Path = Path(abspath(join(__file__, "../../../../examples/instance_message_from_aleph.json")))
FAKE_INSTANCE_QEMU_MESSAGE: Path = Path(
abspath(join(__file__, "../../../../examples/qemu_message_from_aleph.json"))
)

CHECK_FASTAPI_VM_ID: str = "63faf8b5db1cf8d965e6a464a0cb8062af8e7df131729e48738342d956f29ace"
LEGACY_CHECK_FASTAPI_VM_ID: str = "67705389842a0a1b95eaa408b009741027964edc805997475e95c505d642edd8"
@@ -345,7 +350,7 @@
assert isfile(self.JAILER_PATH), f"File not found {self.JAILER_PATH}"
assert isfile(self.LINUX_PATH), f"File not found {self.LINUX_PATH}"
assert self.NETWORK_INTERFACE, "Network interface is not specified"
assert self.CONNECTOR_URL.startswith("http://") or self.CONNECTOR_URL.startswith("https://")
assert str(self.CONNECTOR_URL).startswith("http://") or str(self.CONNECTOR_URL).startswith("https://")
if self.ALLOW_VM_NETWORKING:
assert exists(
f"/sys/class/net/{self.NETWORK_INTERFACE}"
@@ -480,18 +485,25 @@
attributes[attr] = "<REDACTED>"
else:
attributes[attr] = getattr(self, attr)

return "\n".join(f"{self.Config.env_prefix}{attribute} = {value}" for attribute, value in attributes.items())
return "\n".join(

Check warning on line 488 in src/aleph/vm/conf.py

Codecov / codecov/patch

src/aleph/vm/conf.py#L488

Added line #L488 was not covered by tests
f"{self.model_config.get('env_prefix', '')}{attribute} = {value}" for attribute, value in attributes.items()
)

def __init__(
self,
_env_file: DotenvType | None = env_file_sentinel,
_env_file: str | Path | None = None,
_env_file_encoding: str | None = None,
_env_nested_delimiter: str | None = None,
_secrets_dir: Path | None = None,
**values: Any,
) -> None:
super().__init__(_env_file, _env_file_encoding, _env_nested_delimiter, _secrets_dir, **values)
super().__init__(
_env_file,
_env_file_encoding,
_env_nested_delimiter,
_secrets_dir,
**values,
)
if not self.MESSAGE_CACHE:
self.MESSAGE_CACHE = self.CACHE_ROOT / "message"
if not self.CODE_CACHE:
@@ -515,10 +527,9 @@
if not self.CONFIDENTIAL_SESSION_DIRECTORY:
self.CONFIDENTIAL_SESSION_DIRECTORY = self.EXECUTION_ROOT / "sessions"

class Config:
env_prefix = "ALEPH_VM_"
case_sensitive = False
env_file = ".env"
model_config = SettingsConfigDict(
env_prefix="ALEPH_VM_", case_sensitive=False, env_file=".env", validate_default=False
)


def make_db_url():
2 changes: 1 addition & 1 deletion src/aleph/vm/controllers/__main__.py
Original file line number Diff line number Diff line change
@@ -26,7 +26,7 @@
def configuration_from_file(path: Path):
with open(path) as f:
data = json.load(f)
return Configuration.parse_obj(data)
return Configuration.model_validate(data)


def parse_args(args):
10 changes: 5 additions & 5 deletions src/aleph/vm/controllers/configuration.py
Original file line number Diff line number Diff line change
@@ -29,26 +29,26 @@ class QemuGPU(BaseModel):

class QemuVMConfiguration(BaseModel):
qemu_bin_path: str
cloud_init_drive_path: str | None
cloud_init_drive_path: str | None = None
image_path: str
monitor_socket_path: Path
qmp_socket_path: Path
vcpu_count: int
mem_size_mb: int
interface_name: str | None
interface_name: str | None = None
host_volumes: list[QemuVMHostVolume]
gpus: list[QemuGPU]


class QemuConfidentialVMConfiguration(BaseModel):
qemu_bin_path: str
cloud_init_drive_path: str | None
cloud_init_drive_path: str | None = None
image_path: str
monitor_socket_path: Path
qmp_socket_path: Path
vcpu_count: int
mem_size_mb: int
interface_name: str | None
interface_name: str | None = None
host_volumes: list[QemuVMHostVolume]
gpus: list[QemuGPU]
ovmf_path: Path
@@ -75,7 +75,7 @@ def save_controller_configuration(vm_hash: str, configuration: Configuration) ->
config_file_path = Path(f"{settings.EXECUTION_ROOT}/{vm_hash}-controller.json")
with config_file_path.open("w") as controller_config_file:
controller_config_file.write(
configuration.json(
configuration.model_dump_json(
by_alias=True, exclude_none=True, indent=4, exclude={"settings": {"USE_DEVELOPER_SSH_KEYS"}}
)
)
2 changes: 1 addition & 1 deletion src/aleph/vm/controllers/qemu/instance.py
Original file line number Diff line number Diff line change
@@ -220,7 +220,7 @@
def save_controller_configuration(self):
"""Save VM configuration to be used by the controller service"""
path = Path(f"{settings.EXECUTION_ROOT}/{self.vm_hash}-controller.json")
path.open("w").write(self.controller_configuration.json(by_alias=True, exclude_none=True, indent=4))
path.open("w").write(self.controller_configuration.model_dump_json(by_alias=True, exclude_none=True, indent=4))

Check warning on line 223 in src/aleph/vm/controllers/qemu/instance.py

Codecov / codecov/patch

src/aleph/vm/controllers/qemu/instance.py#L223

Added line #L223 was not covered by tests
path.chmod(0o644)
return path

13 changes: 4 additions & 9 deletions src/aleph/vm/hypervisors/firecracker/config.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from pathlib import Path

from pydantic import BaseModel, PositiveInt
from pydantic import BaseModel, ConfigDict, PositiveInt

VSOCK_PATH = "/tmp/v.sock"

@@ -51,12 +51,7 @@ class FirecrackerConfig(BaseModel):
boot_source: BootSource
drives: list[Drive]
machine_config: MachineConfig
vsock: Vsock | None
network_interfaces: list[NetworkInterface] | None
vsock: Vsock | None = None
network_interfaces: list[NetworkInterface] | None = None

class Config:
allow_population_by_field_name = True

@staticmethod
def alias_generator(x: str):
return x.replace("_", "-")
model_config = ConfigDict(populate_by_name=True, alias_generator=lambda x: x.replace("_", "-"))
2 changes: 1 addition & 1 deletion src/aleph/vm/hypervisors/firecracker/microvm.py
Original file line number Diff line number Diff line change
@@ -195,7 +195,7 @@ async def save_configuration_file(self, config: FirecrackerConfig) -> Path:
if not self.use_jailer
else open(f"{self.jailer_path}/tmp/config.json", "wb")
) as config_file:
config_file.write(config.json(by_alias=True, exclude_none=True, indent=4).encode())
config_file.write(config.model_dump_json(by_alias=True, exclude_none=True, indent=4).encode())
config_file.flush()
config_file_path = Path(config_file.name)
config_file_path.chmod(0o644)
8 changes: 4 additions & 4 deletions src/aleph/vm/models.py
Original file line number Diff line number Diff line change
@@ -435,8 +435,8 @@ async def save(self):
vcpus=self.vm.hardware_resources.vcpus,
memory=self.vm.hardware_resources.memory,
network_tap=self.vm.tap_interface.device_name if self.vm.tap_interface else "",
message=self.message.json(),
original_message=self.original.json(),
message=self.message.model_dump_json(),
original_message=self.original.model_dump_json(),
persistent=self.persistent,
)
)
@@ -459,8 +459,8 @@ async def save(self):
io_write_bytes=None,
vcpus=self.vm.hardware_resources.vcpus,
memory=self.vm.hardware_resources.memory,
message=self.message.json(),
original_message=self.original.json(),
message=self.message.model_dump_json(),
original_message=self.original.model_dump_json(),
persistent=self.persistent,
gpus=json.dumps(self.gpus, default=pydantic_encoder),
)
4 changes: 2 additions & 2 deletions src/aleph/vm/orchestrator/README.md
Original file line number Diff line number Diff line change
@@ -80,12 +80,12 @@ cd aleph-vm/

### 2.e. Install Pydantic

[PyDantic](https://pydantic-docs.helpmanual.io/)
[PyDantic](https://pydantic-docs.helpmanual.io/)
is used to parse and validate Aleph messages.

```shell
apt install -y --no-install-recommends --no-install-suggests python3-pip
pip3 install pydantic[dotenv]
pip3 install pydantic-dotenv
pip3 install 'aleph-message==0.4.9'
```

15 changes: 8 additions & 7 deletions src/aleph/vm/orchestrator/chain.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import logging

from aleph_message.models import Chain
from pydantic import BaseModel, root_validator
from pydantic import BaseModel, HttpUrl, model_validator

logger = logging.getLogger(__name__)

@@ -12,7 +12,7 @@ class ChainInfo(BaseModel):
"""

chain_id: int
rpc: str
rpc: HttpUrl
standard_token: str | None = None
super_token: str | None = None
testnet: bool = False
@@ -22,7 +22,8 @@ class ChainInfo(BaseModel):
def token(self) -> str | None:
return self.super_token or self.standard_token

@root_validator(pre=True)
@model_validator(mode="before")
@classmethod
def check_tokens(cls, values):
if not values.get("standard_token") and not values.get("super_token"):
msg = "At least one of standard_token or super_token must be provided."
@@ -34,7 +35,7 @@ def check_tokens(cls, values):
# TESTNETS
"SEPOLIA": ChainInfo(
chain_id=11155111,
rpc="https://eth-sepolia.public.blastapi.io",
rpc=HttpUrl("https://eth-sepolia.public.blastapi.io"),
standard_token="0xc4bf5cbdabe595361438f8c6a187bdc330539c60",
super_token="0x22064a21fee226d8ffb8818e7627d5ff6d0fc33a",
active=False,
@@ -43,18 +44,18 @@ def check_tokens(cls, values):
# MAINNETS
Chain.ETH: ChainInfo(
chain_id=1,
rpc="https://eth-mainnet.public.blastapi.io",
rpc=HttpUrl("https://eth-mainnet.public.blastapi.io"),
standard_token="0x27702a26126e0B3702af63Ee09aC4d1A084EF628",
active=False,
),
Chain.AVAX: ChainInfo(
chain_id=43114,
rpc="https://api.avax.network/ext/bc/C/rpc",
rpc=HttpUrl("https://api.avax.network/ext/bc/C/rpc"),
super_token="0xc0Fbc4967259786C743361a5885ef49380473dCF",
),
Chain.BASE: ChainInfo(
chain_id=8453,
rpc="https://base-mainnet.public.blastapi.io",
rpc=HttpUrl("https://base-mainnet.public.blastapi.io"),
super_token="0xc0Fbc4967259786C743361a5885ef49380473dCF",
),
}
2 changes: 1 addition & 1 deletion src/aleph/vm/orchestrator/reactor.py
Original file line number Diff line number Diff line change
@@ -61,7 +61,7 @@
for subscription in listener.content.on.message:
if subscription_matches(subscription, message):
vm_hash = listener.item_hash
event = message.json()
event = message.model_dump_json()

Check warning on line 64 in src/aleph/vm/orchestrator/reactor.py

Codecov / codecov/patch

src/aleph/vm/orchestrator/reactor.py#L64

Added line #L64 was not covered by tests
# Register the listener in the list of coroutines to run asynchronously:
coroutines.append(run_code_on_event(vm_hash, event, self.pubsub, pool=self.pool))
break
2 changes: 1 addition & 1 deletion src/aleph/vm/orchestrator/resources.py
Original file line number Diff line number Diff line change
@@ -157,7 +157,7 @@ async def about_system_usage(request: web.Request):
gpu=get_machine_gpus(request),
)

return web.json_response(text=usage.json(exclude_none=True))
return web.json_response(text=usage.model_dump_json(exclude_none=True))


@cors_allow_all
Loading