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 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 diff --git a/src/ansys/fluent/core/docker/docker_compose.py b/src/ansys/fluent/core/docker/docker_compose.py index 77ec7e86c296..270a01b34658 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 @@ -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 @@ -45,6 +46,8 @@ def __init__(self, compose_config, container_dict): self._container_source = self._set_compose_cmds() self._container_source.remove("compose") + self._container_server_info_file = container_server_info_file + self._compose_file = self._get_compose_file(container_dict) def _get_compose_file(self, container_dict): @@ -243,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..36fa95ed08b3 100644 --- a/src/ansys/fluent/core/launcher/container_launcher.py +++ b/src/ansys/fluent/core/launcher/container_launcher.py @@ -231,7 +231,15 @@ def __call__(self): compose_config=self._compose_config, ) - _, _, password = _get_server_info_from_container(config_dict=config_dict) + 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( self._args, diff --git a/src/ansys/fluent/core/launcher/fluent_container.py b/src/ansys/fluent/core/launcher/fluent_container.py index cb94c80a8560..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 @@ -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 @@ -468,6 +467,7 @@ def configure_container_dict( timeout, container_grpc_port, host_server_info_file, + container_server_info_file, remove_server_info_file, ) @@ -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"]) @@ -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():