Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/changelog.d/4483.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Chown server-info file by client user in compose mode
7 changes: 6 additions & 1 deletion src/ansys/fluent/core/docker/docker_compose.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -31,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
Expand All @@ -45,6 +46,10 @@ 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_server_info_file}\\\")" """
)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will send the scheme command (system "chown <uid>:<gid> <server-info-file>") to Fluent.


self._compose_file = self._get_compose_file(container_dict)

def _get_compose_file(self, container_dict):
Expand Down
8 changes: 5 additions & 3 deletions src/ansys/fluent/core/launcher/fluent_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -353,8 +354,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
Expand Down Expand Up @@ -468,6 +467,7 @@ def configure_container_dict(
timeout,
container_grpc_port,
host_server_info_file,
container_server_info_file,
remove_server_info_file,
)

Expand Down Expand Up @@ -528,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"])
Expand All @@ -546,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():
Expand Down
26 changes: 19 additions & 7 deletions src/ansys/fluent/core/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
from enum import Enum
import json
import logging
import time
from typing import Any, Callable, Dict
import warnings
import weakref
Expand Down Expand Up @@ -59,13 +60,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:
Expand Down
Loading