Skip to content

Commit ec2c873

Browse files
fix: chown server-info file by client user in compose mode - alt fix (#4484)
This PR removes the `FLUENT_SERVER_INFO_PERMISSION_SYSTEM` env var for compose launch. The server writes the server-info file with the default 600 permission. The file owner is subsequently changed to client-user subsequent using a `docker exec` call, so the file can be read in the client side. --------- Co-authored-by: pyansys-ci-bot <[email protected]>
1 parent e2bc87f commit ec2c873

File tree

5 files changed

+46
-5
lines changed

5 files changed

+46
-5
lines changed

doc/changelog.d/4483.fixed.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Chown server-info file by client user in compose mode

doc/changelog.d/4484.fixed.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Chown server-info file by client user in compose mode - alt fix

src/ansys/fluent/core/docker/docker_compose.py

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2323
# SOFTWARE.
2424

25+
import os
2526
import subprocess
2627
import uuid
2728

@@ -31,7 +32,7 @@
3132
class ComposeBasedLauncher:
3233
"""Launch Fluent through docker or Podman compose."""
3334

34-
def __init__(self, compose_config, container_dict):
35+
def __init__(self, compose_config, container_dict, container_server_info_file):
3536
from ansys.fluent.core import config
3637

3738
self._compose_config = compose_config
@@ -45,6 +46,8 @@ def __init__(self, compose_config, container_dict):
4546
self._container_source = self._set_compose_cmds()
4647
self._container_source.remove("compose")
4748

49+
self._container_server_info_file = container_server_info_file
50+
4851
self._compose_file = self._get_compose_file(container_dict)
4952

5053
def _get_compose_file(self, container_dict):
@@ -243,3 +246,29 @@ def ports(self) -> list[str]:
243246
self._container_source + ["port", f"{self._compose_name}-fluent-1"],
244247
)
245248
return self._extract_ports(output.decode("utf-8").strip())
249+
250+
def chown_server_info_file(self) -> None:
251+
"""Change ownership of the server info file inside the container.
252+
253+
Raises
254+
------
255+
RuntimeError
256+
If the command fails.
257+
"""
258+
result = subprocess.run(
259+
self._container_source
260+
+ [
261+
"exec",
262+
f"{self._compose_name}-fluent-1",
263+
"chown",
264+
f"{os.getuid()}:{os.getgid()}",
265+
self._container_server_info_file,
266+
],
267+
capture_output=True,
268+
text=True,
269+
)
270+
if result.returncode != 0:
271+
raise RuntimeError(
272+
f"Failed to change ownership of the server info file. "
273+
f"Error: {result.stderr.strip()}"
274+
)

src/ansys/fluent/core/launcher/container_launcher.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,15 @@ def __call__(self):
231231
compose_config=self._compose_config,
232232
)
233233

234-
_, _, password = _get_server_info_from_container(config_dict=config_dict)
234+
try:
235+
_, _, password = _get_server_info_from_container(
236+
config_dict=config_dict
237+
)
238+
except PermissionError:
239+
container.chown_server_info_file()
240+
_, _, password = _get_server_info_from_container(
241+
config_dict=config_dict
242+
)
235243
else:
236244
port, password, container = start_fluent_container(
237245
self._args,

src/ansys/fluent/core/launcher/fluent_container.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ def configure_container_dict(
172172
file_transfer_service: Any | None = None,
173173
compose_config: ComposeConfig | None = None,
174174
**container_dict,
175-
) -> (dict, int, int, Path, bool):
175+
) -> (dict, int, int, Path, str, bool):
176176
"""Parses the parameters listed below, and sets up the container configuration file.
177177
178178
Parameters
@@ -218,6 +218,7 @@ def configure_container_dict(
218218
timeout : int
219219
port : int
220220
host_server_info_file : Path
221+
container_server_info_file: str
221222
remove_server_info_file: bool
222223
223224
Raises
@@ -353,8 +354,6 @@ def configure_container_dict(
353354
"FLUENT_ALLOW_REMOTE_GRPC_CONNECTION": "1",
354355
}
355356
)
356-
if compose_config.is_compose:
357-
container_dict["environment"]["FLUENT_SERVER_INFO_PERMISSION_SYSTEM"] = "1"
358357

359358
if "labels" not in container_dict:
360359
test_name = pyfluent.config.test_name
@@ -468,6 +467,7 @@ def configure_container_dict(
468467
timeout,
469468
container_grpc_port,
470469
host_server_info_file,
470+
container_server_info_file,
471471
remove_server_info_file,
472472
)
473473

@@ -528,6 +528,7 @@ def start_fluent_container(
528528
timeout,
529529
port,
530530
host_server_info_file,
531+
container_server_info_file,
531532
remove_server_info_file,
532533
) = container_vars
533534
launch_string = " ".join(config_dict["command"])
@@ -546,6 +547,7 @@ def start_fluent_container(
546547
compose_container = ComposeBasedLauncher(
547548
compose_config=compose_config,
548549
container_dict=config_dict,
550+
container_server_info_file=container_server_info_file,
549551
)
550552

551553
if not compose_container.check_image_exists():

0 commit comments

Comments
 (0)