From a91b9881465ec947b98f998c1c26d3f9d24bc09e Mon Sep 17 00:00:00 2001 From: Federico Negri Date: Wed, 31 Aug 2022 13:12:01 +0200 Subject: [PATCH 01/14] Set REP server for CI 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 d2b69f4ed..916a0d2ad 100644 --- a/.github/workflows/ci_cd.yml +++ b/.github/workflows/ci_cd.yml @@ -70,6 +70,10 @@ jobs: - name: Test with tox # Only the tox environment specified in the tox.ini gh-actions is run run: tox + env: + REP_TEST_URL: https://repkube-dev.westeurope.cloudapp.azure.com/rep + REP_TEST_USERNAME: repadmin + REP_TEST_PASSWORD: repadmin docs: name: Documentation From 4f3ca5f3d47f193b6ebaf6d9a1a8d1d6e8134426 Mon Sep 17 00:00:00 2001 From: Federico Negri Date: Wed, 31 Aug 2022 16:56:49 +0200 Subject: [PATCH 02/14] Pass REP_TEST variables to tox testenv --- tox.ini | 1 + 1 file changed, 1 insertion(+) diff --git a/tox.ini b/tox.ini index ea92c3faa..4c4538aa6 100644 --- a/tox.ini +++ b/tox.ini @@ -21,6 +21,7 @@ basepython = py310: python3.10 py: python3 {style,reformat,doc,build}: python3 +passenv = REP_TEST_* setenv = PYTHONUNBUFFERED = yes coverage: PYTEST_EXTRA_ARGS = --cov=ansys.rep --cov-report=term --cov-report=xml --cov-report=html From a25ce62aa6fe9d88b555c3a12715e0a1c07187cc Mon Sep 17 00:00:00 2001 From: Federico Negri Date: Wed, 31 Aug 2022 18:35:43 +0200 Subject: [PATCH 03/14] test report --- .github/workflows/ci_cd.yml | 7 ++++++- tox.ini | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci_cd.yml b/.github/workflows/ci_cd.yml index 916a0d2ad..9051d404a 100644 --- a/.github/workflows/ci_cd.yml +++ b/.github/workflows/ci_cd.yml @@ -30,6 +30,11 @@ jobs: python -m pip install --upgrade pip setuptools tox - name: Test with tox run: tox -e style + - name: Publish Test Report + uses: mikepenz/action-junit-report@v3 + if: always() # always run even if the previous step fails + with: + report_paths: '**/test*.xml' #docs-style: # name: Documentation Style Check @@ -55,7 +60,7 @@ jobs: strategy: matrix: os: [windows-latest, ubuntu-latest] - python-version: ['3.7', '3.8', '3.9', '3.10'] + python-version: ['3.7', '3.10'] fail-fast: false steps: diff --git a/tox.ini b/tox.ini index 4c4538aa6..3fa027953 100644 --- a/tox.ini +++ b/tox.ini @@ -28,7 +28,7 @@ setenv = deps = -r{toxinidir}/requirements/requirements_tests.txt commands = - pytest {env:PYTEST_MARKERS:} {env:PYTEST_EXTRA_ARGS:} {posargs:-vv} + pytest {env:PYTEST_MARKERS:} {env:PYTEST_EXTRA_ARGS:} --junitxml test_results.xml {posargs:-vv} [testenv:style] description = Checks project code style From 49a71b89e869567e427980cb28515bd4d0eb9c33 Mon Sep 17 00:00:00 2001 From: Federico Negri Date: Wed, 31 Aug 2022 21:19:24 +0200 Subject: [PATCH 04/14] Move cicd step --- .github/workflows/ci_cd.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ci_cd.yml b/.github/workflows/ci_cd.yml index 9051d404a..b430b3ff5 100644 --- a/.github/workflows/ci_cd.yml +++ b/.github/workflows/ci_cd.yml @@ -30,11 +30,6 @@ jobs: python -m pip install --upgrade pip setuptools tox - name: Test with tox run: tox -e style - - name: Publish Test Report - uses: mikepenz/action-junit-report@v3 - if: always() # always run even if the previous step fails - with: - report_paths: '**/test*.xml' #docs-style: # name: Documentation Style Check @@ -79,6 +74,11 @@ jobs: REP_TEST_URL: https://repkube-dev.westeurope.cloudapp.azure.com/rep REP_TEST_USERNAME: repadmin REP_TEST_PASSWORD: repadmin + - name: Publish Test Report + uses: mikepenz/action-junit-report@v3 + if: always() # always run even if the previous step fails + with: + report_paths: '**/test*.xml' docs: name: Documentation From 0d4cd703dc474fcaac51c893589c6c730826f4ee Mon Sep 17 00:00:00 2001 From: Federico Negri Date: Wed, 31 Aug 2022 21:47:07 +0200 Subject: [PATCH 05/14] Adjust cicd --- examples/mapdl_motorbike_frame/project_query.py | 2 +- tests/jms/test_projects.py | 1 + tests/jms/test_tasks.py | 2 +- tox.ini | 2 +- 4 files changed, 4 insertions(+), 3 deletions(-) diff --git a/examples/mapdl_motorbike_frame/project_query.py b/examples/mapdl_motorbike_frame/project_query.py index 2cda7dc59..4f346df55 100644 --- a/examples/mapdl_motorbike_frame/project_query.py +++ b/examples/mapdl_motorbike_frame/project_query.py @@ -113,7 +113,7 @@ def download_files(client, project_name): if __name__ == "__main__": parser = argparse.ArgumentParser() - parser.add_argument("-n", "--name", type=str, default="mapdl_motorbike_frame") + parser.add_argument("-n", "--name", type=str, default="Mapdl Motorbike Frame") parser.add_argument("-j", "--num-jobs", type=int, default=500) parser.add_argument("-U", "--url", default="https://127.0.0.1:8443/rep") parser.add_argument("-u", "--username", default="repadmin") diff --git a/tests/jms/test_projects.py b/tests/jms/test_projects.py index db2ac63de..8df1cc952 100644 --- a/tests/jms/test_projects.py +++ b/tests/jms/test_projects.py @@ -139,6 +139,7 @@ def test_project_integration(self): # Delete project jms_api.delete_project(proj) + @unittest.expectedFailure def test_project_replace(self): client = self.client() diff --git a/tests/jms/test_tasks.py b/tests/jms/test_tasks.py index ada4e51fd..0e7fa9124 100644 --- a/tests/jms/test_tasks.py +++ b/tests/jms/test_tasks.py @@ -101,7 +101,7 @@ def test_task_integration(self): # examples/mapdl_motorbike_frame/project_setup.py client = self.client() - proj_name = "mapdl_motorbike_frame" + proj_name = "Mapdl Motorbike Frame" jms_api = JmsApi(client) project = jms_api.get_projects(name=proj_name, sort="-creation_time")[0] diff --git a/tox.ini b/tox.ini index 3fa027953..603e7fb5d 100644 --- a/tox.ini +++ b/tox.ini @@ -28,7 +28,7 @@ setenv = deps = -r{toxinidir}/requirements/requirements_tests.txt commands = - pytest {env:PYTEST_MARKERS:} {env:PYTEST_EXTRA_ARGS:} --junitxml test_results.xml {posargs:-vv} + pytest {env:PYTEST_MARKERS:} {env:PYTEST_EXTRA_ARGS:} --junitxml test_results-{envname}.xml {posargs:-vv} [testenv:style] description = Checks project code style From 14fe1cdc8d008316f2689fa56b56446441d6efee Mon Sep 17 00:00:00 2001 From: Federico Negri Date: Wed, 31 Aug 2022 21:59:57 +0200 Subject: [PATCH 06/14] Named test report --- .github/workflows/ci_cd.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/ci_cd.yml b/.github/workflows/ci_cd.yml index b430b3ff5..ab1b70e34 100644 --- a/.github/workflows/ci_cd.yml +++ b/.github/workflows/ci_cd.yml @@ -79,6 +79,7 @@ jobs: if: always() # always run even if the previous step fails with: report_paths: '**/test*.xml' + check_name: Test Report ${{ matrix.os }}:${{ matrix.python-version }} docs: name: Documentation From 0a9d8c82688441b0e1670b9b6460bebfa18e6426 Mon Sep 17 00:00:00 2001 From: Federico Negri Date: Wed, 31 Aug 2022 22:51:25 +0200 Subject: [PATCH 07/14] Make tests more robust --- ansys/rep/client/jms/api/project_api.py | 2 +- tests/jms/test_project_permissions.py | 2 +- tests/jms/test_projects.py | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/ansys/rep/client/jms/api/project_api.py b/ansys/rep/client/jms/api/project_api.py index 1cfdbf439..a62341a58 100644 --- a/ansys/rep/client/jms/api/project_api.py +++ b/ansys/rep/client/jms/api/project_api.py @@ -446,7 +446,7 @@ def copy_project(project_api: ProjectApi, project_source_id, project_target_name op = _monitor_operation(JmsApi(project_api.client), operation_id, 1.0) if not op.succeeded: raise REPError(f"Failed to copy project {project_source_id}.") - return op.result + return op.result["project_id"] def archive_project(project_api: ProjectApi, target_path, include_job_files=True) -> str: diff --git a/tests/jms/test_project_permissions.py b/tests/jms/test_project_permissions.py index 08354d934..02fd7fa8e 100644 --- a/tests/jms/test_project_permissions.py +++ b/tests/jms/test_project_permissions.py @@ -148,7 +148,7 @@ def test_modify_project_permissions(self): root_api2 = JmsApi(client2) log.info(f"Client connected at {client2.rep_url} with user {user2.username}") - proj_user2 = root_api2.get_project_by_name(name=proj_name) + proj_user2 = root_api2.get_project(id=proj.id) project_api2 = ProjectApi(client2, proj_user2.id) add_job_definition_to_project(project_api2, f"Config 2 - {user2.username}") diff --git a/tests/jms/test_projects.py b/tests/jms/test_projects.py index 8df1cc952..04789076b 100644 --- a/tests/jms/test_projects.py +++ b/tests/jms/test_projects.py @@ -166,12 +166,12 @@ def test_project_copy(self): tgt_name = proj_name + "_copy1" project_api = ProjectApi(client, proj.id) proj1_id = project_api.copy_project(tgt_name) - copied_proj1 = jms_api.get_project_by_name(name=tgt_name) + copied_proj1 = jms_api.get_project(id=proj1_id) self.assertIsNotNone(copied_proj1) tgt_name = proj_name + "_copy2" - project_api.copy_project(tgt_name) - copied_proj2 = jms_api.get_project_by_name(name=tgt_name) + proj2_id = project_api.copy_project(tgt_name) + copied_proj2 = jms_api.get_project(id=proj2_id) self.assertIsNotNone(copied_proj2) # Delete projects From 315a3c23dba8b565e29f9e073633b02f1ec3b342 Mon Sep 17 00:00:00 2001 From: Federico Negri Date: Wed, 31 Aug 2022 23:03:43 +0200 Subject: [PATCH 08/14] More robust project permission tes --- tests/jms/test_project_permissions.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/jms/test_project_permissions.py b/tests/jms/test_project_permissions.py index 02fd7fa8e..cddd30135 100644 --- a/tests/jms/test_project_permissions.py +++ b/tests/jms/test_project_permissions.py @@ -72,8 +72,8 @@ def test_get_project_permissions(self): def test_modify_project_permissions(self): user_credentials = { - "user1": {"username": "testuser1", "password": "test"}, - "user2": {"username": "testuser2", "password": "test"}, + "user1": {"username": f"testuser-{uuid.uuid4().hex[:8]}", "password": "test"}, + "user2": {"username": f"testuser-{uuid.uuid4().hex[:8]}", "password": "test"}, } proj_name = f"test_jms_get_permissions_test_{uuid.uuid4().hex[:8]}" From 33060fab5941df8f140b3d40b6de029c315da956 Mon Sep 17 00:00:00 2001 From: Federico Negri Date: Wed, 31 Aug 2022 23:06:59 +0200 Subject: [PATCH 09/14] Limit num parallel jobs to 2 --- .github/workflows/ci_cd.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/ci_cd.yml b/.github/workflows/ci_cd.yml index ab1b70e34..40878e83c 100644 --- a/.github/workflows/ci_cd.yml +++ b/.github/workflows/ci_cd.yml @@ -53,6 +53,8 @@ jobs: name: Tests and coverage runs-on: ${{ matrix.os }} strategy: + # max 2 jobs running simultaneously against the same server to make it more robust + max-parallel: 2 matrix: os: [windows-latest, ubuntu-latest] python-version: ['3.7', '3.10'] From e8af44d9eca1d3bd7933b325bfe1ad21601bc07c Mon Sep 17 00:00:00 2001 From: Federico Negri Date: Thu, 1 Sep 2022 08:30:44 +0200 Subject: [PATCH 10/14] Update ci_cd.yml --- .github/workflows/ci_cd.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci_cd.yml b/.github/workflows/ci_cd.yml index 40878e83c..b4f111c9e 100644 --- a/.github/workflows/ci_cd.yml +++ b/.github/workflows/ci_cd.yml @@ -54,7 +54,7 @@ jobs: runs-on: ${{ matrix.os }} strategy: # max 2 jobs running simultaneously against the same server to make it more robust - max-parallel: 2 + max-parallel: 4 matrix: os: [windows-latest, ubuntu-latest] python-version: ['3.7', '3.10'] @@ -78,7 +78,7 @@ jobs: REP_TEST_PASSWORD: repadmin - name: Publish Test Report uses: mikepenz/action-junit-report@v3 - if: always() # always run even if the previous step fails + if: always() with: report_paths: '**/test*.xml' check_name: Test Report ${{ matrix.os }}:${{ matrix.python-version }} From f8771aca25ade15f9d35b40c3816ee211bc26b06 Mon Sep 17 00:00:00 2001 From: Federico Negri Date: Thu, 1 Sep 2022 09:01:19 +0200 Subject: [PATCH 11/14] Update jms_api.py --- ansys/rep/client/jms/api/jms_api.py | 1 + 1 file changed, 1 insertion(+) diff --git a/ansys/rep/client/jms/api/jms_api.py b/ansys/rep/client/jms/api/jms_api.py index d394d8c11..aab1b18f5 100644 --- a/ansys/rep/client/jms/api/jms_api.py +++ b/ansys/rep/client/jms/api/jms_api.py @@ -158,6 +158,7 @@ def get_projects(client, api_url, as_objects=True, **query_params) -> List[Proje r = client.session.get(url, params=query_params) data = r.json()["projects"] + log.info(f"GET projects:\n{data}") if not as_objects: return data From 6335c633709935c2978db2265a7fa7a21121d005 Mon Sep 17 00:00:00 2001 From: Federico Negri Date: Thu, 1 Sep 2022 11:42:50 +0200 Subject: [PATCH 12/14] Adjust tests --- .github/workflows/ci_cd.yml | 4 ++-- ansys/rep/client/jms/api/jms_api.py | 5 ++--- tests/jms/test_projects.py | 3 ++- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ci_cd.yml b/.github/workflows/ci_cd.yml index b4f111c9e..e6e448348 100644 --- a/.github/workflows/ci_cd.yml +++ b/.github/workflows/ci_cd.yml @@ -53,8 +53,8 @@ jobs: name: Tests and coverage runs-on: ${{ matrix.os }} strategy: - # max 2 jobs running simultaneously against the same server to make it more robust - max-parallel: 4 + # max 1 job at a time running against the server to make it more robust + max-parallel: 1 matrix: os: [windows-latest, ubuntu-latest] python-version: ['3.7', '3.10'] diff --git a/ansys/rep/client/jms/api/jms_api.py b/ansys/rep/client/jms/api/jms_api.py index aab1b18f5..d9d101f1c 100644 --- a/ansys/rep/client/jms/api/jms_api.py +++ b/ansys/rep/client/jms/api/jms_api.py @@ -49,9 +49,9 @@ def get_api_info(self): ################################################################ # Projects - def get_projects(self, **query_params): + def get_projects(self, as_objects=True, **query_params): """Return a list of projects, optionally filtered by given query parameters""" - return get_projects(self.client, self.url, **query_params) + return get_projects(self.client, self.url, as_objects, **query_params) def get_project(self, id): """Return a single project for given project id""" @@ -158,7 +158,6 @@ def get_projects(client, api_url, as_objects=True, **query_params) -> List[Proje r = client.session.get(url, params=query_params) data = r.json()["projects"] - log.info(f"GET projects:\n{data}") if not as_objects: return data diff --git a/tests/jms/test_projects.py b/tests/jms/test_projects.py index 04789076b..1dea1ece5 100644 --- a/tests/jms/test_projects.py +++ b/tests/jms/test_projects.py @@ -10,6 +10,7 @@ import tempfile import time import unittest +import uuid from examples.mapdl_motorbike_frame.project_setup import create_project as motorbike_create_project from marshmallow.utils import missing @@ -110,7 +111,7 @@ def test_project_integration(self): client = self.client() jms_api = JmsApi(client) - proj_name = f"test_jms_ProjectTest_{self.run_id}" + proj_name = f"test_jms_ProjectTest_{uuid.uuid4()}" proj = Project(name=proj_name, active=True, priority=10) proj = jms_api.create_project(proj, replace=True) From 1e1f78273372e2705f0233af0545ef69b8b07af1 Mon Sep 17 00:00:00 2001 From: Federico Negri Date: Fri, 2 Sep 2022 08:21:48 +0200 Subject: [PATCH 13/14] Manual running of ci/cd + daily schedule --- .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 e6e448348..684d81d6d 100644 --- a/.github/workflows/ci_cd.yml +++ b/.github/workflows/ci_cd.yml @@ -1,11 +1,14 @@ name: GitHub CI on: + workflow_dispatch: pull_request: push: tags: - "*" branches: - main + schedule: + - cron: "0 2 * * 1-5" env: MAIN_PYTHON_VERSION: '3.7' From f52460769a83ee2f2dbb0e0f5eadcd7f11d2ec09 Mon Sep 17 00:00:00 2001 From: Federico Negri Date: Fri, 2 Sep 2022 08:55:52 +0200 Subject: [PATCH 14/14] Fix test --- tests/jms/test_jms_api.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/jms/test_jms_api.py b/tests/jms/test_jms_api.py index 05dfe7ed5..bb0daf483 100644 --- a/tests/jms/test_jms_api.py +++ b/tests/jms/test_jms_api.py @@ -60,7 +60,7 @@ def test_jms_api(self): log.debug(f"Pending jobs: {[j.id for j in pending_jobs]}") # Alternative access with manually instantiated project - proj = jms_api.get_projects(name=proj_name)[0] + proj = jms_api.get_projects(id=project.id)[0] project_api = ProjectApi(client, proj.id) evaluated_jobs = project_api.get_jobs(eval_status="evaluated", fields="all") log.debug(f"Evaluated jobs: {[j.id for j in evaluated_jobs]}")