From 6cded53f0e769b6becd87c7c01938038824fa827 Mon Sep 17 00:00:00 2001 From: ckunki Date: Wed, 6 Mar 2024 16:38:28 +0100 Subject: [PATCH] Fixed review findings --- exasol/ds/sandbox/lib/dss_docker/create_image.py | 2 +- .../ds/sandbox/runtime/ansible/general_setup_tasks.yml | 2 +- .../runtime/ansible/roles/entrypoint/files/entrypoint.py | 5 +++++ test/unit/entrypoint/test_main.py | 9 +++++---- 4 files changed, 12 insertions(+), 6 deletions(-) diff --git a/exasol/ds/sandbox/lib/dss_docker/create_image.py b/exasol/ds/sandbox/lib/dss_docker/create_image.py index 59a7f3fc..54c029a3 100644 --- a/exasol/ds/sandbox/lib/dss_docker/create_image.py +++ b/exasol/ds/sandbox/lib/dss_docker/create_image.py @@ -171,7 +171,7 @@ def _commit_container( "Cmd": [], "Volumes": {notebook_folder_final: {}, }, "ExposedPorts": {f"{port}/tcp": {}}, - "User": get_fact(facts, "docker_runner"), + "User": get_fact(facts, "docker_user"), "Env": [ f"VIRTUAL_ENV={virtualenv}", f"NOTEBOOK_FOLDER_FINAL={notebook_folder_final}", diff --git a/exasol/ds/sandbox/runtime/ansible/general_setup_tasks.yml b/exasol/ds/sandbox/runtime/ansible/general_setup_tasks.yml index 3b9a615f..116e5bb6 100644 --- a/exasol/ds/sandbox/runtime/ansible/general_setup_tasks.yml +++ b/exasol/ds/sandbox/runtime/ansible/general_setup_tasks.yml @@ -4,8 +4,8 @@ ansible.builtin.set_fact: dss_facts: entrypoint: "{{user_home}}/entrypoint.py" + docker_user: "{{ ansible_user }}" docker_group: "{{ docker_group }}" - docker_runner: "{{ ansible_user }}" jupyter: virtualenv: "{{ jupyter_virtualenv }}" command: "{{ jupyter_virtualenv }}/bin/jupyter-lab" diff --git a/exasol/ds/sandbox/runtime/ansible/roles/entrypoint/files/entrypoint.py b/exasol/ds/sandbox/runtime/ansible/roles/entrypoint/files/entrypoint.py index 05a09b3f..ebf7987d 100644 --- a/exasol/ds/sandbox/runtime/ansible/roles/entrypoint/files/entrypoint.py +++ b/exasol/ds/sandbox/runtime/ansible/roles/entrypoint/files/entrypoint.py @@ -188,6 +188,11 @@ def id(self): self._id = grp.getgrnam(self.name).gr_gid return self._id + def __eq__(self, other) -> bool: + if not isinstance(other, Group): + return False + return other.name == self.name + class User: def __init__(self, user_name: str, group: Group, docker_group: Group): diff --git a/test/unit/entrypoint/test_main.py b/test/unit/entrypoint/test_main.py index 83ffcac2..97a30d05 100644 --- a/test/unit/entrypoint/test_main.py +++ b/test/unit/entrypoint/test_main.py @@ -32,10 +32,11 @@ def test_user_arg(mocker): mocker.patch(entrypoint_method("sleep_infinity")) entrypoint.main() assert entrypoint.User.called - args = entrypoint.User.call_args[0] - assert args[0] == "jennifer" - assert args[1].name == "users" - assert args[2].name == "docker" + args = entrypoint.User.call_args = mocker.call( + "jennifer", + entrypoint.Group("users"), + entrypoint.Group("docker"), + ) assert user.own.called assert user.own.call_args == mocker.call("/var/run/docker.sock") assert user.switch_to.called