From 61ccb506d6836e8efa5513376b4782439e25558d Mon Sep 17 00:00:00 2001 From: Olivier Desenfans Date: Mon, 12 Jun 2023 14:09:31 +0200 Subject: [PATCH] Fix: remove cloud-init support and add authorized keys Adaptations to the latest update of aleph-message. --- .../versions/0017_f9fa39b6bdef_vm_instances.py | 6 +++--- setup.cfg | 2 +- src/aleph/db/models/vms.py | 4 ++-- src/aleph/handlers/content/vm.py | 2 +- tests/message_processing/test_process_instances.py | 13 ++++++++++--- 5 files changed, 17 insertions(+), 10 deletions(-) diff --git a/deployment/migrations/versions/0017_f9fa39b6bdef_vm_instances.py b/deployment/migrations/versions/0017_f9fa39b6bdef_vm_instances.py index be5021046..2e7f54ece 100644 --- a/deployment/migrations/versions/0017_f9fa39b6bdef_vm_instances.py +++ b/deployment/migrations/versions/0017_f9fa39b6bdef_vm_instances.py @@ -209,11 +209,11 @@ def upgrade() -> None: sa.Column("parent_use_latest", sa.Boolean(), nullable=True), ) - # Add the instance columns to the vms (ex programs) table + # Add new columns to the vms (ex programs) table op.add_column( "vms", sa.Column( - "cloud_config", postgresql.JSONB(astext_type=sa.Text()), nullable=True + "authorized_keys", postgresql.JSONB(astext_type=sa.Text()), nullable=True ), ) op.add_column("vms", sa.Column("program_type", sa.String(), nullable=True)) @@ -397,7 +397,7 @@ def downgrade() -> None: op.execute("ALTER INDEX ix_vms_owner RENAME TO ix_programs_owner") op.drop_column("programs", "program_type") - op.drop_column("programs", "cloud_config") + op.drop_column('programs', 'authorized_keys') # Drop the parent column for persistent VMs op.drop_column("program_machine_volumes", "parent") diff --git a/setup.cfg b/setup.cfg index 69ad96c17..1b1a10779 100644 --- a/setup.cfg +++ b/setup.cfg @@ -40,7 +40,7 @@ install_requires = aiohttp==3.8.4 aioipfs@git+https://github.com/aleph-im/aioipfs.git@d671c79b2871bb4d6c8877ba1e7f3ffbe7d20b71 alembic==1.8.1 - aleph-message==0.4.0a1 + aleph-message@git+https://github.com/aleph-im/aleph-message.git@34016aea9d097b21993ad00be3f81cb1d9c738e8 aleph-p2p-client@git+https://github.com/aleph-im/p2p-service-client-python@2c04af39c566217f629fd89505ffc3270fba8676 aleph-pytezos@git+https://github.com/aleph-im/aleph-pytezos.git@32dd1749a4773da494275709060632cbeba9a51b asyncpg==0.26.0 diff --git a/src/aleph/db/models/vms.py b/src/aleph/db/models/vms.py index 0c054409a..eec7d4b11 100644 --- a/src/aleph/db/models/vms.py +++ b/src/aleph/db/models/vms.py @@ -146,6 +146,8 @@ class VmBaseDb(Base): replaces: Optional[str] = Column(ForeignKey(item_hash), nullable=True) created: dt.datetime = Column(TIMESTAMP(timezone=True), nullable=False) + authorized_keys: Optional[List[str]] = Column(JSONB, nullable=True) + __mapper_args__: Dict[str, Any] = { "polymorphic_on": type, } @@ -160,8 +162,6 @@ class VmInstanceDb(VmBaseDb): "polymorphic_identity": VmType.INSTANCE.value, } - cloud_config: Dict[str, Any] = Column(JSONB, nullable=True) - rootfs: RootfsVolumeDb = relationship( "RootfsVolumeDb", back_populates="instance", uselist=False ) diff --git a/src/aleph/handlers/content/vm.py b/src/aleph/handlers/content/vm.py index ef6372cd7..84fb4d4d9 100644 --- a/src/aleph/handlers/content/vm.py +++ b/src/aleph/handlers/content/vm.py @@ -196,7 +196,7 @@ def vm_message_to_db(message: MessageDb) -> VmBaseDb: size_mib=content.rootfs.size_mib, persistence=content.rootfs.persistence, ) - vm.cloud_config = content.cloud_config + vm.authorized_keys = content.authorized_keys else: raise TypeError(f"Unexpected VM message content type: {type(content)}") diff --git a/tests/message_processing/test_process_instances.py b/tests/message_processing/test_process_instances.py index 9c68bcb6c..3d4d1148d 100644 --- a/tests/message_processing/test_process_instances.py +++ b/tests/message_processing/test_process_instances.py @@ -64,7 +64,10 @@ def fixture_instance_message(session_factory: DbSessionFactory) -> PendingMessag "name": "test-rootfs", "size_mib": 20000, }, - "cloud_config": {"password": "password"}, + "authorized_keys": [ + "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIGULT6A41Msmw2KEu0R9MvUjhuWNAsbdeZ0DOwYbt4Qt user@example", + "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIH0jqdc5dmt75QhTrWqeHDV9xN8vxbgFyOYs2fuQl7CI", + ], "volumes": [ { "comment": "Python libraries. Read-only since a 'ref' is specified.", @@ -273,8 +276,12 @@ async def test_process_instance( rootfs = instance.rootfs assert rootfs.parent_ref == content_dict["rootfs"]["parent"]["ref"] - assert rootfs.parent_use_latest == content_dict["rootfs"]["parent"]["use_latest"] - assert rootfs.parent_use_latest == content_dict["rootfs"]["parent"]["use_latest"] + assert ( + rootfs.parent_use_latest == content_dict["rootfs"]["parent"]["use_latest"] + ) + assert ( + rootfs.parent_use_latest == content_dict["rootfs"]["parent"]["use_latest"] + ) assert rootfs.size_mib == content_dict["rootfs"]["size_mib"] assert rootfs.persistence == content_dict["rootfs"]["persistence"]