From 22fcb0cb3cdf5de710b4740b89394be36048bfd3 Mon Sep 17 00:00:00 2001 From: Mainak Kundu Date: Fri, 19 Sep 2025 14:58:08 -0400 Subject: [PATCH 1/7] fix: chown server-info file by client user in compose mode --- .../fluent/core/docker/docker_compose.py | 3 +++ .../fluent/core/launcher/fluent_container.py | 3 +-- src/ansys/fluent/core/session.py | 25 +++++++++++++------ 3 files changed, 22 insertions(+), 9 deletions(-) diff --git a/src/ansys/fluent/core/docker/docker_compose.py b/src/ansys/fluent/core/docker/docker_compose.py index 77ec7e86c296..c5927b91c1b5 100644 --- a/src/ansys/fluent/core/docker/docker_compose.py +++ b/src/ansys/fluent/core/docker/docker_compose.py @@ -22,6 +22,7 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. +import os import subprocess import uuid @@ -45,6 +46,8 @@ def __init__(self, compose_config, container_dict): self._container_source = self._set_compose_cmds() self._container_source.remove("compose") + container_dict["command"].append(f"""-command="(system \\\"chown {os.getuid()}:{os.getgid()} {container_dict["container_server_info_file"]}\\\")" """) + self._compose_file = self._get_compose_file(container_dict) def _get_compose_file(self, container_dict): diff --git a/src/ansys/fluent/core/launcher/fluent_container.py b/src/ansys/fluent/core/launcher/fluent_container.py index cb94c80a8560..ea9faf4a6d13 100644 --- a/src/ansys/fluent/core/launcher/fluent_container.py +++ b/src/ansys/fluent/core/launcher/fluent_container.py @@ -353,8 +353,6 @@ def configure_container_dict( "FLUENT_ALLOW_REMOTE_GRPC_CONNECTION": "1", } ) - if compose_config.is_compose: - container_dict["environment"]["FLUENT_SERVER_INFO_PERMISSION_SYSTEM"] = "1" if "labels" not in container_dict: test_name = pyfluent.config.test_name @@ -389,6 +387,7 @@ def configure_container_dict( logger.debug( f"Using server info file '{container_server_info_file}' for Fluent container." ) + container_dict["container_server_info_file"] = container_server_info_file # If the 'command' had already been specified in the 'container_dict', # maintain other 'command' arguments but update the '-sifile' argument, diff --git a/src/ansys/fluent/core/session.py b/src/ansys/fluent/core/session.py index 67439b2d6c46..2d453109b4ee 100644 --- a/src/ansys/fluent/core/session.py +++ b/src/ansys/fluent/core/session.py @@ -59,13 +59,24 @@ def _parse_server_info_file(file_name: str): - with open(file_name, encoding="utf-8") as f: - lines = f.readlines() - ip_and_port = lines[0].strip().split(":") - ip = ip_and_port[0] - port = int(ip_and_port[1]) - password = lines[1].strip() - return ip, port, password + max_retries = 5 + retry_delay = 1 # seconds + + for attempt in range(max_retries): + try: + with open(file_name, encoding="utf-8") as f: + lines = f.readlines() + ip_and_port = lines[0].strip().split(":") + ip = ip_and_port[0] + port = int(ip_and_port[1]) + password = lines[1].strip() + return ip, port, password + except PermissionError as e: + if attempt < max_retries - 1: + time.sleep(retry_delay) + continue + else: + raise RuntimeError(f"Failed to parse server info file: {e}") from e class _IsDataValid: From 26fb1fba41116333d025936134d11f4a4a8dd636 Mon Sep 17 00:00:00 2001 From: pyansys-ci-bot <92810346+pyansys-ci-bot@users.noreply.github.com> Date: Fri, 19 Sep 2025 18:59:49 +0000 Subject: [PATCH 2/7] chore: adding changelog file 4483.fixed.md [dependabot-skip] --- doc/changelog.d/4483.fixed.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 doc/changelog.d/4483.fixed.md diff --git a/doc/changelog.d/4483.fixed.md b/doc/changelog.d/4483.fixed.md new file mode 100644 index 000000000000..2c6a48e24810 --- /dev/null +++ b/doc/changelog.d/4483.fixed.md @@ -0,0 +1 @@ +Chown server-info file by client user in compose mode From 20686f687b35bfdafaf31c659c705d5fdb2e233d Mon Sep 17 00:00:00 2001 From: Mainak Kundu Date: Fri, 19 Sep 2025 15:05:19 -0400 Subject: [PATCH 3/7] fix: chown server-info file by client user in compose mode --- src/ansys/fluent/core/docker/docker_compose.py | 4 +++- src/ansys/fluent/core/session.py | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/ansys/fluent/core/docker/docker_compose.py b/src/ansys/fluent/core/docker/docker_compose.py index c5927b91c1b5..cf7089b1d8b4 100644 --- a/src/ansys/fluent/core/docker/docker_compose.py +++ b/src/ansys/fluent/core/docker/docker_compose.py @@ -46,7 +46,9 @@ def __init__(self, compose_config, container_dict): self._container_source = self._set_compose_cmds() self._container_source.remove("compose") - container_dict["command"].append(f"""-command="(system \\\"chown {os.getuid()}:{os.getgid()} {container_dict["container_server_info_file"]}\\\")" """) + container_dict["command"].append( + f"""-command="(system \\\"chown {os.getuid()}:{os.getgid()} {container_dict["container_server_info_file"]}\\\")" """ + ) self._compose_file = self._get_compose_file(container_dict) diff --git a/src/ansys/fluent/core/session.py b/src/ansys/fluent/core/session.py index 2d453109b4ee..cc2c153b5810 100644 --- a/src/ansys/fluent/core/session.py +++ b/src/ansys/fluent/core/session.py @@ -25,6 +25,7 @@ from enum import Enum import json import logging +import time from typing import Any, Callable, Dict import warnings import weakref From 8d2ee63b8c6dabb497984d56d488e52838f7f308 Mon Sep 17 00:00:00 2001 From: Mainak Kundu Date: Fri, 19 Sep 2025 16:57:16 -0400 Subject: [PATCH 4/7] fix: chown server-info file by client user in compose mode --- src/ansys/fluent/core/docker/docker_compose.py | 4 ++-- src/ansys/fluent/core/launcher/fluent_container.py | 7 +++++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/ansys/fluent/core/docker/docker_compose.py b/src/ansys/fluent/core/docker/docker_compose.py index cf7089b1d8b4..7e1e37dc5923 100644 --- a/src/ansys/fluent/core/docker/docker_compose.py +++ b/src/ansys/fluent/core/docker/docker_compose.py @@ -32,7 +32,7 @@ class ComposeBasedLauncher: """Launch Fluent through docker or Podman compose.""" - def __init__(self, compose_config, container_dict): + def __init__(self, compose_config, container_dict, container_server_info_file): from ansys.fluent.core import config self._compose_config = compose_config @@ -47,7 +47,7 @@ def __init__(self, compose_config, container_dict): self._container_source.remove("compose") container_dict["command"].append( - f"""-command="(system \\\"chown {os.getuid()}:{os.getgid()} {container_dict["container_server_info_file"]}\\\")" """ + f"""-command="(system \\\"chown {os.getuid()}:{os.getgid()} {container_server_info_file}\\\")" """ ) self._compose_file = self._get_compose_file(container_dict) diff --git a/src/ansys/fluent/core/launcher/fluent_container.py b/src/ansys/fluent/core/launcher/fluent_container.py index ea9faf4a6d13..c9593cf09a02 100644 --- a/src/ansys/fluent/core/launcher/fluent_container.py +++ b/src/ansys/fluent/core/launcher/fluent_container.py @@ -172,7 +172,7 @@ def configure_container_dict( file_transfer_service: Any | None = None, compose_config: ComposeConfig | None = None, **container_dict, -) -> (dict, int, int, Path, bool): +) -> (dict, int, int, Path, str, bool): """Parses the parameters listed below, and sets up the container configuration file. Parameters @@ -218,6 +218,7 @@ def configure_container_dict( timeout : int port : int host_server_info_file : Path + container_server_info_file: str remove_server_info_file: bool Raises @@ -387,7 +388,6 @@ def configure_container_dict( logger.debug( f"Using server info file '{container_server_info_file}' for Fluent container." ) - container_dict["container_server_info_file"] = container_server_info_file # If the 'command' had already been specified in the 'container_dict', # maintain other 'command' arguments but update the '-sifile' argument, @@ -467,6 +467,7 @@ def configure_container_dict( timeout, container_grpc_port, host_server_info_file, + container_server_info_file, remove_server_info_file, ) @@ -527,6 +528,7 @@ def start_fluent_container( timeout, port, host_server_info_file, + container_server_info_file, remove_server_info_file, ) = container_vars launch_string = " ".join(config_dict["command"]) @@ -545,6 +547,7 @@ def start_fluent_container( compose_container = ComposeBasedLauncher( compose_config=compose_config, container_dict=config_dict, + container_server_info_file=container_server_info_file, ) if not compose_container.check_image_exists(): From 9b12728f80d6268f9c7a52ccffcbbe0b1941563b Mon Sep 17 00:00:00 2001 From: Mainak Kundu Date: Sat, 20 Sep 2025 22:00:31 -0400 Subject: [PATCH 5/7] fix: chown server-info file by client user in compose mode - alt fix --- .../fluent/core/docker/docker_compose.py | 30 +++++++++++++++++-- .../core/launcher/container_launcher.py | 7 +++++ src/ansys/fluent/core/session.py | 26 +++++----------- 3 files changed, 41 insertions(+), 22 deletions(-) diff --git a/src/ansys/fluent/core/docker/docker_compose.py b/src/ansys/fluent/core/docker/docker_compose.py index 7e1e37dc5923..270a01b34658 100644 --- a/src/ansys/fluent/core/docker/docker_compose.py +++ b/src/ansys/fluent/core/docker/docker_compose.py @@ -46,9 +46,7 @@ def __init__(self, compose_config, container_dict, container_server_info_file): self._container_source = self._set_compose_cmds() self._container_source.remove("compose") - container_dict["command"].append( - f"""-command="(system \\\"chown {os.getuid()}:{os.getgid()} {container_server_info_file}\\\")" """ - ) + self._container_server_info_file = container_server_info_file self._compose_file = self._get_compose_file(container_dict) @@ -248,3 +246,29 @@ def ports(self) -> list[str]: self._container_source + ["port", f"{self._compose_name}-fluent-1"], ) return self._extract_ports(output.decode("utf-8").strip()) + + def chown_server_info_file(self) -> None: + """Change ownership of the server info file inside the container. + + Raises + ------ + RuntimeError + If the command fails. + """ + result = subprocess.run( + self._container_source + + [ + "exec", + f"{self._compose_name}-fluent-1", + "chown", + f"{os.getuid()}:{os.getgid()}", + self._container_server_info_file, + ], + capture_output=True, + text=True, + ) + if result.returncode != 0: + raise RuntimeError( + f"Failed to change ownership of the server info file. " + f"Error: {result.stderr.strip()}" + ) diff --git a/src/ansys/fluent/core/launcher/container_launcher.py b/src/ansys/fluent/core/launcher/container_launcher.py index ad24c691c5a4..5101c90f949e 100644 --- a/src/ansys/fluent/core/launcher/container_launcher.py +++ b/src/ansys/fluent/core/launcher/container_launcher.py @@ -231,6 +231,13 @@ def __call__(self): compose_config=self._compose_config, ) + try: + _, _, password = _get_server_info_from_container( + config_dict=config_dict + ) + except PermissionError: + container.chown_server_info_file() + _, _, password = _get_server_info_from_container(config_dict=config_dict) else: port, password, container = start_fluent_container( diff --git a/src/ansys/fluent/core/session.py b/src/ansys/fluent/core/session.py index cc2c153b5810..67439b2d6c46 100644 --- a/src/ansys/fluent/core/session.py +++ b/src/ansys/fluent/core/session.py @@ -25,7 +25,6 @@ from enum import Enum import json import logging -import time from typing import Any, Callable, Dict import warnings import weakref @@ -60,24 +59,13 @@ def _parse_server_info_file(file_name: str): - max_retries = 5 - retry_delay = 1 # seconds - - for attempt in range(max_retries): - try: - with open(file_name, encoding="utf-8") as f: - lines = f.readlines() - ip_and_port = lines[0].strip().split(":") - ip = ip_and_port[0] - port = int(ip_and_port[1]) - password = lines[1].strip() - return ip, port, password - except PermissionError as e: - if attempt < max_retries - 1: - time.sleep(retry_delay) - continue - else: - raise RuntimeError(f"Failed to parse server info file: {e}") from e + with open(file_name, encoding="utf-8") as f: + lines = f.readlines() + ip_and_port = lines[0].strip().split(":") + ip = ip_and_port[0] + port = int(ip_and_port[1]) + password = lines[1].strip() + return ip, port, password class _IsDataValid: From fba1de0875d2bcf1a7a1b9665ead49e32d25f6f8 Mon Sep 17 00:00:00 2001 From: pyansys-ci-bot <92810346+pyansys-ci-bot@users.noreply.github.com> Date: Sun, 21 Sep 2025 02:13:20 +0000 Subject: [PATCH 6/7] chore: adding changelog file 4484.fixed.md [dependabot-skip] --- doc/changelog.d/4484.fixed.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 doc/changelog.d/4484.fixed.md diff --git a/doc/changelog.d/4484.fixed.md b/doc/changelog.d/4484.fixed.md new file mode 100644 index 000000000000..6bb9e871313f --- /dev/null +++ b/doc/changelog.d/4484.fixed.md @@ -0,0 +1 @@ +Chown server-info file by client user in compose mode - alt fix From cd6f949d5b500d03b655aed70ebf2f79c044b1f3 Mon Sep 17 00:00:00 2001 From: Mainak Kundu Date: Sun, 21 Sep 2025 00:58:37 -0400 Subject: [PATCH 7/7] fix: chown server-info file by client user in compose mode --- src/ansys/fluent/core/launcher/container_launcher.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/ansys/fluent/core/launcher/container_launcher.py b/src/ansys/fluent/core/launcher/container_launcher.py index 5101c90f949e..36fa95ed08b3 100644 --- a/src/ansys/fluent/core/launcher/container_launcher.py +++ b/src/ansys/fluent/core/launcher/container_launcher.py @@ -237,8 +237,9 @@ def __call__(self): ) except PermissionError: container.chown_server_info_file() - - _, _, password = _get_server_info_from_container(config_dict=config_dict) + _, _, password = _get_server_info_from_container( + config_dict=config_dict + ) else: port, password, container = start_fluent_container( self._args,