diff --git a/deployment/edge/ansible/README.md b/deployment/edge/ansible/README.md index 3d6ab25c..1d21c71a 100644 --- a/deployment/edge/ansible/README.md +++ b/deployment/edge/ansible/README.md @@ -4,13 +4,27 @@ export LOCAL_VIO_DIR= ``` -### Install sshpass -https://stackoverflow.com/questions/42835626/ansible-to-use-the-ssh-connection-type-with-passwords-you-must-install-the-s +### Install sshpass and the requirements +On MacOS, you can install sshpass using brew: +```bash +brew install sshpass ``` + +Then install requirements: +```bash pip install -r requirements.txt ``` +### Find the IP of the edge + +Under Ubuntu, you can use the following command to find the IP of the edge +```bash +ip a | grep -A 2 'wlx' | grep 'inet ' | awk '{print $2}' | cut -d/ -f1 +``` + +Then change the IP addresses on the inventory file + ## docker-compose devices We are adding those devices to be able to trigger capture from 2 cameras connected on the usb port of your edge. diff --git a/deployment/edge/ansible/files/docker-compose.template.yml b/deployment/edge/ansible/files/docker-compose.template.yml index f8465511..f4c7dd02 100644 --- a/deployment/edge/ansible/files/docker-compose.template.yml +++ b/deployment/edge/ansible/files/docker-compose.template.yml @@ -1,5 +1,3 @@ -version: '3' - services: edge_model_serving: container_name: edge_model_serving diff --git a/deployment/edge/gcp/README.md b/deployment/edge/gcp/README.md index 197d6521..2c30439d 100644 --- a/deployment/edge/gcp/README.md +++ b/deployment/edge/gcp/README.md @@ -1,3 +1,21 @@ +## Launch edge locally and upload data on GCP + +### Service account for edge_orchestrator +- Create a service account with the roles/storage.admin directly through the GCP UI. +- Export key json file +- Store the key file at this location: `edge_orchestrator/config/secrets/credentials.json` + +### Set env variables on docker-compose.yml + + API_CONFIG: upload-gcp + GOOGLE_APPLICATION_CREDENTIALS: /edge_orchestrator/config/secrets/credentials.json + GCP_BUCKET_NAME: + +### Launch VIO +```shell +$ make vio-edge-up: +``` + ## Deploy edge on GCP via Kube Ensure that Terraform has ran before to create the infrastructure. diff --git a/docker-compose.raspberrypi.yml b/docker-compose.raspberrypi.yml index f4276e10..2e40584c 100644 --- a/docker-compose.raspberrypi.yml +++ b/docker-compose.raspberrypi.yml @@ -1,5 +1,3 @@ -version: '3' - services: edge_db: image: webhippie/mongodb:latest-arm32v7 diff --git a/docker-compose.yml b/docker-compose.yml index 33b0002c..3a043959 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,5 +1,3 @@ -version: '3' - services: edge_db: image: mongo:5.0.2 diff --git a/edge_model_serving/tflite_serving/Dockerfile b/edge_model_serving/tflite_serving/Dockerfile index f66fd61d..64db928a 100644 --- a/edge_model_serving/tflite_serving/Dockerfile +++ b/edge_model_serving/tflite_serving/Dockerfile @@ -1,4 +1,4 @@ -FROM python:3.8.10-slim +FROM python:3.8-slim WORKDIR /tflite_serving diff --git a/edge_model_serving/tflite_serving/Dockerfile.raspberrypi b/edge_model_serving/tflite_serving/Dockerfile.raspberrypi index 48a25bd8..b2c80771 100644 --- a/edge_model_serving/tflite_serving/Dockerfile.raspberrypi +++ b/edge_model_serving/tflite_serving/Dockerfile.raspberrypi @@ -1,4 +1,4 @@ -FROM --platform=linux/arm64 arm64v8/python:3.8.10 +FROM --platform=linux/arm64 arm64v8/python:3.8 WORKDIR /tflite_serving diff --git a/edge_orchestrator/.env.template b/edge_orchestrator/.env.template index 2d654ed7..8ff5bb99 100644 --- a/edge_orchestrator/.env.template +++ b/edge_orchestrator/.env.template @@ -1,2 +1,8 @@ -REGISTRY_USERNAME = -REGISTRY_PASSWORD = \ No newline at end of file +EDGE_NAME= +API_CONFIG= +SERVING_MODEL_URL= +GOOGLE_APPLICATION_CREDENTIALS= +GCP_BUCKET_NAME= +ACTIVE_CONFIG_NAME= +REGISTRY_USERNAME= +REGISTRY_PASSWORD= diff --git a/edge_orchestrator/.python-version b/edge_orchestrator/.python-version index d20cc2bf..98fccd6d 100644 --- a/edge_orchestrator/.python-version +++ b/edge_orchestrator/.python-version @@ -1 +1 @@ -3.8.10 +3.8 \ No newline at end of file diff --git a/edge_orchestrator/Dockerfile b/edge_orchestrator/Dockerfile index 7f8028ba..28a933ed 100644 --- a/edge_orchestrator/Dockerfile +++ b/edge_orchestrator/Dockerfile @@ -1,4 +1,4 @@ -FROM python:3.8.16-slim +FROM python:3.8-slim WORKDIR /edge_orchestrator diff --git a/edge_orchestrator/Dockerfile.raspberrypi b/edge_orchestrator/Dockerfile.raspberrypi index df18ce3d..848b5f8a 100644 --- a/edge_orchestrator/Dockerfile.raspberrypi +++ b/edge_orchestrator/Dockerfile.raspberrypi @@ -1,4 +1,4 @@ -FROM --platform=linux/arm64 arm64v8/python:3.8.16 +FROM --platform=linux/arm64 arm64v8/python:3.8 #FROM --platform=linux/arm/v7 arm32v7/python:3.9.16-bullseye WORKDIR /edge_orchestrator diff --git a/edge_orchestrator/README.md b/edge_orchestrator/README.md index e46d9784..90148bc9 100644 --- a/edge_orchestrator/README.md +++ b/edge_orchestrator/README.md @@ -7,3 +7,21 @@ The edge_orchestrator orchestrates the following steps as soon as it is triggere 3. metadata backup 4. model inference on images 5. saving results + + +## Common errors + +# Error: pg_config executable not found. + +Check if pg_config is installed on your system. + +```bash +pg_config --version +``` + +If not, install it using the following command: + +MacOS: +```bash +brew install postgresql +``` diff --git a/edge_orchestrator/config/inventory.json b/edge_orchestrator/config/inventory.json index 389de19b..f2b3a0cf 100644 --- a/edge_orchestrator/config/inventory.json +++ b/edge_orchestrator/config/inventory.json @@ -86,4 +86,4 @@ "min_threshold_ok_ratio_rule", "min_threshold_ko_rule" ] -} +} \ No newline at end of file diff --git a/edge_orchestrator/edge_orchestrator/api_config.py b/edge_orchestrator/edge_orchestrator/api_config.py index 08f0bd0a..9089ea1c 100644 --- a/edge_orchestrator/edge_orchestrator/api_config.py +++ b/edge_orchestrator/edge_orchestrator/api_config.py @@ -1,9 +1,12 @@ import os +from dotenv import load_dotenv + from edge_orchestrator import logger def load_config(): + load_dotenv() configuration = os.environ.get("API_CONFIG", "default") logger.info(f"App running with configuration: {configuration}") diff --git a/edge_orchestrator/edge_orchestrator/application/trigger_routes.py b/edge_orchestrator/edge_orchestrator/application/trigger_routes.py index 2a29dc32..d634aa55 100644 --- a/edge_orchestrator/edge_orchestrator/application/trigger_routes.py +++ b/edge_orchestrator/edge_orchestrator/application/trigger_routes.py @@ -45,8 +45,17 @@ async def upload_job( station_config: StationConfig = Depends(get_station_config), background_tasks: BackgroundTasks = None, ): - item = Item.from_nothing() - contents = image.file.read() - item.binaries = {"0": contents} - background_tasks.add_task(uploader.upload, item, station_config.active_config["name"]) - return {"item_id": item.id} + if station_config.active_config is None: + return JSONResponse( + status_code=403, + content={ + "message": "No active configuration selected! " + "Set the active station configuration before triggering the inspection." + }, + ) + else: + item = Item.from_nothing() + contents = image.file.read() + item.binaries = {"0": contents} + background_tasks.add_task(uploader.upload, item, station_config.active_config["name"]) + return {"item_id": item.id} diff --git a/edge_orchestrator/edge_orchestrator/domain/use_cases/supervisor.py b/edge_orchestrator/edge_orchestrator/domain/use_cases/supervisor.py index 269280fd..d8c94d43 100644 --- a/edge_orchestrator/edge_orchestrator/domain/use_cases/supervisor.py +++ b/edge_orchestrator/edge_orchestrator/domain/use_cases/supervisor.py @@ -5,7 +5,6 @@ from pathlib import Path from typing import Any, Dict, List, Union -from codecarbon import track_emissions from PIL import Image from edge_orchestrator.api_config import ( @@ -59,9 +58,6 @@ def __init__( self.edge_station = edge_station self.telemetry_sink = telemetry_sink - @track_emissions( - project_name="save_item_metadata", measure_power_secs=1, log_level="info", output_dir=str(emissions_path) - ) def save_item_metadata(self, fct): @functools.wraps(fct) async def wrapper(item: Item, *args): @@ -80,7 +76,6 @@ async def inspect(self, item: Item): tasks = OrderedDict() @self.save_item_metadata - @track_emissions(project_name="capture", measure_power_secs=1, log_level="info", output_dir=str(emissions_path)) async def capture(item: Item): if item.binaries is None or len(item.binaries) == 0: cameras_metadata, binaries = self.edge_station.capture() @@ -89,23 +84,14 @@ async def capture(item: Item): check_capture_according_to_config(item, self.station_config.get_cameras()) @self.save_item_metadata - @track_emissions( - project_name="save_item_binaries", measure_power_secs=1, log_level="info", output_dir=str(emissions_path) - ) async def save_item_binaries(item: Item): self.binary_storage.save_item_binaries(item, self.station_config.active_config["name"]) @self.save_item_metadata - @track_emissions( - project_name="set_inferences", measure_power_secs=1, log_level="info", output_dir=str(emissions_path) - ) async def set_inferences(item: Item): item.inferences = await self.get_predictions(item) @self.save_item_metadata - @track_emissions( - project_name="set_decision", measure_power_secs=1, log_level="info", output_dir=str(emissions_path) - ) async def set_decision(item: Item): decision = self.apply_business_rules(item) item.decision = decision.value diff --git a/edge_orchestrator/edge_orchestrator/domain/use_cases/uploader.py b/edge_orchestrator/edge_orchestrator/domain/use_cases/uploader.py index f2cef1fa..28122ffc 100644 --- a/edge_orchestrator/edge_orchestrator/domain/use_cases/uploader.py +++ b/edge_orchestrator/edge_orchestrator/domain/use_cases/uploader.py @@ -29,7 +29,8 @@ def save_item_metadata(self, fct): async def wrapper(item: Item, *args): item.state = args[0].value await fct(item) - self.metadata_storage.save_item_metadata(item) + active_config_name = args[1] + self.metadata_storage.save_item_metadata(item, active_config_name) return wrapper @@ -50,7 +51,7 @@ async def set_error_state(item: Item, error_message: str): logger.info(f"Starting {uploader_state.value}") try: logger.info(f"Entering try {uploader_state.value}") - await task_fct(item, uploader_state) + await task_fct(item, uploader_state, active_config_name) except Exception as e: logger.error(f"Error during {uploader_state.value}: {e}") await set_error_state(item, str(e)) @@ -58,4 +59,4 @@ async def set_error_state(item: Item, error_message: str): logger.info(f"End of {uploader_state.value}") item.state = UploaderState.DONE.value - self.metadata_storage.save_item_metadata(item) + self.metadata_storage.save_item_metadata(item, active_config_name) diff --git a/edge_orchestrator/edge_orchestrator/environment/upload_with_gcp_bucket.py b/edge_orchestrator/edge_orchestrator/environment/upload_with_gcp_bucket.py index b352a0b2..0118c1db 100644 --- a/edge_orchestrator/edge_orchestrator/environment/upload_with_gcp_bucket.py +++ b/edge_orchestrator/edge_orchestrator/environment/upload_with_gcp_bucket.py @@ -24,8 +24,12 @@ class UploadWithGCPBucket(Config): SERVING_MODEL_URL = os.environ.get("SERVING_MODEL_URL", "http://edge_model_serving:8501") def __init__(self): - self.metadata_storage = GCPMetadataStorage() - self.binary_storage = GCPBinaryStorage() + prefix = os.getenv("EDGE_NAME") + if prefix is None: + raise Exception("EDGE_NAME environment variable should be set") + + self.metadata_storage = GCPMetadataStorage(prefix) + self.binary_storage = GCPBinaryStorage(prefix) self.inventory = JsonInventory(self.ROOT_PATH / "config" / "inventory.json") self.station_config = JsonStationConfig( self.ROOT_PATH / "config" / "station_configs", diff --git a/edge_orchestrator/edge_orchestrator/infrastructure/binary_storage/gcp_binary_storage.py b/edge_orchestrator/edge_orchestrator/infrastructure/binary_storage/gcp_binary_storage.py index da742cc2..ac19e5df 100644 --- a/edge_orchestrator/edge_orchestrator/infrastructure/binary_storage/gcp_binary_storage.py +++ b/edge_orchestrator/edge_orchestrator/infrastructure/binary_storage/gcp_binary_storage.py @@ -8,9 +8,10 @@ class GCPBinaryStorage(BinaryStorage): - def __init__(self): + def __init__(self, prefix: str): self.storage_client = storage.Client() - self.prefix = os.environ.get("EDGE_NAME", "") + + self.prefix = prefix self.bucket = self.storage_client.get_bucket(os.getenv("GCP_BUCKET_NAME")) def save_item_binaries(self, item: Item, active_config_name: str) -> None: diff --git a/edge_orchestrator/edge_orchestrator/infrastructure/metadata_storage/gcp_metadata_storage.py b/edge_orchestrator/edge_orchestrator/infrastructure/metadata_storage/gcp_metadata_storage.py index bb3e9a9a..0342cc82 100644 --- a/edge_orchestrator/edge_orchestrator/infrastructure/metadata_storage/gcp_metadata_storage.py +++ b/edge_orchestrator/edge_orchestrator/infrastructure/metadata_storage/gcp_metadata_storage.py @@ -9,9 +9,10 @@ class GCPMetadataStorage(MetadataStorage): - def __init__(self): + def __init__(self, prefix: str): self.storage_client = storage.Client() - self.prefix = os.environ.get("EDGE_NAME", "") + + self.prefix = prefix self.bucket = self.storage_client.get_bucket(os.getenv("GCP_BUCKET_NAME")) def save_item_metadata(self, item: Item, active_config_name: str): diff --git a/edge_orchestrator/edge_orchestrator/infrastructure/model_forward/tf_serving_classification_wrapper.py b/edge_orchestrator/edge_orchestrator/infrastructure/model_forward/tf_serving_classification_wrapper.py index b5ed7e50..c6902c3c 100644 --- a/edge_orchestrator/edge_orchestrator/infrastructure/model_forward/tf_serving_classification_wrapper.py +++ b/edge_orchestrator/edge_orchestrator/infrastructure/model_forward/tf_serving_classification_wrapper.py @@ -45,9 +45,17 @@ def perform_pre_processing(self, model: ModelInfos, binary: bytes): def perform_post_processing(self, model: ModelInfos, json_outputs: list, binary_name: str) -> dict: logger.debug(f"model classnames: {model.class_names}") + predictions = json_outputs[0] + number_predictions_classes = len(predictions) + number_model_classes = len(model.class_names) + if number_predictions_classes != number_model_classes: + logger.warning( + f"Number of classes in the model ({number_model_classes}) is different from" + "the number of predictions ({number_predictions_classes})" + ) return { binary_name: { - "label": model.class_names[np.argmax(json_outputs[0])], - "probability": float(np.max(json_outputs[0])), + "label": model.class_names[np.argmax(predictions)], + "probability": float(np.max(predictions)), } } diff --git a/edge_orchestrator/edge_orchestrator/infrastructure/station_config/json_station_config.py b/edge_orchestrator/edge_orchestrator/infrastructure/station_config/json_station_config.py index 9f5e9883..7538219e 100644 --- a/edge_orchestrator/edge_orchestrator/infrastructure/station_config/json_station_config.py +++ b/edge_orchestrator/edge_orchestrator/infrastructure/station_config/json_station_config.py @@ -28,7 +28,7 @@ def __init__(self, station_configs_folder: Path, inventory: Inventory, data_fold self.load() self.active_config = None - config_name = os.environ.get("ACTIVE_CONFIG_NAME", None) + config_name = os.getenv("ACTIVE_CONFIG_NAME") if config_name is not None: self.set_station_config(config_name) diff --git a/edge_orchestrator/pyproject.toml b/edge_orchestrator/pyproject.toml index c53ed10e..c8a45d11 100644 --- a/edge_orchestrator/pyproject.toml +++ b/edge_orchestrator/pyproject.toml @@ -23,8 +23,7 @@ classifiers = [ dependencies = [ "aiohttp==3.8.3", "azure-iot-device==2.12.0", - "codecarbon==2.4.2", - "fastapi[all]==0.100.0", + "fastapi[all]==0.115.6", "numpy==1.24.1", "Pillow==9.3.0", "psycopg2-binary==2.9.5", diff --git a/edge_orchestrator/tests/conftest.py b/edge_orchestrator/tests/conftest.py index b1a0298d..a4645f16 100644 --- a/edge_orchestrator/tests/conftest.py +++ b/edge_orchestrator/tests/conftest.py @@ -26,3 +26,4 @@ "host_volume_path_suffix": "edge_model_serving", } EDGE_TFLITE_SERVING_IMG = "ghcr.io/octo-technology/vio/edge_tflite_serving:main" +EDGE_NAME = "edge_test" diff --git a/edge_orchestrator/tests/data/test_config/item_0/camera_id1.jpg b/edge_orchestrator/tests/data/edge_test/test_config/item_0/camera_id1.jpg similarity index 100% rename from edge_orchestrator/tests/data/test_config/item_0/camera_id1.jpg rename to edge_orchestrator/tests/data/edge_test/test_config/item_0/camera_id1.jpg diff --git a/edge_orchestrator/tests/data/test_config/item_0/camera_id2.jpg b/edge_orchestrator/tests/data/edge_test/test_config/item_0/camera_id2.jpg similarity index 100% rename from edge_orchestrator/tests/data/test_config/item_0/camera_id2.jpg rename to edge_orchestrator/tests/data/edge_test/test_config/item_0/camera_id2.jpg diff --git a/edge_orchestrator/tests/data/test_config/item_0/cameras.json b/edge_orchestrator/tests/data/edge_test/test_config/item_0/cameras.json similarity index 100% rename from edge_orchestrator/tests/data/test_config/item_0/cameras.json rename to edge_orchestrator/tests/data/edge_test/test_config/item_0/cameras.json diff --git a/edge_orchestrator/tests/data/test_config/item_0/inputs.json b/edge_orchestrator/tests/data/edge_test/test_config/item_0/inputs.json similarity index 100% rename from edge_orchestrator/tests/data/test_config/item_0/inputs.json rename to edge_orchestrator/tests/data/edge_test/test_config/item_0/inputs.json diff --git a/edge_orchestrator/tests/data/test_config/item_1/camera_id1.jpg b/edge_orchestrator/tests/data/edge_test/test_config/item_1/camera_id1.jpg similarity index 100% rename from edge_orchestrator/tests/data/test_config/item_1/camera_id1.jpg rename to edge_orchestrator/tests/data/edge_test/test_config/item_1/camera_id1.jpg diff --git a/edge_orchestrator/tests/data/test_config/item_1/cameras.json b/edge_orchestrator/tests/data/edge_test/test_config/item_1/cameras.json similarity index 100% rename from edge_orchestrator/tests/data/test_config/item_1/cameras.json rename to edge_orchestrator/tests/data/edge_test/test_config/item_1/cameras.json diff --git a/edge_orchestrator/tests/data/test_config/item_1/inputs.json b/edge_orchestrator/tests/data/edge_test/test_config/item_1/inputs.json similarity index 100% rename from edge_orchestrator/tests/data/test_config/item_1/inputs.json rename to edge_orchestrator/tests/data/edge_test/test_config/item_1/inputs.json diff --git a/edge_orchestrator/tests/data/test_config/item_2/camera_id1.jpg b/edge_orchestrator/tests/data/edge_test/test_config/item_2/camera_id1.jpg similarity index 100% rename from edge_orchestrator/tests/data/test_config/item_2/camera_id1.jpg rename to edge_orchestrator/tests/data/edge_test/test_config/item_2/camera_id1.jpg diff --git a/edge_orchestrator/tests/data/test_config/item_2/camera_id2.jpg b/edge_orchestrator/tests/data/edge_test/test_config/item_2/camera_id2.jpg similarity index 100% rename from edge_orchestrator/tests/data/test_config/item_2/camera_id2.jpg rename to edge_orchestrator/tests/data/edge_test/test_config/item_2/camera_id2.jpg diff --git a/edge_orchestrator/tests/data/test_config/item_2/cameras.json b/edge_orchestrator/tests/data/edge_test/test_config/item_2/cameras.json similarity index 100% rename from edge_orchestrator/tests/data/test_config/item_2/cameras.json rename to edge_orchestrator/tests/data/edge_test/test_config/item_2/cameras.json diff --git a/edge_orchestrator/tests/data/test_config/item_2/inputs.json b/edge_orchestrator/tests/data/edge_test/test_config/item_2/inputs.json similarity index 100% rename from edge_orchestrator/tests/data/test_config/item_2/inputs.json rename to edge_orchestrator/tests/data/edge_test/test_config/item_2/inputs.json diff --git a/edge_orchestrator/tests/fixtures/binaries.py b/edge_orchestrator/tests/fixtures/binaries.py index 40e6d2bf..ae42c2ab 100644 --- a/edge_orchestrator/tests/fixtures/binaries.py +++ b/edge_orchestrator/tests/fixtures/binaries.py @@ -1,12 +1,12 @@ from _pytest.fixtures import fixture -from tests.conftest import TEST_DATA_FOLDER_PATH +from tests.conftest import EDGE_NAME, TEST_DATA_FOLDER_PATH @fixture(scope="function") def my_binaries_0(): - with (TEST_DATA_FOLDER_PATH / "test_config" / "item_0" / "camera_id1.jpg").open("br") as f1, ( - TEST_DATA_FOLDER_PATH / "test_config" / "item_0" / "camera_id2.jpg" + with (TEST_DATA_FOLDER_PATH / EDGE_NAME / "test_config" / "item_0" / "camera_id1.jpg").open("br") as f1, ( + TEST_DATA_FOLDER_PATH / EDGE_NAME / "test_config" / "item_0" / "camera_id2.jpg" ).open("br") as f2: picture_1 = f1.read() picture_2 = f2.read() @@ -15,7 +15,7 @@ def my_binaries_0(): @fixture(scope="function") def my_binaries_1(): - with (TEST_DATA_FOLDER_PATH / "test_config" / "item_1" / "camera_id1.jpg").open("br") as f: + with (TEST_DATA_FOLDER_PATH / EDGE_NAME / "test_config" / "item_1" / "camera_id1.jpg").open("br") as f: picture = f.read() return { "camera_id1": picture, @@ -27,8 +27,8 @@ def my_binaries_1(): @fixture(scope="function") def my_binaries_2(): - with (TEST_DATA_FOLDER_PATH / "test_config" / "item_2" / "camera_id1.jpg").open("br") as f1, ( - TEST_DATA_FOLDER_PATH / "test_config" / "item_2" / "camera_id2.jpg" + with (TEST_DATA_FOLDER_PATH / EDGE_NAME / "test_config" / "item_2" / "camera_id1.jpg").open("br") as f1, ( + TEST_DATA_FOLDER_PATH / EDGE_NAME / "test_config" / "item_2" / "camera_id2.jpg" ).open("br") as f2: picture_2 = f1.read() picture_3 = f2.read() diff --git a/edge_orchestrator/tests/integration_tests/application/test_server.py b/edge_orchestrator/tests/integration_tests/application/test_server.py index 32137adc..c48dcd2a 100644 --- a/edge_orchestrator/tests/integration_tests/application/test_server.py +++ b/edge_orchestrator/tests/integration_tests/application/test_server.py @@ -4,7 +4,7 @@ from edge_orchestrator.api_config import get_metadata_storage from edge_orchestrator.application.server import server -from tests.conftest import TEST_DATA_FOLDER_PATH +from tests.conftest import EDGE_NAME, TEST_DATA_FOLDER_PATH class TestServer: @@ -12,7 +12,7 @@ def test_upload_route__should_return_expected_logs_when_received_paylod_with_bin # Given client = TestClient(server()) test_file = "camera_id1.jpg" - test_file_path = TEST_DATA_FOLDER_PATH / "test_config" / "item_2" / test_file + test_file_path = TEST_DATA_FOLDER_PATH / EDGE_NAME / "test_config" / "item_2" / test_file expected_logs = [ "Starting Save Binaries", "Entering try Save Binaries", diff --git a/edge_orchestrator/tests/unit_tests/infrastructure/binary_storage/test_gcp_binary_storage.py b/edge_orchestrator/tests/unit_tests/infrastructure/binary_storage/test_gcp_binary_storage.py index 4d7b1b1c..1700cb4d 100644 --- a/edge_orchestrator/tests/unit_tests/infrastructure/binary_storage/test_gcp_binary_storage.py +++ b/edge_orchestrator/tests/unit_tests/infrastructure/binary_storage/test_gcp_binary_storage.py @@ -4,7 +4,7 @@ from edge_orchestrator.infrastructure.binary_storage.gcp_binary_storage import ( GCPBinaryStorage, ) -from tests.conftest import TEST_DATA_FOLDER_PATH +from tests.conftest import EDGE_NAME, TEST_DATA_FOLDER_PATH class TestGCPBinaryStorage: @@ -13,21 +13,23 @@ def test_save_item_binaries_should_write_image_in_gcp(self, mock_storage): # Given test_active_config_name = "test_config" test_camera_id = "1" - test_file_path = TEST_DATA_FOLDER_PATH / test_active_config_name / "item_2" / "camera_id1.jpg" + test_file_path = TEST_DATA_FOLDER_PATH / EDGE_NAME / test_active_config_name / "item_2" / "camera_id1.jpg" item = Item.from_nothing() with open(test_file_path, "rb") as f: item.binaries = {test_camera_id: f} mock_gcs_client = mock_storage.Client.return_value mock_bucket = Mock() mock_gcs_client.get_bucket.return_value = mock_bucket - gcs = GCPBinaryStorage() + gcs = GCPBinaryStorage(prefix=EDGE_NAME) # When gcs.save_item_binaries(item, test_active_config_name) # Then mock_storage.Client.assert_called_once() - mock_bucket.blob.assert_called_once_with(f"{test_active_config_name}/{item.id}/{test_camera_id}.jpg") + mock_bucket.blob.assert_called_once_with( + f"{EDGE_NAME}/{test_active_config_name}/{item.id}/{test_camera_id}.jpg" + ) mock_bucket.blob.return_value.upload_from_string.assert_called_once_with(f, content_type="image/jpg") @patch("edge_orchestrator.infrastructure.binary_storage.gcp_binary_storage.storage") @@ -35,14 +37,14 @@ def test_get_item_binary_should_return_image(self, mock_storage): # Given test_active_config_name = "test_config" test_camera_id = "1" - test_file_path = TEST_DATA_FOLDER_PATH / test_active_config_name / "item_2" / "camera_id1.jpg" + test_file_path = TEST_DATA_FOLDER_PATH / EDGE_NAME / test_active_config_name / "item_2" / "camera_id1.jpg" item = Item.from_nothing() with open(test_file_path, "rb") as f: item.binaries = {test_camera_id: f} mock_gcs_client = mock_storage.Client.return_value mock_bucket = Mock() mock_gcs_client.get_bucket.return_value = mock_bucket - gcs = GCPBinaryStorage() + gcs = GCPBinaryStorage(prefix=EDGE_NAME) gcs.save_item_binaries(item, test_active_config_name) # When @@ -50,4 +52,6 @@ def test_get_item_binary_should_return_image(self, mock_storage): # Then mock_storage.Client.assert_called_once() - mock_bucket.get_blob.assert_called_once_with(f"{test_active_config_name}/{item.id}/{test_camera_id}.jpg") + mock_bucket.get_blob.assert_called_once_with( + f"{EDGE_NAME}/{test_active_config_name}/{item.id}/{test_camera_id}.jpg" + ) diff --git a/hub_labelizer/Dockerfile b/hub_labelizer/Dockerfile index 1de608d6..4c78946b 100644 --- a/hub_labelizer/Dockerfile +++ b/hub_labelizer/Dockerfile @@ -1,4 +1,4 @@ -FROM python:3.8.16-slim +FROM python:3.8-slim WORKDIR /hub_labelizer