Skip to content

Commit

Permalink
missing func
Browse files Browse the repository at this point in the history
  • Loading branch information
pcrespov committed Jul 31, 2023
1 parent 3d4249c commit 2e53571
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ async def discover_running_services(scheduler: "Scheduler") -> None: # type: ig
await scheduler._add_service(scheduler_data) # pylint: disable=protected-access


def _create_model_from_scheduler_data(
def create_model_from_scheduler_data(
node_uuid: NodeID,
scheduler_data: SchedulerData,
service_state: ServiceState,
Expand Down Expand Up @@ -132,7 +132,7 @@ async def get_stack_status_from_scheduler_data(
# check if there was an error picked up by the scheduler
# and marked this service as failed
if scheduler_data.dynamic_sidecar.status.current != DynamicSidecarStatus.OK:
return _create_model_from_scheduler_data(
return create_model_from_scheduler_data(
node_uuid=scheduler_data.node_uuid,
scheduler_data=scheduler_data,
service_state=ServiceState.FAILED,
Expand All @@ -141,7 +141,7 @@ async def get_stack_status_from_scheduler_data(

# is the service stopping?
if scheduler_data.dynamic_sidecar.service_removal_state.can_remove:
return _create_model_from_scheduler_data(
return create_model_from_scheduler_data(
node_uuid=scheduler_data.node_uuid,
scheduler_data=scheduler_data,
service_state=ServiceState.STOPPING,
Expand All @@ -157,7 +157,7 @@ async def get_stack_status_from_scheduler_data(
)
except DockerServiceNotFoundError:
# in this case, the service is starting, so state is pending
return _create_model_from_scheduler_data(
return create_model_from_scheduler_data(
node_uuid=scheduler_data.node_uuid,
scheduler_data=scheduler_data,
service_state=ServiceState.PENDING,
Expand All @@ -166,7 +166,7 @@ async def get_stack_status_from_scheduler_data(

# while the dynamic-sidecar state is not RUNNING report it's state
if sidecar_state != ServiceState.RUNNING:
return _create_model_from_scheduler_data(
return create_model_from_scheduler_data(
node_uuid=scheduler_data.node_uuid,
scheduler_data=scheduler_data,
service_state=sidecar_state,
Expand All @@ -179,7 +179,7 @@ async def get_stack_status_from_scheduler_data(
# wait for containers to start
if len(scheduler_data.dynamic_sidecar.containers_inspect) == 0:
# marks status as waiting for containers
return _create_model_from_scheduler_data(
return create_model_from_scheduler_data(
node_uuid=scheduler_data.node_uuid,
scheduler_data=scheduler_data,
service_state=ServiceState.STARTING,
Expand All @@ -190,7 +190,7 @@ async def get_stack_status_from_scheduler_data(
container_state, container_message = extract_containers_minimum_statuses(
scheduler_data.dynamic_sidecar.containers_inspect
)
return _create_model_from_scheduler_data(
return create_model_from_scheduler_data(
node_uuid=scheduler_data.node_uuid,
scheduler_data=scheduler_data,
service_state=container_state,
Expand Down
10 changes: 9 additions & 1 deletion services/director-v2/tests/unit/test_models_dynamic_services.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
# pylint: disable=protected-access
# pylint: disable=redefined-outer-name
# pylint: disable=too-many-arguments
# pylint: disable=unused-argument
# pylint: disable=unused-variable

import string
from collections import namedtuple

Expand All @@ -15,6 +20,9 @@
CONTAINER_STATUSES_UNEXPECTED,
extract_containers_minimum_statuses,
)
from simcore_service_director_v2.modules.dynamic_sidecar.scheduler._core._scheduler_utils import (
create_model_from_scheduler_data,
)

# the following is the predefined expected ordering, change below test only if
# this order is not adequate anymore
Expand Down Expand Up @@ -121,7 +129,7 @@ def _all_states() -> set[ServiceState]:
def test_running_service_details_make_status(
scheduler_data: SchedulerData, service_message: str, service_state: ServiceState
):
running_service_details = RunningDynamicServiceDetails.from_scheduler_data(
running_service_details = create_model_from_scheduler_data(
node_uuid=scheduler_data.node_uuid,
scheduler_data=scheduler_data,
service_state=service_state,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from typing import Any

import pytest
from simcore_service_director_v2.core.settings import AppSettings
from simcore_service_director_v2.models.dynamic_services_scheduler import SchedulerData
from simcore_service_director_v2.modules.dynamic_sidecar.docker_service_specs.sidecar import (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@
from simcore_service_director_v2.modules.dynamic_sidecar.scheduler._core._scheduler import (
Scheduler,
)
from simcore_service_director_v2.modules.dynamic_sidecar.scheduler._core._scheduler_utils import (
create_model_from_scheduler_data,
)

# running scheduler at a hight rate to stress out the system
# and ensure faster tests
Expand Down Expand Up @@ -364,7 +367,7 @@ async def test_get_stack_status(
await scheduler._scheduler._add_service(scheduler_data)

stack_status = await scheduler.get_stack_status(scheduler_data.node_uuid)
assert stack_status == RunningDynamicServiceDetails.from_scheduler_data(
assert stack_status == create_model_from_scheduler_data(
node_uuid=scheduler_data.node_uuid,
scheduler_data=scheduler_data,
service_state=ServiceState.PENDING,
Expand Down Expand Up @@ -395,7 +398,7 @@ async def test_get_stack_status_failing_sidecar(
await scheduler._scheduler._add_service(scheduler_data)

stack_status = await scheduler.get_stack_status(scheduler_data.node_uuid)
assert stack_status == RunningDynamicServiceDetails.from_scheduler_data(
assert stack_status == create_model_from_scheduler_data(
node_uuid=scheduler_data.node_uuid,
scheduler_data=scheduler_data,
service_state=ServiceState.FAILED,
Expand All @@ -414,7 +417,7 @@ async def test_get_stack_status_containers_are_starting(
async with _assert_get_dynamic_services_mocked(
scheduler, scheduler_data, mock_service_running, expected_status="created"
) as stack_status:
assert stack_status == RunningDynamicServiceDetails.from_scheduler_data(
assert stack_status == create_model_from_scheduler_data(
node_uuid=scheduler_data.node_uuid,
scheduler_data=scheduler_data,
service_state=ServiceState.STARTING,
Expand All @@ -433,7 +436,7 @@ async def test_get_stack_status_ok(
async with _assert_get_dynamic_services_mocked(
scheduler, scheduler_data, mock_service_running, expected_status="running"
) as stack_status:
assert stack_status == RunningDynamicServiceDetails.from_scheduler_data(
assert stack_status == create_model_from_scheduler_data(
node_uuid=scheduler_data.node_uuid,
scheduler_data=scheduler_data,
service_state=ServiceState.RUNNING,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
# pylint: disable=protected-access
# pylint: disable=redefined-outer-name
# pylint: disable=too-many-arguments
# pylint: disable=unused-argument
# pylint: disable=unused-variable

import pytest
from pytest import LogCaptureFixture
Expand Down

0 comments on commit 2e53571

Please sign in to comment.