From edd8af585daa1e2b3a718753ed0c113b593068fa Mon Sep 17 00:00:00 2001 From: Felin Tusun Date: Fri, 5 Jan 2024 23:35:00 +0100 Subject: [PATCH 1/5] chore: :wrench: update requirements and adjust tooling This splits and updates the requirements files so we only install ansible in the ci. This switches the python formatter to use Ruff. such faster. This switches the recommended linter to pylint. provided lints are more digestible and maybe enough. no need for pylama. additionally updated dependencies to new versions --- .gitlab-ci.yml | 8 +++++--- .vscode/extensions.json | 7 +++++-- .vscode/settings.json | 6 +++--- CONTRIBUTING.md | 2 +- .../paessler/prtg/tests/sanity/ignore-2.16.txt | 2 ++ .../paessler/prtg/tests/unit/requirements.txt | 2 +- requirements.txt | 12 ++++-------- requirements_dev.txt | 8 ++++++++ 8 files changed, 29 insertions(+), 18 deletions(-) create mode 100644 ansible_collections/paessler/prtg/tests/sanity/ignore-2.16.txt create mode 100644 requirements_dev.txt diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index c205f96..a94c873 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -15,7 +15,7 @@ ansible-test-sanity: stage: lint script: - apt-get update && apt-get install git -y - - python3 -m pip install -r ${CI_PROJECT_DIR}/requirements.txt + - python3 -m pip install -r ${CI_PROJECT_DIR}/requirements_dev.txt - cd ${CI_PROJECT_DIR}/ansible_collections/paessler/prtg - echo "ready to run sanity tests" - ansible-test sanity --python 3.9 @@ -26,7 +26,7 @@ test-job: stage: test script: - apt-get update && apt-get install git -y - - python3 -m pip install -r ${CI_PROJECT_DIR}/requirements.txt + - python3 -m pip install -r ${CI_PROJECT_DIR}/requirements_dev.txt - cd ${CI_PROJECT_DIR}/ansible_collections/paessler/prtg - ansible-test units --venv --python 3.9 --coverage --requirements - ansible-test integration --coverage --requirements @@ -49,7 +49,7 @@ ansible-galaxy-build: stage: build script: - apt-get update && apt-get install git -y - - python3 -m pip install -r ${CI_PROJECT_DIR}/requirements.txt + - python3 -m pip install -r ${CI_PROJECT_DIR}/requirements_dev.txt - ansible-galaxy collection build ${CI_PROJECT_DIR}/ansible_collections/paessler/prtg artifacts: paths: @@ -60,5 +60,7 @@ ansible-galaxy-build: extends: - .RUNNER_TAGS stage: build + needs: + - ansible-galaxy-build script: - echo "not implemented" diff --git a/.vscode/extensions.json b/.vscode/extensions.json index 6b5d852..e092c13 100644 --- a/.vscode/extensions.json +++ b/.vscode/extensions.json @@ -1,6 +1,9 @@ { "recommendations": [ - "redhat.vscode-yaml", - "redhat.ansible" + "charliermarsh.ruff", + "ms-python.pylint", + "ms-python.python", + "redhat.ansible", + "redhat.vscode-yaml" ] } diff --git a/.vscode/settings.json b/.vscode/settings.json index 5e3999b..5c0b116 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,14 +1,14 @@ { - "python.linting.pylamaEnabled": true, - "python.linting.enabled": true, "git.ignoreLimitWarning": true, "yaml.format.enable": false, "yaml.format.bracketSpacing": false, "python.testing.pytestArgs": ["ansible_collections"], "python.testing.unittestEnabled": false, "python.testing.pytestEnabled": true, + "python.linting.enabled": true, "cSpell.enabled": false, "[python]": { - "editor.defaultFormatter": "ms-python.black-formatter" + "editor.formatOnSave": true, + "editor.defaultFormatter": "charliermarsh.ruff", } } diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index a1b51b0..460afae 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -41,7 +41,7 @@ The sections below outline the steps in each case. ansible-test integration --coverage --requirements ``` 1. Add your own tests (if necessary). -1. Confirm that everything is formatted using [Black](https://black.readthedocs.io/en/stable/). +1. Confirm that everything is formatted using [Ruff](https://docs.astral.sh/ruff/). 1. Update the documentation. 1. Push your feature branch to the repository. 1. Create a Merge Request; diff --git a/ansible_collections/paessler/prtg/tests/sanity/ignore-2.16.txt b/ansible_collections/paessler/prtg/tests/sanity/ignore-2.16.txt new file mode 100644 index 0000000..c03a688 --- /dev/null +++ b/ansible_collections/paessler/prtg/tests/sanity/ignore-2.16.txt @@ -0,0 +1,2 @@ +plugins/modules/device_pause.py validate-modules:missing-gplv3-license # ignore license check +plugins/modules/device_resume.py validate-modules:missing-gplv3-license # ignore license check diff --git a/ansible_collections/paessler/prtg/tests/unit/requirements.txt b/ansible_collections/paessler/prtg/tests/unit/requirements.txt index 996dd88..76756c6 100644 --- a/ansible_collections/paessler/prtg/tests/unit/requirements.txt +++ b/ansible_collections/paessler/prtg/tests/unit/requirements.txt @@ -1,3 +1,3 @@ -pytest==7.1.3 +pytest==7.4.4 mock==4.0.3 epdb diff --git a/requirements.txt b/requirements.txt index 7df8d66..e13a06e 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,8 +1,4 @@ -ansible-core==2.15.4 -ansible-lint==6.20.1 -ansible==8.4.0 -black==23.9.1 -connexion==2.14.2 -openapi-spec-validator==0.6.0 -pylama==8.4.1 -pytest==7.4.2 +# common requirements file. in many cases we only need ansible +ansible-core==9.1.0 +ansible-lint==6.22.1 +ansible==9.1.0 diff --git a/requirements_dev.txt b/requirements_dev.txt new file mode 100644 index 0000000..4fce8e6 --- /dev/null +++ b/requirements_dev.txt @@ -0,0 +1,8 @@ +# This requirements file contains packages needed for development +# include default requirements +-r requirements.txt +connexion==3.0.5 +openapi-spec-validator==0.7.1 +pylint==3.0.3 +pytest==7.4.4 +ruff==1.16.1 -- GitLab From 048b67cf649adecf78a22d0b40fc9c0820d41236 Mon Sep 17 00:00:00 2001 From: Felin Tusun Date: Fri, 5 Jan 2024 23:54:16 +0100 Subject: [PATCH 2/5] build(ansible-galaxy): :wrench: Add required runtime.yml for galaxy publish The ansible-galaxy collection init command we used in older ansible version did not create the runtime.yml that is required for publishing to galaxy. I copied it over from a fresh init with recent ansible-galaxy command. Added the commented section about collection manifest into galaxy.yml. --- ansible_collections/paessler/prtg/galaxy.yml | 7 +++ .../paessler/prtg/meta/runtime.yml | 52 +++++++++++++++++++ 2 files changed, 59 insertions(+) create mode 100644 ansible_collections/paessler/prtg/meta/runtime.yml diff --git a/ansible_collections/paessler/prtg/galaxy.yml b/ansible_collections/paessler/prtg/galaxy.yml index d54edf1..b85e630 100644 --- a/ansible_collections/paessler/prtg/galaxy.yml +++ b/ansible_collections/paessler/prtg/galaxy.yml @@ -62,3 +62,10 @@ issues: https://gitlab.com/PRTG/prtg-ansible/-/issues # uses 'fnmatch' to match the files or directories. Some directories and files like 'galaxy.yml', '*.pyc', '*.retry', # and '.git' are always filtered build_ignore: [] + +# A dict controlling use of manifest directives used in building the collection artifact. The key 'directives' is a +# list of MANIFEST.in style +# L(directives,https://packaging.python.org/en/latest/guides/using-manifest-in/#manifest-in-commands). The key +# 'omit_default_directives' is a boolean that controls whether the default directives are used. Mutually exclusive +# with 'build_ignore' +# manifest: null diff --git a/ansible_collections/paessler/prtg/meta/runtime.yml b/ansible_collections/paessler/prtg/meta/runtime.yml new file mode 100644 index 0000000..2fe301c --- /dev/null +++ b/ansible_collections/paessler/prtg/meta/runtime.yml @@ -0,0 +1,52 @@ +--- +# Collections must specify a minimum required ansible version to upload +# to galaxy +requires_ansible: '>=2.9.10' + +# Content that Ansible needs to load from another location or that has +# been deprecated/removed +# plugin_routing: +# action: +# redirected_plugin_name: +# redirect: ns.col.new_location +# deprecated_plugin_name: +# deprecation: +# removal_version: "4.0.0" +# warning_text: | +# See the porting guide on how to update your playbook to +# use ns.col.another_plugin instead. +# removed_plugin_name: +# tombstone: +# removal_version: "2.0.0" +# warning_text: | +# See the porting guide on how to update your playbook to +# use ns.col.another_plugin instead. +# become: +# cache: +# callback: +# cliconf: +# connection: +# doc_fragments: +# filter: +# httpapi: +# inventory: +# lookup: +# module_utils: +# modules: +# netconf: +# shell: +# strategy: +# terminal: +# test: +# vars: + +# Python import statements that Ansible needs to load from another location +# import_redirection: +# ansible_collections.ns.col.plugins.module_utils.old_location: +# redirect: ansible_collections.ns.col.plugins.module_utils.new_location + +# Groups of actions/modules that take a common set of options +# action_groups: +# group_name: +# - module1 +# - module2 -- GitLab From d1edb2f95f8daed2aa878a2abf6eaaaa7c35c75e Mon Sep 17 00:00:00 2001 From: Felin Tusun Date: Sat, 6 Jan 2024 00:29:00 +0100 Subject: [PATCH 3/5] chore: :adhesive_bandage: set correct package versions adjust installed req.txt in ci --- .gitlab-ci.yml | 12 ++++++------ requirements.txt | 2 +- requirements_dev.txt | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index a94c873..6d6cf7e 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -14,8 +14,8 @@ ansible-test-sanity: - .RUNNER_TAGS stage: lint script: - - apt-get update && apt-get install git -y - - python3 -m pip install -r ${CI_PROJECT_DIR}/requirements_dev.txt + - apt-get update && apt-get --no-install-recommends --no-install-suggests --yes install git + - python3 -m pip install -r ${CI_PROJECT_DIR}/requirements.txt - cd ${CI_PROJECT_DIR}/ansible_collections/paessler/prtg - echo "ready to run sanity tests" - ansible-test sanity --python 3.9 @@ -25,8 +25,8 @@ test-job: - .RUNNER_TAGS stage: test script: - - apt-get update && apt-get install git -y - - python3 -m pip install -r ${CI_PROJECT_DIR}/requirements_dev.txt + - apt-get update && apt-get --no-install-recommends --no-install-suggests --yes install git + - python3 -m pip install -r ${CI_PROJECT_DIR}/requirements.txt - cd ${CI_PROJECT_DIR}/ansible_collections/paessler/prtg - ansible-test units --venv --python 3.9 --coverage --requirements - ansible-test integration --coverage --requirements @@ -48,8 +48,8 @@ ansible-galaxy-build: - .RUNNER_TAGS stage: build script: - - apt-get update && apt-get install git -y - - python3 -m pip install -r ${CI_PROJECT_DIR}/requirements_dev.txt + - apt-get update && apt-get --no-install-recommends --no-install-suggests --yes install git + - python3 -m pip install -r ${CI_PROJECT_DIR}/requirements.txt - ansible-galaxy collection build ${CI_PROJECT_DIR}/ansible_collections/paessler/prtg artifacts: paths: diff --git a/requirements.txt b/requirements.txt index e13a06e..961f62a 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ # common requirements file. in many cases we only need ansible -ansible-core==9.1.0 +ansible-core==2.16.2 ansible-lint==6.22.1 ansible==9.1.0 diff --git a/requirements_dev.txt b/requirements_dev.txt index 4fce8e6..d34d2f8 100644 --- a/requirements_dev.txt +++ b/requirements_dev.txt @@ -5,4 +5,4 @@ connexion==3.0.5 openapi-spec-validator==0.7.1 pylint==3.0.3 pytest==7.4.4 -ruff==1.16.1 +ruff==0.1.11 -- GitLab From d39a0286f8d2a8cbe91d834bc725c28c7561842b Mon Sep 17 00:00:00 2001 From: Felin Tusun <7155809-felintusun@users.noreply.gitlab.com> Date: Fri, 12 Jan 2024 21:16:14 +0000 Subject: [PATCH 4/5] chore: update python Update the image used in the CI. Adjust the ansible-test invocation use venv and remove specific ptyhon parameter --- .gitlab-ci.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 6d6cf7e..aae8d4b 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,7 +1,7 @@ .RUNNER_TAGS: &RUNNER_TAGS tags: - gitlab-org-docker - image: "python:3.9.18-slim-bullseye" + image: "python:3.11.7-slim-bookworm" stages: - lint @@ -18,7 +18,7 @@ ansible-test-sanity: - python3 -m pip install -r ${CI_PROJECT_DIR}/requirements.txt - cd ${CI_PROJECT_DIR}/ansible_collections/paessler/prtg - echo "ready to run sanity tests" - - ansible-test sanity --python 3.9 + - ansible-test sanity --venv test-job: extends: @@ -28,7 +28,7 @@ test-job: - apt-get update && apt-get --no-install-recommends --no-install-suggests --yes install git - python3 -m pip install -r ${CI_PROJECT_DIR}/requirements.txt - cd ${CI_PROJECT_DIR}/ansible_collections/paessler/prtg - - ansible-test units --venv --python 3.9 --coverage --requirements + - ansible-test units --venv --coverage --requirements - ansible-test integration --coverage --requirements - ansible-test coverage xml - ansible-test coverage html -- GitLab From 6107d7237fe0a31291f313aebc4961b855c2c1b2 Mon Sep 17 00:00:00 2001 From: Felin Tusun <7155809-felintusun@users.noreply.gitlab.com> Date: Fri, 12 Jan 2024 22:42:21 +0000 Subject: [PATCH 5/5] chore: set LANG for ansible-test sanity The ansible-test sanity command hinted to having set C.UTF-8 as locale which could lead to unexpected behaviour in some tests. --- .gitignore | 2 ++ .gitlab-ci.yml | 7 +++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 94746db..faf505e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,8 @@ *venv* __pycache__ bot +.ruff_cache +.pytest_cache ansible_collections/paessler/prtg/tests/output/ ansible_collections/paessler/prtg/tests/integration/inventory diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index aae8d4b..6224baa 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -13,12 +13,15 @@ ansible-test-sanity: extends: - .RUNNER_TAGS stage: lint + before_script: + - apt-get update + - apt-get install --yes locales locales-all + - apt-get --no-install-recommends --no-install-suggests --yes install git shellcheck script: - - apt-get update && apt-get --no-install-recommends --no-install-suggests --yes install git - python3 -m pip install -r ${CI_PROJECT_DIR}/requirements.txt - cd ${CI_PROJECT_DIR}/ansible_collections/paessler/prtg - echo "ready to run sanity tests" - - ansible-test sanity --venv + - LANG=en_US.UTF-8 ansible-test sanity --venv test-job: extends: -- GitLab