-
Notifications
You must be signed in to change notification settings - Fork 18
Fix: Execution creation was not tested #558
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
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
9255803
Fix: Execution creation was not tested
hoh 5320ea6
Fix: Circular imports prevented pytest to run
hoh 7f4f351
Fix: Pytest failed due to missing files
hoh 4f7638f
Doc: Add docstring to settings.setup(), .check()
hoh 5da40c1
Fix: Assertion errors did not display missing path
hoh 5158dd4
Fix: run_guest_api mixed str and Path
hoh 11e5a5b
Fix: Missed documentation, no TESTING.md
hoh 968585b
Fix: Could not launch a VM without building it locally (#588)
Antonyjin 71d8978
Problem: hatch envs needed manual manipulation for testing
olethanh b1809e2
Fix: Missing comments in workflow
hoh 3fa8ca2
Problem: Execution test hanging. Python runtime slow
olethanh e30adef
Problem cannot import name 'async_sessionmaker' from 'sqlalchemy.ext.…
olethanh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| # Testing aleph-vm | ||
|
|
||
| This procedure describes how to run tests on a local system. | ||
|
|
||
| Tests also run on GitHub Actions via [the following workflow](./.github/workflows/test-on-droplets-matrix.yml). | ||
|
|
||
| Since these tests create block devices and manipulate network interfaces, they need to run as root. | ||
| If you are not comfortable with this, run them in a virtual machine. | ||
|
|
||
| ## 1. Clone this repository | ||
|
|
||
| ```shell | ||
| git clone https://github.com/aleph-im/aleph-vm.git | ||
| ``` | ||
|
|
||
| ## 2. Install [hatch](https://hatch.pypa.io/), the project manager | ||
|
|
||
| Since installing tools globally is not recommended, we will install `hatch` | ||
| in a dedicated virtual environment. Alternatives include using [pipx](https://pipx.pypa.io) | ||
| or your distribution. | ||
|
|
||
| ```shell | ||
| python3 -m venv /opt/venv | ||
| source /opt/venv/bin/activate | ||
|
|
||
| # Inside the venv | ||
| pip install hatch | ||
| ``` | ||
|
|
||
| ## 3. Initialize hatch for running the tests | ||
hoh marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| It is required that the testing virtual environment relies on system packages | ||
| for `nftables` instead of the package obtained from `salsa.debian.org` as defined in | ||
| [pyproject.toml](./pyproject.toml). | ||
|
|
||
| Create the testing virtual environment: | ||
| ```shell | ||
| hatch env create testing | ||
| ``` | ||
|
|
||
|
|
||
| ## 4. Run tests | ||
|
|
||
| ```shell | ||
| hatch run testing:test | ||
| ``` | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,30 +1,3 @@ | ||
| from aleph.vm.version import __version__ | ||
|
|
||
| from . import ( | ||
| messages, | ||
| metrics, | ||
| pubsub, | ||
| reactor, | ||
| resources, | ||
| run, | ||
| status, | ||
| supervisor, | ||
| tasks, | ||
| views, | ||
| vm, | ||
| ) | ||
|
|
||
| __all__ = ( | ||
| "__version__", | ||
| "messages", | ||
| "metrics", | ||
| "pubsub", | ||
| "reactor", | ||
| "resources", | ||
| "run", | ||
| "status", | ||
| "supervisor", | ||
| "tasks", | ||
| "views", | ||
| "vm", | ||
| ) | ||
| __all__ = ("__version__",) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,95 @@ | ||
| import asyncio | ||
| import logging | ||
|
|
||
| import pytest | ||
| from aleph_message.models import ItemHash | ||
|
|
||
| from aleph.vm.conf import settings | ||
| from aleph.vm.controllers.firecracker import AlephFirecrackerProgram | ||
| from aleph.vm.models import VmExecution | ||
| from aleph.vm.orchestrator import metrics | ||
| from aleph.vm.storage import get_message | ||
|
|
||
|
|
||
| @pytest.mark.asyncio | ||
| async def test_create_execution(): | ||
hoh marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| """ | ||
| Create a new VM execution and check that it starts properly. | ||
| """ | ||
|
|
||
| settings.FAKE_DATA_PROGRAM = settings.BENCHMARK_FAKE_DATA_PROGRAM | ||
| settings.ALLOW_VM_NETWORKING = False | ||
| settings.USE_JAILER = False | ||
|
|
||
| logging.basicConfig(level=logging.DEBUG) | ||
| settings.PRINT_SYSTEM_LOGS = True | ||
|
|
||
| # Ensure that the settings are correct and required files present. | ||
| settings.setup() | ||
| settings.check() | ||
|
|
||
| # The database is required for the metrics and is currently not optional. | ||
| engine = metrics.setup_engine() | ||
| await metrics.create_tables(engine) | ||
|
|
||
| vm_hash = ItemHash("cafecafecafecafecafecafecafecafecafecafecafecafecafecafecafecafe") | ||
hoh marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| message = await get_message(ref=vm_hash) | ||
|
|
||
| execution = VmExecution( | ||
| vm_hash=vm_hash, | ||
| message=message.content, | ||
| original=message.content, | ||
| snapshot_manager=None, | ||
| systemd_manager=None, | ||
| persistent=False, | ||
| ) | ||
|
|
||
| # Downloading the resources required may take some time, limit it to 10 seconds | ||
| await asyncio.wait_for(execution.prepare(), timeout=30) | ||
|
|
||
| vm = execution.create(vm_id=3, tap_interface=None) | ||
|
|
||
| # Test that the VM is created correctly. It is not started yet. | ||
| assert isinstance(vm, AlephFirecrackerProgram) | ||
| assert vm.vm_id == 3 | ||
olethanh marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| await execution.start() | ||
| await execution.stop() | ||
|
|
||
|
|
||
| @pytest.mark.asyncio | ||
| async def test_create_execution_online(): | ||
| """ | ||
| Create a new VM execution without building it locally and check that it starts properly. | ||
| """ | ||
|
|
||
| # Ensure that the settings are correct and required files present. | ||
| settings.setup() | ||
| settings.check() | ||
|
|
||
| # The database is required for the metrics and is currently not optional. | ||
| engine = metrics.setup_engine() | ||
| await metrics.create_tables(engine) | ||
|
|
||
| vm_hash = ItemHash("3fc0aa9569da840c43e7bd2033c3c580abb46b007527d6d20f2d4e98e867f7af") | ||
| message = await get_message(ref=vm_hash) | ||
|
|
||
| execution = VmExecution( | ||
| vm_hash=vm_hash, | ||
| message=message.content, | ||
| original=message.content, | ||
| snapshot_manager=None, | ||
| systemd_manager=None, | ||
| persistent=False, | ||
| ) | ||
|
|
||
| # Downloading the resources required may take some time, limit it to 10 seconds | ||
| await asyncio.wait_for(execution.prepare(), timeout=30) | ||
|
|
||
| vm = execution.create(vm_id=3, tap_interface=None) | ||
| # Test that the VM is created correctly. It is not started yet. | ||
| assert isinstance(vm, AlephFirecrackerProgram) | ||
| assert vm.vm_id == 3 | ||
|
|
||
| await execution.start() | ||
| await execution.stop() | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.