From cb8ef97007b039e7ed91d2c21414d0d65b9479d6 Mon Sep 17 00:00:00 2001 From: Mario Ostieri Date: Tue, 13 Aug 2024 10:03:45 +0100 Subject: [PATCH 01/12] add team mate session to debug tests --- .github/workflows/ci_cd.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/ci_cd.yml b/.github/workflows/ci_cd.yml index e1c2e2d2..6c536b04 100644 --- a/.github/workflows/ci_cd.yml +++ b/.github/workflows/ci_cd.yml @@ -88,6 +88,10 @@ jobs: - name: Pull Docker container run: make pull-docker + + - name: Setup tmate session + uses: mxschmitt/action-tmate@v3 + - name: Run pytest uses: ansys/actions/tests-pytest@v4 env: From a1cfe5e9041d3efb56b5a930b2268a8ee67c1b04 Mon Sep 17 00:00:00 2001 From: Mario Ostieri Date: Tue, 13 Aug 2024 10:11:41 +0100 Subject: [PATCH 02/12] fix style --- .github/workflows/ci_cd.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/ci_cd.yml b/.github/workflows/ci_cd.yml index 6c536b04..3a9fc93d 100644 --- a/.github/workflows/ci_cd.yml +++ b/.github/workflows/ci_cd.yml @@ -88,7 +88,6 @@ jobs: - name: Pull Docker container run: make pull-docker - - name: Setup tmate session uses: mxschmitt/action-tmate@v3 From 33079ea5c841168298e3ef79de90a2963cb6eae3 Mon Sep 17 00:00:00 2001 From: Mario Ostieri Date: Wed, 21 Aug 2024 17:18:34 +0100 Subject: [PATCH 03/12] remove unique container name and get it from docker api --- .../dynamicreporting/core/docker_support.py | 17 ++++++++--------- tests/conftest.py | 2 -- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/src/ansys/dynamicreporting/core/docker_support.py b/src/ansys/dynamicreporting/core/docker_support.py index a7a9ea1b..cda1bd68 100644 --- a/src/ansys/dynamicreporting/core/docker_support.py +++ b/src/ansys/dynamicreporting/core/docker_support.py @@ -154,13 +154,13 @@ def start(self, host_directory: str, db_directory: str, port: int) -> None: } # get a unique name for the container to run - existing_names = [x.name for x in self._docker_client.from_env().containers.list()] - container_name = "nexus" - while container_name in existing_names: - container_name += random.choice(string.ascii_letters) - if len(container_name) > 500: - raise RuntimeError("Can't determine a unique Docker container name.") - self._container_name = container_name + #existing_names = [x.name for x in self._docker_client.from_env().containers.list()] + #container_name = "nexus" + #while container_name in existing_names: + # container_name += random.choice(string.ascii_letters) + # if len(container_name) > 500: + # raise RuntimeError("Can't determine a unique Docker container name.") + #self._container_name = container_name # Start the container in detached mode and override # the default entrypoint so multiple commands can be @@ -177,13 +177,12 @@ def start(self, host_directory: str, db_directory: str, port: int) -> None: volumes=data_volume, environment=container_env, ports=ports_to_map, - name=self._container_name, tty=True, detach=True, ) except Exception as e: # pragma: no cover raise RuntimeError("Can't run Docker container: " + self._image_name + "\n\n" + str(e)) - + self._container_name = self._container.name # Build up the command to run and send it to the container # as a detached command. # diff --git a/tests/conftest.py b/tests/conftest.py index 51934e87..b9de31d3 100755 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -58,7 +58,6 @@ def adr_service_create(request, pytestconfig: pytest.Config) -> Service: port=8000 + int(random() * 4000), ) else: - cleanup_docker(request) tmp_service = Service( ansys_installation="docker", docker_image=DOCKER_DEV_REPO_URL, @@ -80,7 +79,6 @@ def adr_service_query(request, pytestconfig: pytest.Config) -> Service: if use_local: ansys_installation = pytestconfig.getoption("install_path") else: - cleanup_docker(request) ansys_installation = "docker" tmp_service = Service( ansys_installation=ansys_installation, From 5f77700ce764a4f3a123fbd2ca638dae6a28fe71 Mon Sep 17 00:00:00 2001 From: Mario Ostieri Date: Wed, 21 Aug 2024 17:20:33 +0100 Subject: [PATCH 04/12] fix styling --- src/ansys/dynamicreporting/core/docker_support.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/ansys/dynamicreporting/core/docker_support.py b/src/ansys/dynamicreporting/core/docker_support.py index cda1bd68..0dd3080a 100644 --- a/src/ansys/dynamicreporting/core/docker_support.py +++ b/src/ansys/dynamicreporting/core/docker_support.py @@ -154,13 +154,13 @@ def start(self, host_directory: str, db_directory: str, port: int) -> None: } # get a unique name for the container to run - #existing_names = [x.name for x in self._docker_client.from_env().containers.list()] - #container_name = "nexus" - #while container_name in existing_names: + # existing_names = [x.name for x in self._docker_client.from_env().containers.list()] + # container_name = "nexus" + # while container_name in existing_names: # container_name += random.choice(string.ascii_letters) # if len(container_name) > 500: # raise RuntimeError("Can't determine a unique Docker container name.") - #self._container_name = container_name + # self._container_name = container_name # Start the container in detached mode and override # the default entrypoint so multiple commands can be From d661d30fc1e80d6e4abae49ac8cd5f38017a0498 Mon Sep 17 00:00:00 2001 From: Mario Ostieri Date: Thu, 22 Aug 2024 13:21:22 +0100 Subject: [PATCH 05/12] use port randomizer and global list of used ports to avoid --- .github/workflows/ci_cd.yml | 3 --- tests/conftest.py | 16 +++++++++++++--- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ci_cd.yml b/.github/workflows/ci_cd.yml index 3a9fc93d..e1c2e2d2 100644 --- a/.github/workflows/ci_cd.yml +++ b/.github/workflows/ci_cd.yml @@ -88,9 +88,6 @@ jobs: - name: Pull Docker container run: make pull-docker - - name: Setup tmate session - uses: mxschmitt/action-tmate@v3 - - name: Run pytest uses: ansys/actions/tests-pytest@v4 env: diff --git a/tests/conftest.py b/tests/conftest.py index b9de31d3..4e09e01f 100755 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -9,6 +9,7 @@ from ansys.dynamicreporting.core import Service from ansys.dynamicreporting.core.constants import DOCKER_DEV_REPO_URL +from ansys.dynamicreporting.core.utils.report_utils import find_unused_ports def pytest_addoption(parser): @@ -44,18 +45,23 @@ def get_exec(pytestconfig: pytest.Config) -> str: return exec_basis +used_ports = [] + + @pytest.fixture def adr_service_create(request, pytestconfig: pytest.Config) -> Service: + global used_ports use_local = pytestconfig.getoption("use_local_launcher") dir_name = "auto_delete_" + "".join(choice(ascii_letters) for x in range(5)) db_dir = os.path.join(os.path.join(request.fspath.dirname, "test_data"), dir_name) tmp_docker_dir = os.path.join(os.path.join(request.fspath.dirname, "test_data"), "tmp_docker") + port = find_unused_ports(1, avoid=used_ports)[0] if use_local: tmp_service = Service( ansys_installation=pytestconfig.getoption("install_path"), docker_image=DOCKER_DEV_REPO_URL, db_directory=db_dir, - port=8000 + int(random() * 4000), + port=port, ) else: tmp_service = Service( @@ -63,13 +69,15 @@ def adr_service_create(request, pytestconfig: pytest.Config) -> Service: docker_image=DOCKER_DEV_REPO_URL, db_directory=db_dir, data_directory=tmp_docker_dir, - port=8000 + int(random() * 4000), + port=port, ) + used_ports.append(port) return tmp_service @pytest.fixture def adr_service_query(request, pytestconfig: pytest.Config) -> Service: + global used_ports use_local = pytestconfig.getoption("use_local_launcher") local_db = os.path.join("test_data", "query_db") db_dir = os.path.join(request.fspath.dirname, local_db) @@ -80,13 +88,15 @@ def adr_service_query(request, pytestconfig: pytest.Config) -> Service: ansys_installation = pytestconfig.getoption("install_path") else: ansys_installation = "docker" + port = find_unused_ports(1, avoid=used_ports) tmp_service = Service( ansys_installation=ansys_installation, docker_image=DOCKER_DEV_REPO_URL, db_directory=db_dir, data_directory=tmp_docker_dir, - port=8000 + int(random() * 4000), + port=port, ) + used_ports.append(port) if not use_local: tmp_service._container.save_config() tmp_service.start(create_db=False, exit_on_close=True, delete_db=False) From a364b57e3fbca3d58204895f43417eebd183854e Mon Sep 17 00:00:00 2001 From: Mario Ostieri Date: Thu, 22 Aug 2024 13:35:50 +0100 Subject: [PATCH 06/12] start from 8000 --- tests/conftest.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index 4e09e01f..092247e0 100755 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -45,17 +45,19 @@ def get_exec(pytestconfig: pytest.Config) -> str: return exec_basis -used_ports = [] +used_ports = None @pytest.fixture def adr_service_create(request, pytestconfig: pytest.Config) -> Service: global used_ports + if not used_ports: + used_ports = [] use_local = pytestconfig.getoption("use_local_launcher") dir_name = "auto_delete_" + "".join(choice(ascii_letters) for x in range(5)) db_dir = os.path.join(os.path.join(request.fspath.dirname, "test_data"), dir_name) tmp_docker_dir = os.path.join(os.path.join(request.fspath.dirname, "test_data"), "tmp_docker") - port = find_unused_ports(1, avoid=used_ports)[0] + port = find_unused_ports(1, start=8000, avoid=used_ports)[0] if use_local: tmp_service = Service( ansys_installation=pytestconfig.getoption("install_path"), @@ -78,6 +80,8 @@ def adr_service_create(request, pytestconfig: pytest.Config) -> Service: @pytest.fixture def adr_service_query(request, pytestconfig: pytest.Config) -> Service: global used_ports + if not used_ports: + used_ports = [] use_local = pytestconfig.getoption("use_local_launcher") local_db = os.path.join("test_data", "query_db") db_dir = os.path.join(request.fspath.dirname, local_db) @@ -88,7 +92,7 @@ def adr_service_query(request, pytestconfig: pytest.Config) -> Service: ansys_installation = pytestconfig.getoption("install_path") else: ansys_installation = "docker" - port = find_unused_ports(1, avoid=used_ports) + port = find_unused_ports(1, start=8000, avoid=used_ports)[0] tmp_service = Service( ansys_installation=ansys_installation, docker_image=DOCKER_DEV_REPO_URL, From 48341a279c557c0f656dcdee7610b9518db993f4 Mon Sep 17 00:00:00 2001 From: Mario Ostieri Date: Thu, 22 Aug 2024 13:41:24 +0100 Subject: [PATCH 07/12] tmate debug --- .github/workflows/ci_cd.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/ci_cd.yml b/.github/workflows/ci_cd.yml index e1c2e2d2..3a9fc93d 100644 --- a/.github/workflows/ci_cd.yml +++ b/.github/workflows/ci_cd.yml @@ -88,6 +88,9 @@ jobs: - name: Pull Docker container run: make pull-docker + - name: Setup tmate session + uses: mxschmitt/action-tmate@v3 + - name: Run pytest uses: ansys/actions/tests-pytest@v4 env: From 340719267b343302033cd000170689548ed82570 Mon Sep 17 00:00:00 2001 From: Mario Ostieri Date: Thu, 22 Aug 2024 13:58:00 +0100 Subject: [PATCH 08/12] remove debug --- .github/workflows/ci_cd.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.github/workflows/ci_cd.yml b/.github/workflows/ci_cd.yml index 3a9fc93d..e1c2e2d2 100644 --- a/.github/workflows/ci_cd.yml +++ b/.github/workflows/ci_cd.yml @@ -88,9 +88,6 @@ jobs: - name: Pull Docker container run: make pull-docker - - name: Setup tmate session - uses: mxschmitt/action-tmate@v3 - - name: Run pytest uses: ansys/actions/tests-pytest@v4 env: From 44a2973796e93403519f0e7c9b485fcd6707c6de Mon Sep 17 00:00:00 2001 From: Mario Ostieri Date: Fri, 23 Aug 2024 15:44:09 +0100 Subject: [PATCH 09/12] add more debugging logs --- .../dynamicreporting/core/docker_support.py | 22 +++++++++++++++++++ tests/conftest.py | 2 ++ 2 files changed, 24 insertions(+) diff --git a/src/ansys/dynamicreporting/core/docker_support.py b/src/ansys/dynamicreporting/core/docker_support.py index 0dd3080a..ec1a973c 100644 --- a/src/ansys/dynamicreporting/core/docker_support.py +++ b/src/ansys/dynamicreporting/core/docker_support.py @@ -404,6 +404,28 @@ def save_config(self) -> str: ret = self.run_in_container(nexus_cmd) return ret + def status(self) -> str: + """ + Run the ``nexus_launcher save_config ...`` command in the Docker container. + + This command runs on the previously specified database directory. + + Returns + ------- + str + Output from the command. + + Raises + ------ + RuntimeError + """ + nexus_cmd = self._cei_home + "/bin/nexus_launcher" + nexus_cmd += " --db_directory /db_directory" + nexus_cmd += " status" + ret = self.run_in_container(nexus_cmd) + print(ret) + return ret + def launch_nexus_server( self, username: str, diff --git a/tests/conftest.py b/tests/conftest.py index 092247e0..50142221 100755 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -103,5 +103,7 @@ def adr_service_query(request, pytestconfig: pytest.Config) -> Service: used_ports.append(port) if not use_local: tmp_service._container.save_config() + tmp_service._container.status() + tmp_service._container.run_in_container("ls /db_directory/") tmp_service.start(create_db=False, exit_on_close=True, delete_db=False) return tmp_service From e9ebfacd03f19ff5703e25656a712abae803fc9b Mon Sep 17 00:00:00 2001 From: Mario Ostieri Date: Fri, 23 Aug 2024 15:44:26 +0100 Subject: [PATCH 10/12] add more debugging logs --- tests/conftest.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/conftest.py b/tests/conftest.py index 50142221..4d2290c9 100755 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -105,5 +105,6 @@ def adr_service_query(request, pytestconfig: pytest.Config) -> Service: tmp_service._container.save_config() tmp_service._container.status() tmp_service._container.run_in_container("ls /db_directory/") + tmp_service._container.run_in_container("cat /db_directory/nexus.log") tmp_service.start(create_db=False, exit_on_close=True, delete_db=False) return tmp_service From 391f9b209a91749097041659df69e14a09640a95 Mon Sep 17 00:00:00 2001 From: Mario Ostieri Date: Fri, 23 Aug 2024 15:45:12 +0100 Subject: [PATCH 11/12] add more debugging logs --- src/ansys/dynamicreporting/core/docker_support.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ansys/dynamicreporting/core/docker_support.py b/src/ansys/dynamicreporting/core/docker_support.py index ec1a973c..2b39979c 100644 --- a/src/ansys/dynamicreporting/core/docker_support.py +++ b/src/ansys/dynamicreporting/core/docker_support.py @@ -424,8 +424,8 @@ def status(self) -> str: nexus_cmd += " status" ret = self.run_in_container(nexus_cmd) print(ret) - return ret - + return ret + def launch_nexus_server( self, username: str, From bb578bf590751ff39c4604050f1c339a74b175ec Mon Sep 17 00:00:00 2001 From: Mario Ostieri Date: Fri, 23 Aug 2024 15:59:52 +0100 Subject: [PATCH 12/12] print logs --- tests/conftest.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index 4d2290c9..8c385f9b 100755 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -104,7 +104,8 @@ def adr_service_query(request, pytestconfig: pytest.Config) -> Service: if not use_local: tmp_service._container.save_config() tmp_service._container.status() - tmp_service._container.run_in_container("ls /db_directory/") - tmp_service._container.run_in_container("cat /db_directory/nexus.log") + print(tmp_service._container.run_in_container("ls /db_directory/")) + print(tmp_service._container.run_in_container("cat /db_directory/nexus.log")) tmp_service.start(create_db=False, exit_on_close=True, delete_db=False) + tmp_service._container.status() return tmp_service