Skip to content

Commit

Permalink
Cleanup: Code quality issues reported by tooling.
Browse files Browse the repository at this point in the history
This fixes a series of small code quality issues raised by our code quality tools.
  • Loading branch information
hoh committed Sep 25, 2023
1 parent 2b418e3 commit 3e6e3ce
Show file tree
Hide file tree
Showing 13 changed files with 24 additions and 23 deletions.
4 changes: 3 additions & 1 deletion docker/run_vm_supervisor.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/bin/sh

set -euf

# Use Podman if installed, else use Docker
if hash podman 2> /dev/null
then
Expand All @@ -17,4 +19,4 @@ $DOCKER_COMMAND run -ti --rm \
-v "$(pwd)/firecracker:/opt/aleph-vm/firecracker:ro" \
--device /dev/kvm \
-p 4020:4020 \
alephim/vm-supervisor-dev $@
alephim/vm-supervisor-dev "$@"
3 changes: 3 additions & 0 deletions examples/example_http_js/src/run.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#!/bin/sh

set -euf

cd /opt/code
node /opt/code/server.js
2 changes: 1 addition & 1 deletion packaging/extract_requirements.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ export DEBIAN_FRONTEND=noninteractive

apt update
apt --yes install /opt/packaging/target/aleph-vm.deb
pip freeze > $1
pip freeze > "$1"
2 changes: 1 addition & 1 deletion runtimes/aleph-debian-11-python/init0.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ set -euf
mount -t proc proc /proc -o nosuid,noexec,nodev

log() {
echo "$(cat /proc/uptime | awk '{printf $1}')" '|S' "$@"
echo "$(awk '{print $1}' /proc/uptime)" '|S' "$@"
}
log "init0.sh is launching"

Expand Down
2 changes: 1 addition & 1 deletion runtimes/aleph-debian-11-python/init1.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
logger.debug("Imports finished")

__version__ = "2.0.0"
ASGIApplication = NewType("ASGIApplication", Any)
ASGIApplication = NewType("ASGIApplication", Any) # type: ignore


class Encoding(str, Enum):
Expand Down
2 changes: 1 addition & 1 deletion runtimes/instance-rootfs/create-debian-11-disk.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ tar xvf "$IMAGE_NAME"

# Mount first partition of Debian Image
LOOPDISK=$(losetup --find --show $IMAGE_RAW_NAME)
partx -u $LOOPDISK
partx -u "$LOOPDISK"
mount "$LOOPDISK"p1 "$MOUNT_ORIGIN_DIR"

# Fix boot partition missing
Expand Down
2 changes: 1 addition & 1 deletion runtimes/instance-rootfs/create-debian-12-disk.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ tar xvf "$IMAGE_NAME"

# Mount first partition of Debian Image
LOOPDISK=$(losetup --find --show $IMAGE_RAW_NAME)
partx -u $LOOPDISK
partx -u "$LOOPDISK"
mount "$LOOPDISK"p1 "$MOUNT_ORIGIN_DIR"

# Fix boot partition missing
Expand Down
4 changes: 2 additions & 2 deletions vm_supervisor/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ async def save_execution_data(execution_uuid: UUID, execution_data: str):

async def save_record(record: ExecutionRecord):
"""Record the resource usage in database"""
session = Session()
session = Session() # noqa: F821 undefined name 'Session'
try:
session.add(record)
session.commit()
Expand All @@ -77,7 +77,7 @@ async def save_record(record: ExecutionRecord):

async def get_execution_records() -> Iterable[ExecutionRecord]:
"""Get the execution records from the database."""
session = Session()
session = Session() # noqa: F821 undefined name 'Session'
try:
return session.query(ExecutionRecord).all()
finally:
Expand Down
1 change: 0 additions & 1 deletion vm_supervisor/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import re
import sys
from datetime import datetime
from enum import Enum
from pathlib import Path
from shutil import copy2, disk_usage, make_archive
from typing import Union
Expand Down
2 changes: 1 addition & 1 deletion vm_supervisor/views/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ async def update_allocations(request: web.Request):
for execution in pool.get_persistent_executions():
if execution.vm_hash not in allocations:
vm_type = "instance" if execution.is_instance else "persistent program"
logger.info(f"Stopping %s %s", vm_type, execution.vm_hash)
logger.info("Stopping %s %s", vm_type, execution.vm_hash)
await execution.stop()
execution.persistent = False

Expand Down
6 changes: 2 additions & 4 deletions vm_supervisor/views/operator.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import asyncio
import functools
import json
import logging
from datetime import datetime, timedelta
Expand All @@ -19,9 +20,6 @@
logger = logging.getLogger(__name__)


import functools


def is_token_still_valid(timestamp):
"""
Checks if a token has exprired based on its timestamp
Expand Down Expand Up @@ -199,7 +197,7 @@ async def operate_stop(request: web.Request):
execution.persistent = False
return web.Response(status=200, body=f"Stopped VM with ref {vm_hash}")
else:
return web.Response(status=200, body=f"Already stopped, nothing to do")
return web.Response(status=200, body="Already stopped, nothing to do")


@require_jwk_authentication
Expand Down
15 changes: 7 additions & 8 deletions vm_supervisor/vm/firecracker/executable.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,10 @@
from multiprocessing import Process, set_start_method
from os.path import exists, isfile
from pathlib import Path
from typing import Any, Dict, Generic, List, Optional, TypeVar
from typing import Dict, Generic, List, Optional, TypeVar

from aleph_message.models import ItemHash

psutil: Optional[Any]
try:
import psutil # type: ignore [no-redef]
except ImportError:
psutil = None
from aiohttp import ClientResponseError
from aleph_message.models import ItemHash
from aleph_message.models.execution.environment import MachineResources

from firecracker.config import FirecrackerConfig
Expand All @@ -31,6 +25,11 @@
from vm_supervisor.snapshots import CompressedDiskVolumeSnapshot
from vm_supervisor.storage import get_volume_path

try:
import psutil # type: ignore [no-redef]
except ImportError:
psutil = None

logger = logging.getLogger(__name__)
set_start_method("spawn")

Expand Down
2 changes: 1 addition & 1 deletion vm_supervisor/vm/firecracker/program.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def read_input_data(path_to_data: Optional[Path]) -> Optional[bytes]:
return None

if os.path.getsize(path_to_data) > settings.MAX_DATA_ARCHIVE_SIZE:
raise FileTooLargeError(f"Data file too large to pass as an inline zip")
raise FileTooLargeError("Data file too large to pass as an inline zip")

return path_to_data.read_bytes()

Expand Down

0 comments on commit 3e6e3ce

Please sign in to comment.