diff --git a/src/openjd/sessions/__init__.py b/src/openjd/sessions/__init__.py index fc281165..208b1768 100644 --- a/src/openjd/sessions/__init__.py +++ b/src/openjd/sessions/__init__.py @@ -1,7 +1,7 @@ # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. from ._logging import LOG -from ._path_mapping import PathMappingOS, PathMappingRule +from ._path_mapping import PathFormat, PathMappingRule from ._session import ActionStatus, Session, SessionCallbackType, SessionState from ._session_user import PosixSessionUser, SessionUser from ._types import ( @@ -23,7 +23,7 @@ "LOG", "Parameter", "ParameterType", - "PathMappingOS", + "PathFormat", "PathMappingRule", "PosixSessionUser", "Session", diff --git a/src/openjd/sessions/_path_mapping.py b/src/openjd/sessions/_path_mapping.py index 64509aac..b84178ff 100644 --- a/src/openjd/sessions/_path_mapping.py +++ b/src/openjd/sessions/_path_mapping.py @@ -6,29 +6,33 @@ from pathlib import PurePath, PurePosixPath, PureWindowsPath -class PathMappingOS(str, Enum): +class PathFormat(str, Enum): POSIX = "POSIX" WINDOWS = "WINDOWS" @dataclass(frozen=True) class PathMappingRule: - source_os: PathMappingOS + source_path_format: PathFormat source_path: PurePath destination_path: PurePath def __init__( - self, *, source_os: PathMappingOS, source_path: PurePath, destination_path: PurePath + self, *, source_path_format: PathFormat, source_path: PurePath, destination_path: PurePath ): - if source_os == PathMappingOS.POSIX: + if source_path_format == PathFormat.POSIX: if not isinstance(source_path, PurePosixPath): - raise ValueError("Path mapping rule source_os does not match source_path type") + raise ValueError( + "Path mapping rule source_path_format does not match source_path type" + ) else: if not isinstance(source_path, PureWindowsPath): - raise ValueError("Path mapping rule source_os does not match source_path type") + raise ValueError( + "Path mapping rule source_path_format does not match source_path type" + ) # This roundabout way can set the attributes of a frozen dataclass - object.__setattr__(self, "source_os", source_os) + object.__setattr__(self, "source_path_format", source_path_format) object.__setattr__(self, "source_path", source_path) object.__setattr__(self, "destination_path", destination_path) @@ -44,9 +48,9 @@ def from_dict(rule: dict[str, str]) -> "PathMappingRule": if name not in rule: raise ValueError(f"Path mapping rule requires the following fields: {field_names}") - source_os = PathMappingOS(rule["source_os"].upper()) + source_path_format = PathFormat(rule["source_path_format"].upper()) source_path: PurePath - if source_os == PathMappingOS.POSIX: + if source_path_format == PathFormat.POSIX: source_path = PurePosixPath(rule["source_path"]) else: source_path = PureWindowsPath(rule["source_path"]) @@ -59,13 +63,15 @@ def from_dict(rule: dict[str, str]) -> "PathMappingRule": ) return PathMappingRule( - source_os=source_os, source_path=source_path, destination_path=destination_path + source_path_format=source_path_format, + source_path=source_path, + destination_path=destination_path, ) def to_dict(self) -> dict[str, str]: """Returns a dictionary representation of the PathMappingRule.""" return { - "source_os": self.source_os.name, + "source_path_format": self.source_path_format.name, "source_path": str(self.source_path), "destination_path": str(self.destination_path), } @@ -78,7 +84,7 @@ def apply(self, *, path: str) -> tuple[bool, str]: mapped path. If it doesn't match, then it returns the original path unmodified. """ pure_path: PurePath - if self.source_os == PathMappingOS.POSIX: + if self.source_path_format == PathFormat.POSIX: pure_path = PurePosixPath(path) else: pure_path = PureWindowsPath(path) @@ -91,17 +97,17 @@ def apply(self, *, path: str) -> tuple[bool, str]: ) if os_name == "posix": result = str(PurePosixPath(*remapped_parts)) - if self._has_trailing_slash(self.source_os, path): + if self._has_trailing_slash(self.source_path_format, path): result += "/" else: result = str(PureWindowsPath(*remapped_parts)) - if self._has_trailing_slash(self.source_os, path): + if self._has_trailing_slash(self.source_path_format, path): result += "\\" return True, result - def _has_trailing_slash(self, os: PathMappingOS, path: str) -> bool: - if os == PathMappingOS.POSIX: + def _has_trailing_slash(self, os: PathFormat, path: str) -> bool: + if os == PathFormat.POSIX: return path.endswith("/") else: return path.endswith("\\") diff --git a/src/openjd/sessions/_session.py b/src/openjd/sessions/_session.py index 3cb6bd7b..e1d67dca 100644 --- a/src/openjd/sessions/_session.py +++ b/src/openjd/sessions/_session.py @@ -777,24 +777,21 @@ def _materialize_path_mapping( """Materialize path mapping rules to disk and the os environment variables.""" if self._path_mapping_rules: rules_dict = { + "version": "pathmapping-1.0", "path_mapping_rules": [ { - "source_os": rule.source_os.value, + "source_path_format": rule.source_path_format.value, "source_path": str(rule.source_path), "destination_path": str(rule.destination_path), } for rule in self._path_mapping_rules - ] + ], } symtab[ValueReferenceConstants_2023_09.HAS_PATH_MAPPING_RULES.value] = "true" else: rules_dict = dict() symtab[ValueReferenceConstants_2023_09.HAS_PATH_MAPPING_RULES.value] = "false" rules_json = json.dumps(rules_dict) - # TODO - Remove this environment variable before the formal release of the lib/spec. - # Reason: This is an interim workaround for functionality that was missing. - os_env["PATH_MAPPING_RULES"] = rules_json - # TODO /stop file_handle, filename = mkstemp(dir=self.working_directory, suffix=".json", text=True) os.close(file_handle) write_file_for_user(Path(filename), rules_json, self._user) diff --git a/test/openjd/sessions/test_path_mapping.py b/test/openjd/sessions/test_path_mapping.py index 7c14d127..434ab517 100644 --- a/test/openjd/sessions/test_path_mapping.py +++ b/test/openjd/sessions/test_path_mapping.py @@ -6,7 +6,7 @@ import pytest -from openjd.sessions import PathMappingOS, PathMappingRule +from openjd.sessions import PathFormat, PathMappingRule from openjd.sessions import _path_mapping as path_mapping_impl_mod @@ -21,7 +21,7 @@ class TestPathMapping: [ pytest.param( PathMappingRule( - source_os=PathMappingOS.POSIX, + source_path_format=PathFormat.POSIX, source_path=PurePosixPath("/mnt/shared/"), destination_path=PurePosixPath("/newprefix"), ), @@ -52,7 +52,7 @@ class TestPathMapping: + [ pytest.param( PathMappingRule( - source_os=PathMappingOS.POSIX, + source_path_format=PathFormat.POSIX, source_path=PurePosixPath("/mnt/shared/"), destination_path=PureWindowsPath("c:\\newprefix"), ), @@ -91,7 +91,7 @@ class TestPathMapping: + [ pytest.param( PathMappingRule( - source_os=PathMappingOS.WINDOWS, + source_path_format=PathFormat.WINDOWS, source_path=PureWindowsPath("c:\\mnt\\shared\\"), destination_path=PurePosixPath("/newprefix"), ), @@ -130,7 +130,7 @@ class TestPathMapping: + [ pytest.param( PathMappingRule( - source_os=PathMappingOS.WINDOWS, + source_path_format=PathFormat.WINDOWS, source_path=PureWindowsPath("c:\\mnt\\shared\\"), destination_path=PureWindowsPath("c:\\newprefix"), ), @@ -173,7 +173,7 @@ class TestPathMapping: + [ pytest.param( PathMappingRule( - source_os=PathMappingOS.WINDOWS, + source_path_format=PathFormat.WINDOWS, source_path=PureWindowsPath("\\\\128.0.0.1\\share\\assets"), destination_path=PureWindowsPath("z:\\assets"), ), @@ -198,7 +198,7 @@ class TestPathMapping: + [ pytest.param( PathMappingRule( - source_os=PathMappingOS.WINDOWS, + source_path_format=PathFormat.WINDOWS, source_path=PureWindowsPath("z:\\assets"), destination_path=PureWindowsPath("\\\\128.0.0.1\\share\\assets"), ), @@ -223,7 +223,7 @@ class TestPathMapping: + [ pytest.param( PathMappingRule( - source_os=PathMappingOS.WINDOWS, + source_path_format=PathFormat.WINDOWS, source_path=PureWindowsPath("\\\\.\\c:\\assets"), destination_path=PureWindowsPath("z:\\assets"), ), @@ -248,7 +248,7 @@ class TestPathMapping: + [ pytest.param( PathMappingRule( - source_os=PathMappingOS.WINDOWS, + source_path_format=PathFormat.WINDOWS, source_path=PureWindowsPath("z:\\assets"), destination_path=PureWindowsPath("\\\\.\\c:\\assets"), ), @@ -273,7 +273,7 @@ class TestPathMapping: + [ pytest.param( PathMappingRule( - source_os=PathMappingOS.WINDOWS, + source_path_format=PathFormat.WINDOWS, source_path=PureWindowsPath("\\\\?\\c:\\assets"), destination_path=PureWindowsPath("z:\\assets"), ), @@ -298,7 +298,7 @@ class TestPathMapping: + [ pytest.param( PathMappingRule( - source_os=PathMappingOS.WINDOWS, + source_path_format=PathFormat.WINDOWS, source_path=PureWindowsPath("z:\\assets"), destination_path=PureWindowsPath("\\\\?\\c:\\assets"), ), @@ -323,7 +323,7 @@ class TestPathMapping: + [ pytest.param( PathMappingRule( - source_os=PathMappingOS.WINDOWS, + source_path_format=PathFormat.WINDOWS, source_path=PureWindowsPath( "\\\\?\\Volume{b75e2c83-0000-0000-0000-602f12345678}\\assets" ), @@ -350,7 +350,7 @@ class TestPathMapping: + [ pytest.param( PathMappingRule( - source_os=PathMappingOS.WINDOWS, + source_path_format=PathFormat.WINDOWS, source_path=PureWindowsPath("z:\\assets"), destination_path=PureWindowsPath( "\\\\?\\Volume{b75e2c83-0000-0000-0000-602f12345678}\\assets" @@ -393,7 +393,7 @@ def test_remaps( [ pytest.param( PathMappingRule( - source_os=PathMappingOS.POSIX, + source_path_format=PathFormat.POSIX, source_path=PurePosixPath("/mnt/shared"), destination_path=PureWindowsPath("c:\\newprefix"), ), @@ -409,7 +409,7 @@ def test_remaps( + [ pytest.param( PathMappingRule( - source_os=PathMappingOS.WINDOWS, + source_path_format=PathFormat.WINDOWS, source_path=PureWindowsPath("c:\\mnt\\shared\\"), destination_path=PureWindowsPath("c:\\newprefix"), ), @@ -437,18 +437,18 @@ def test_does_not_remap(self, rule: PathMappingRule, given: str) -> None: "rule_params", [ { - "source_os": PathMappingOS.WINDOWS, + "source_path_format": PathFormat.WINDOWS, "source_path": PurePosixPath("C:\\oldprefix"), "destination_path": PureWindowsPath("c:\\newprefix"), }, { - "source_os": PathMappingOS.POSIX, + "source_path_format": PathFormat.POSIX, "source_path": PureWindowsPath("/mnt/oldprefix"), "destination_path": PureWindowsPath("c:\\newprefix"), }, ], ) - def test_mismatching_source_os_path(self, rule_params): + def test_mismatching_source_path_format_path(self, rule_params): with pytest.raises(ValueError): PathMappingRule(**rule_params) @@ -457,48 +457,48 @@ def test_mismatching_source_os_path(self, rule_params): [ ( { - "source_os": "WINDOWS", + "source_path_format": "WINDOWS", "source_path": "C:\\oldprefix", "destination_path": "c:\\newprefix", }, PathMappingRule( - source_os=PathMappingOS.WINDOWS, + source_path_format=PathFormat.WINDOWS, source_path=PureWindowsPath("C:\\oldprefix"), destination_path=PurePath("c:\\newprefix"), ), ), ( { - "source_os": "POSIX", + "source_path_format": "POSIX", "source_path": "/mnt/oldprefix", "destination_path": "c:\\newprefix", }, PathMappingRule( - source_os=PathMappingOS.POSIX, + source_path_format=PathFormat.POSIX, source_path=PurePosixPath("/mnt/oldprefix"), destination_path=PurePath("c:\\newprefix"), ), ), ( { - "source_os": "windows", + "source_path_format": "windows", "source_path": "C:\\oldprefix", "destination_path": "c:\\newprefix", }, PathMappingRule( - source_os=PathMappingOS.WINDOWS, + source_path_format=PathFormat.WINDOWS, source_path=PureWindowsPath("C:\\oldprefix"), destination_path=PurePath("c:\\newprefix"), ), ), ( { - "source_os": "posix", + "source_path_format": "posix", "source_path": "/mnt/oldprefix", "destination_path": "c:\\newprefix", }, PathMappingRule( - source_os=PathMappingOS.POSIX, + source_path_format=PathFormat.POSIX, source_path=PurePosixPath("/mnt/oldprefix"), destination_path=PurePath("c:\\newprefix"), ), @@ -514,17 +514,17 @@ def test_from_dict_success(self, dict_rule, expected): [ ( { - "source_os": "WINDOWS10", + "source_path_format": "WINDOWS10", "source_path": "C:\\oldprefix", "destination_path": "c:\\newprefix", } ), ({"source_path": "/mnt/oldprefix", "destination_path": "c:\\newprefix"}), - ({"source_os": "POSIX", "destination_path": "c:\\newprefix"}), - ({"source_os": "POSIX", "source_path": "/mnt/oldprefix"}), + ({"source_path_format": "POSIX", "destination_path": "c:\\newprefix"}), + ({"source_path_format": "POSIX", "source_path": "/mnt/oldprefix"}), ( { - "source_os": "windows", + "source_path_format": "windows", "source_path": "C:\\oldprefix", "destination_path": "c:\\newprefix", "extra_field": "value", diff --git a/test/openjd/sessions/test_session.py b/test/openjd/sessions/test_session.py index dc1c304b..afdcd029 100644 --- a/test/openjd/sessions/test_session.py +++ b/test/openjd/sessions/test_session.py @@ -39,7 +39,7 @@ ActionStatus, Parameter, ParameterType, - PathMappingOS, + PathFormat, PathMappingRule, Session, SessionState, @@ -644,9 +644,7 @@ def test_run_task_with_variables( # THEN assert session._runner is not None assert fix_foo_baz_environment.variables is not None - assert session._runner._os_env_vars == dict( - fix_foo_baz_environment.variables, **{"PATH_MAPPING_RULES": "{}"} - ) + assert session._runner._os_env_vars == dict(fix_foo_baz_environment.variables) class TestSessionCancel: @@ -1005,7 +1003,7 @@ def test_enter_environment_with_variables(self) -> None: time.sleep(0.1) assert session.state == SessionState.READY assert session._runner is not None - assert session._runner._os_env_vars == dict(variables, **{"PATH_MAPPING_RULES": "{}"}) + assert session._runner._os_env_vars == dict(variables) @pytest.mark.usefixtures("caplog") # builtin fixture def test_enter_environment_with_resolved_variables( @@ -1066,7 +1064,7 @@ def test_enter_two_environments_with_variables(self) -> None: time.sleep(0.1) assert session._runner is not None - assert session._runner._os_env_vars == dict(variables2, **{"PATH_MAPPING_RULES": "{}"}) + assert session._runner._os_env_vars == dict(variables2) class TestSessionExitEnvironment_2023_09: # noqa: N801 @@ -1282,7 +1280,7 @@ def test_exit_environment_with_variables(self) -> None: # THEN assert session.state == SessionState.READY_ENDING assert session._runner is not None - assert session._runner._os_env_vars == dict(variables, **{"PATH_MAPPING_RULES": "{}"}) + assert session._runner._os_env_vars == dict(variables) def test_exit_two_environments_with_variables(self) -> None: # GIVEN @@ -1313,7 +1311,7 @@ def test_exit_two_environments_with_variables(self) -> None: # THEN assert session.state == SessionState.READY_ENDING assert session._runner is not None - assert session._runner._os_env_vars == dict(variables2, **{"PATH_MAPPING_RULES": "{}"}) + assert session._runner._os_env_vars == dict(variables2) session.exit_environment(identifier=identifier1) # Wait for the process to exit @@ -1323,7 +1321,7 @@ def test_exit_two_environments_with_variables(self) -> None: # THEN assert session.state == SessionState.READY_ENDING assert session._runner is not None - assert session._runner._os_env_vars == dict(variables1, **{"PATH_MAPPING_RULES": "{}"}) + assert session._runner._os_env_vars == dict(variables1) class TestPathMapping_v2023_09: # noqa: N801 @@ -1337,20 +1335,21 @@ class TestPathMapping_v2023_09: # noqa: N801 pytest.param( [ PathMappingRule( - source_os=PathMappingOS.POSIX, + source_path_format=PathFormat.POSIX, source_path=PurePosixPath("/home/user"), destination_path=PurePosixPath("/mnt/share/user"), ), ], json.dumps( { + "version": "pathmapping-1.0", "path_mapping_rules": [ { - "source_os": "POSIX", + "source_path_format": "POSIX", "source_path": "/home/user", "destination_path": "/mnt/share/user", } - ] + ], } ), id="single posix", @@ -1358,20 +1357,21 @@ class TestPathMapping_v2023_09: # noqa: N801 pytest.param( [ PathMappingRule( - source_os=PathMappingOS.WINDOWS, + source_path_format=PathFormat.WINDOWS, source_path=PureWindowsPath(r"c:\Users\user"), destination_path=PurePosixPath("/mnt/share/user"), ), ], json.dumps( { + "version": "pathmapping-1.0", "path_mapping_rules": [ { - "source_os": "WINDOWS", + "source_path_format": "WINDOWS", "source_path": r"c:\Users\user", "destination_path": "/mnt/share/user", } - ] + ], } ), id="single windows", @@ -1379,30 +1379,31 @@ class TestPathMapping_v2023_09: # noqa: N801 pytest.param( [ PathMappingRule( - source_os=PathMappingOS.POSIX, + source_path_format=PathFormat.POSIX, source_path=PurePosixPath("/home/user"), destination_path=PurePosixPath("/mnt/share/user"), ), PathMappingRule( - source_os=PathMappingOS.POSIX, + source_path_format=PathFormat.POSIX, source_path=PurePosixPath("/home/user2"), destination_path=PurePosixPath("/mnt/share/user2"), ), ], json.dumps( { + "version": "pathmapping-1.0", "path_mapping_rules": [ { - "source_os": "POSIX", + "source_path_format": "POSIX", "source_path": "/home/user", "destination_path": "/mnt/share/user", }, { - "source_os": "POSIX", + "source_path_format": "POSIX", "source_path": "/home/user2", "destination_path": "/mnt/share/user2", }, - ] + ], } ), id="multiple posix", @@ -1410,30 +1411,31 @@ class TestPathMapping_v2023_09: # noqa: N801 pytest.param( [ PathMappingRule( - source_os=PathMappingOS.WINDOWS, + source_path_format=PathFormat.WINDOWS, source_path=PureWindowsPath(r"c:\Users\user"), destination_path=PurePosixPath("/mnt/share/user"), ), PathMappingRule( - source_os=PathMappingOS.WINDOWS, + source_path_format=PathFormat.WINDOWS, source_path=PureWindowsPath(r"c:\Users\user2"), destination_path=PurePosixPath("/mnt/share/user2"), ), ], json.dumps( { + "version": "pathmapping-1.0", "path_mapping_rules": [ { - "source_os": "WINDOWS", + "source_path_format": "WINDOWS", "source_path": r"c:\Users\user", "destination_path": "/mnt/share/user", }, { - "source_os": "WINDOWS", + "source_path_format": "WINDOWS", "source_path": r"c:\Users\user2", "destination_path": "/mnt/share/user2", }, - ] + ], } ), id="multiple windows", @@ -1456,8 +1458,6 @@ def test_materialize(self, rules: Optional[list[PathMappingRule]], expected_json session._materialize_path_mapping(SchemaVersion.v2023_09, env_vars, symtab) # THEN - assert "PATH_MAPPING_RULES" in env_vars - assert env_vars["PATH_MAPPING_RULES"] == expected_json assert symtab["Session.HasPathMappingRules"] == ("true" if rules else "false") assert "Session.PathMappingRulesFile" in symtab filename = symtab["Session.PathMappingRulesFile"] @@ -1484,7 +1484,7 @@ def test_run_task(self, caplog: pytest.LogCaptureFixture) -> None: EmbeddedFileText_2023_09( name="Script", type=EmbeddedFileTypes_2023_09.TEXT, - data="import os; print('Has: {{Session.HasPathMappingRules}}'); print('Has Env:', 'yes' if os.environ.get('PATH_MAPPING_RULES') else 'no')", + data="import os; print('Has: {{Session.HasPathMappingRules}}')", ) ], ) @@ -1493,7 +1493,7 @@ def test_run_task(self, caplog: pytest.LogCaptureFixture) -> None: task_params = list[Parameter]() path_mapping_rules = [ PathMappingRule( - source_os=PathMappingOS.POSIX, + source_path_format=PathFormat.POSIX, source_path=PurePosixPath("/home/user"), destination_path=PurePosixPath("/mnt/share/user"), ), @@ -1510,7 +1510,6 @@ def test_run_task(self, caplog: pytest.LogCaptureFixture) -> None: # THEN assert "Has: true" in caplog.messages - assert "Has Env: yes" in caplog.messages @pytest.mark.usefixtures("caplog") # builtin fixture def test_enter_environment(self, caplog: pytest.LogCaptureFixture) -> None: @@ -1531,7 +1530,7 @@ def test_enter_environment(self, caplog: pytest.LogCaptureFixture) -> None: EmbeddedFileText_2023_09( name="Script", type=EmbeddedFileTypes_2023_09.TEXT, - data="import os; print('Has: {{Session.HasPathMappingRules}}'); print('Has Env:', 'yes' if os.environ.get('PATH_MAPPING_RULES') else 'no')", + data="import os; print('Has: {{Session.HasPathMappingRules}}')", ) ], ) @@ -1540,7 +1539,7 @@ def test_enter_environment(self, caplog: pytest.LogCaptureFixture) -> None: job_params = list[Parameter]() path_mapping_rules = [ PathMappingRule( - source_os=PathMappingOS.POSIX, + source_path_format=PathFormat.POSIX, source_path=PurePosixPath("/home/user"), destination_path=PurePosixPath("/mnt/share/user"), ), @@ -1557,7 +1556,6 @@ def test_enter_environment(self, caplog: pytest.LogCaptureFixture) -> None: # THEN assert "Has: true" in caplog.messages - assert "Has Env: yes" in caplog.messages @pytest.mark.usefixtures("caplog") # builtin fixture def test_exit_environment(self, caplog: pytest.LogCaptureFixture) -> None: @@ -1578,7 +1576,7 @@ def test_exit_environment(self, caplog: pytest.LogCaptureFixture) -> None: EmbeddedFileText_2023_09( name="Script", type=EmbeddedFileTypes_2023_09.TEXT, - data="import os; print('Has: {{Session.HasPathMappingRules}}'); print('Has Env:', 'yes' if os.environ.get('PATH_MAPPING_RULES') else 'no')", + data="import os; print('Has: {{Session.HasPathMappingRules}}')", ) ], ) @@ -1587,7 +1585,7 @@ def test_exit_environment(self, caplog: pytest.LogCaptureFixture) -> None: job_params = list[Parameter]() path_mapping_rules = [ PathMappingRule( - source_os=PathMappingOS.POSIX, + source_path_format=PathFormat.POSIX, source_path=PurePosixPath("/home/user"), destination_path=PurePosixPath("/mnt/share/user"), ), @@ -1606,58 +1604,6 @@ def test_exit_environment(self, caplog: pytest.LogCaptureFixture) -> None: # THEN assert "Has: true" in caplog.messages - assert "Has Env: yes" in caplog.messages - - @pytest.mark.skipif(os.name != "posix", reason="Posix-only test.") - @pytest.mark.xfail( - not has_posix_target_user(), - reason="Must be running inside of the sudo_environment testing container.", - ) - @pytest.mark.usefixtures("caplog", "posix_target_user") # builtin fixture - def test_cross_user( - self, caplog: pytest.LogCaptureFixture, posix_target_user: PosixSessionUser - ) -> None: - # Test a cross-user run-task just to make sure that the path mapping environment variable - # passes through in the correct format. - - # GIVEN - # A script that just prints out some messages indicating that we got the - # expected data. - script = StepScript_2023_09( - actions=StepActions_2023_09( - onRun=Action_2023_09(command=sys.executable, args=["{{ Task.File.Script }}"]) - ), - embeddedFiles=[ - EmbeddedFileText_2023_09( - name="Script", - type=EmbeddedFileTypes_2023_09.TEXT, - data="import os; import json; json.loads(os.environ['PATH_MAPPING_RULES']); print('Success')", - ) - ], - ) - session_id = "some id" - job_params = list[Parameter]() - task_params = list[Parameter]() - path_mapping_rules = [ - PathMappingRule( - source_os=PathMappingOS.POSIX, - source_path=PurePosixPath("/home/user"), - destination_path=PurePosixPath("/mnt/share/user"), - ), - ] - with Session( - session_id=session_id, - job_parameter_values=job_params, - path_mapping_rules=path_mapping_rules, - user=posix_target_user, - ) as session: - # WHEN - session.run_task(step_script=script, task_parameter_values=task_params) - while session.state == SessionState.RUNNING: - time.sleep(0.1) - - # THEN - assert "Success" in caplog.messages @pytest.mark.parametrize( "rules, given, expected", @@ -1665,7 +1611,7 @@ def test_cross_user( pytest.param( [ PathMappingRule( - source_os=PathMappingOS.POSIX, + source_path_format=PathFormat.POSIX, source_path=PurePosixPath("/mnt"), destination_path=PurePosixPath("/home"), ) @@ -1677,12 +1623,12 @@ def test_cross_user( pytest.param( [ PathMappingRule( - source_os=PathMappingOS.POSIX, + source_path_format=PathFormat.POSIX, source_path=PurePosixPath("/mnt"), destination_path=PurePosixPath("/home"), ), PathMappingRule( - source_os=PathMappingOS.POSIX, + source_path_format=PathFormat.POSIX, source_path=PurePosixPath("/mnt/share"), destination_path=PurePosixPath("/share"), ), @@ -1694,12 +1640,12 @@ def test_cross_user( pytest.param( [ PathMappingRule( - source_os=PathMappingOS.POSIX, + source_path_format=PathFormat.POSIX, source_path=PurePosixPath("/mnt/share"), destination_path=PurePosixPath("/share"), ), PathMappingRule( - source_os=PathMappingOS.POSIX, + source_path_format=PathFormat.POSIX, source_path=PurePosixPath("/mnt"), destination_path=PurePosixPath("/home"), ), @@ -1711,12 +1657,12 @@ def test_cross_user( pytest.param( [ PathMappingRule( - source_os=PathMappingOS.POSIX, + source_path_format=PathFormat.POSIX, source_path=PurePosixPath("/mnt/share"), destination_path=PurePosixPath("/mnt"), ), PathMappingRule( - source_os=PathMappingOS.POSIX, + source_path_format=PathFormat.POSIX, source_path=PurePosixPath("/mnt"), destination_path=PurePosixPath("/home"), ), @@ -1728,7 +1674,7 @@ def test_cross_user( pytest.param( [ PathMappingRule( - source_os=PathMappingOS.WINDOWS, + source_path_format=PathFormat.WINDOWS, source_path=PureWindowsPath(r"D:\Assets"), destination_path=PurePosixPath("/tmp/openjd"), ),