Skip to content

Commit

Permalink
Update tests (#86)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
rndmh3ro authored Jan 11, 2021
1 parent 3b06665 commit 0226f0e
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 33 deletions.
67 changes: 36 additions & 31 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }})
Expand All @@ -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
Expand All @@ -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:
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions plugins/module_utils/icinga.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down

0 comments on commit 0226f0e

Please sign in to comment.