From 0226f0e3f7062883dfaad43f1be28335f63ce8bd Mon Sep 17 00:00:00 2001 From: Sebastian Gumprich Date: Mon, 11 Jan 2021 17:17:51 +0100 Subject: [PATCH] Update tests (#86) * update tests to match upstream template * add python 3.5 support * fix linting * fix test * run integration tests on more pythons * run integration tests on more pythons * run integration tests on more pythons * remove py2.6 support --- .github/workflows/main.yml | 67 ++++++++++++++++++---------------- plugins/module_utils/icinga.py | 4 +- 2 files changed, 38 insertions(+), 33 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 9efa6ec5..5cc3e424 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -9,48 +9,48 @@ on: # This ensures that even if there haven't been commits that we are still testing against latest version of ansible-test for each ansible-base version schedule: - cron: '0 6 * * *' + +env: + NAMESPACE: t_systems_mms + COLLECTION_NAME: icinga_director + jobs: - ansible-sanity-tests: - name: Sanity (Ⓐ${{ matrix.ansible }}+py${{ matrix.python }}) + sanity: + name: Sanity (Ⓐ${{ matrix.ansible }}) strategy: matrix: ansible: - # It's important that Sanity is tested against all stable-X.Y branches - # Testing against `devel` may fail as new tests are added. - stable-2.9 - stable-2.10 - devel - python: - - 2.7 - - 3.7 - - 3.8 - exclude: - - python: 3.8 # blocked by ansible/ansible#70155 runs-on: ubuntu-latest steps: + # ansible-test requires the collection to be in a directory in the form - # .../ansible_collections/NAMESPACE/COLLECTION_NAME/ + # .../ansible_collections/${{env.NAMESPACE}}/${{env.COLLECTION_NAME}}/ - name: Check out code uses: actions/checkout@v2 with: - path: ansible_collections/t_systems_mms/icinga_director + path: ansible_collections/${{env.NAMESPACE}}/${{env.COLLECTION_NAME}} - - name: Set up Python ${{ matrix.ansible }} + - name: Set up Python uses: actions/setup-python@v2 with: - python-version: ${{ matrix.python }} + # it is just required to run that once as "ansible-test sanity" in the docker image + # will run on all python versions it supports. + python-version: 3.8 # Install the head of the given branch (devel, stable-2.10) - name: Install ansible-base (${{ matrix.ansible }}) - run: python -m pip install https://github.com/ansible/ansible/archive/${{ matrix.ansible }}.tar.gz --disable-pip-version-check + run: pip install https://github.com/ansible/ansible/archive/${{ matrix.ansible }}.tar.gz --disable-pip-version-check # run ansible-test sanity inside of Docker. - # The docker container has all the pinned dependencies that are required. - # Explicity specify the version of Python we want to test + # The docker container has all the pinned dependencies that are required + # and all python versions ansible supports. - name: Run sanity tests - run: ansible-test sanity --docker -v --color --python ${{ matrix.python }} - working-directory: ./ansible_collections/t_systems_mms/icinga_director + run: ansible-test sanity --docker -v --color + working-directory: ./ansible_collections/${{env.NAMESPACE}}/${{env.COLLECTION_NAME}} linting: name: Tox-Lint (py${{ matrix.python }}) @@ -65,7 +65,7 @@ jobs: - name: Check out code uses: actions/checkout@v2 with: - path: ansible_collections/t_systems_mms/icinga_director + path: ansible_collections/${{env.NAMESPACE}}/${{env.COLLECTION_NAME}} - name: Set up Python ${{ matrix.python }} uses: actions/setup-python@v2 @@ -77,10 +77,11 @@ jobs: - name: Run lint test run: tox -elinters -vv - working-directory: ./ansible_collections/t_systems_mms/icinga_director + working-directory: ansible_collections/${{env.NAMESPACE}}/${{env.COLLECTION_NAME}} - integration-tests: + integration: runs-on: ubuntu-latest + name: I (Ⓐ${{ matrix.ansible }}+py${{ matrix.python }}) strategy: fail-fast: false matrix: @@ -90,39 +91,43 @@ jobs: - devel python: - 2.7 + - 3.5 + - 3.6 - 3.7 + - 3.8 + - 3.9 exclude: - - python: 3.8 # blocked by ansible/ansible#70155 + # Because ansible-test doesn't support python3.9 for Ansible 2.9 + - ansible: stable-2.9 + python: 3.9 defaults: run: - working-directory: ansible_collections/t_systems_mms/icinga_director + working-directory: ansible_collections/${{env.NAMESPACE}}/${{env.COLLECTION_NAME}} services: icinga: image: jordan/icinga2 ports: - 80:80 steps: - - name: Check out code to collections-folder, so ansible finds it + - name: Check out code uses: actions/checkout@v2 with: - path: ansible_collections/t_systems_mms/icinga_director + path: ansible_collections/${{env.NAMESPACE}}/${{env.COLLECTION_NAME}} - - name: Set up Python ${{ matrix.ansible }} + - name: Set up Python ${{ matrix.python }} uses: actions/setup-python@v2 with: python-version: ${{ matrix.python }} - name: Install ansible-base (${{ matrix.ansible }}) - run: python -m pip install https://github.com/ansible/ansible/archive/${{ matrix.ansible }}.tar.gz --disable-pip-version-check + run: pip install https://github.com/ansible/ansible/archive/${{ matrix.ansible }}.tar.gz --disable-pip-version-check - name: Run integration tests run: ansible-test integration -v --color --retry-on-error --continue-on-error --diff --python ${{ matrix.python }} --requirements --coverage - working-directory: ./ansible_collections/t_systems_mms/icinga_director - # ansible-test support producing code coverage date + # ansible-test support producing code coverage date - name: Generate coverage report run: ansible-test coverage xml -v --requirements --group-by command --group-by version - working-directory: ./ansible_collections/t_systems_mms/icinga_director # See the reports at https://codecov.io/gh/T-Systems-MMS/ansible-collection-icinga-director - uses: codecov/codecov-action@v1 diff --git a/plugins/module_utils/icinga.py b/plugins/module_utils/icinga.py index 408bc6ce..54063c35 100644 --- a/plugins/module_utils/icinga.py +++ b/plugins/module_utils/icinga.py @@ -55,10 +55,10 @@ def call_url(self, path, data="", method="GET"): content = "" error = "" if rsp: - content = json.loads(rsp.read()) + content = json.loads(rsp.read().decode("utf-8")) if info["status"] >= 400: try: - content = json.loads(info["body"]) + content = json.loads(info["body"].decode("utf-8")) error = content["error"] except (ValueError, KeyError): error = info["msg"]