Skip to content

Commit

Permalink
Merge branch 'mr/ramonat/nested-entry-points' into 'master'
Browse files Browse the repository at this point in the history
Detect invalid plan containing nested entry points

See merge request it/e3-core!41
  • Loading branch information
enzbang committed Oct 4, 2024
2 parents f81e8d3 + fec8e38 commit 99b54e1
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/e3/electrolyt/plan.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,13 +272,22 @@ def execute(
if entry_point_parameters is None:
entry_point_parameters = {}

nb_entry_points = len(plan.entry_points)
if entry_point_name in plan.entry_points:
plan.entry_points[entry_point_name].execute(**entry_point_parameters)
else:
# ??? An error should be raised as soon as entry points are
# used everywhere
plan.mod.__dict__[entry_point_name](**entry_point_parameters)

if len(plan.entry_points) != nb_entry_points:
# The number of entry points should not change when executing the
# code in an entry point. If it does, it means that there is a
# nested entry point, this is not supported.
raise PlanError(
f"the plan contains nested entry points in {entry_point_name}"
)

return self.action_list

def _add_action(self, name: str, *args: Any, **kwargs: Any) -> None:
Expand Down
28 changes: 28 additions & 0 deletions tests/tests_e3/electrolyt/plan/main_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import e3.electrolyt.host as host
import e3.electrolyt.plan as plan
import e3.env
import pytest


def build_action(spec, build=None, host=None, target=None, board=None):
Expand Down Expand Up @@ -145,6 +146,33 @@ def test_entry_points():
assert ep_executed[0].name == "machine2"


def test_nested_entry_points():
"""Test a plan containing nested entry points.
Nested entry points are not supported, verify that we get an Plan Error.
"""
plan_content = [
'@machine(name="machine1", description="Machine 1",',
' platform="x86_64-linux", version="rhES6")',
"def machine1():",
' build("a")',
' @machine(description="Machine 2",',
' platform="x86_64-linux", version="rhES6")',
" def machine2():",
' build("b")',
]
myplan = _get_plan({}, plan_content)

db = myplan.entry_points
assert len(db) == 1
assert "machine1" in db

context = _get_new_plancontext("machine1")
with pytest.raises(plan.PlanError) as pe:
context.execute(myplan, "machine1")
assert "nested" in str(pe)


def test_plan_disable_lines():
"""Check that lines in enabled=False blocks are disabled."""
context = _get_new_plancontext("myserver")
Expand Down

0 comments on commit 99b54e1

Please sign in to comment.