Skip to content

Commit 0226f0e

Browse files
authored
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
1 parent 3b06665 commit 0226f0e

2 files changed

Lines changed: 38 additions & 33 deletions

File tree

.github/workflows/main.yml

Lines changed: 36 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -9,48 +9,48 @@ on:
99
# 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
1010
schedule:
1111
- cron: '0 6 * * *'
12+
13+
env:
14+
NAMESPACE: t_systems_mms
15+
COLLECTION_NAME: icinga_director
16+
1217
jobs:
13-
ansible-sanity-tests:
14-
name: Sanity (Ⓐ${{ matrix.ansible }}+py${{ matrix.python }})
18+
sanity:
19+
name: Sanity (Ⓐ${{ matrix.ansible }})
1520
strategy:
1621
matrix:
1722
ansible:
18-
# It's important that Sanity is tested against all stable-X.Y branches
19-
# Testing against `devel` may fail as new tests are added.
2023
- stable-2.9
2124
- stable-2.10
2225
- devel
23-
python:
24-
- 2.7
25-
- 3.7
26-
- 3.8
27-
exclude:
28-
- python: 3.8 # blocked by ansible/ansible#70155
2926
runs-on: ubuntu-latest
3027
steps:
28+
3129
# ansible-test requires the collection to be in a directory in the form
32-
# .../ansible_collections/NAMESPACE/COLLECTION_NAME/
30+
# .../ansible_collections/${{env.NAMESPACE}}/${{env.COLLECTION_NAME}}/
3331

3432
- name: Check out code
3533
uses: actions/checkout@v2
3634
with:
37-
path: ansible_collections/t_systems_mms/icinga_director
35+
path: ansible_collections/${{env.NAMESPACE}}/${{env.COLLECTION_NAME}}
3836

39-
- name: Set up Python ${{ matrix.ansible }}
37+
- name: Set up Python
4038
uses: actions/setup-python@v2
4139
with:
42-
python-version: ${{ matrix.python }}
40+
# it is just required to run that once as "ansible-test sanity" in the docker image
41+
# will run on all python versions it supports.
42+
python-version: 3.8
4343

4444
# Install the head of the given branch (devel, stable-2.10)
4545
- name: Install ansible-base (${{ matrix.ansible }})
46-
run: python -m pip install https://github.com/ansible/ansible/archive/${{ matrix.ansible }}.tar.gz --disable-pip-version-check
46+
run: pip install https://github.com/ansible/ansible/archive/${{ matrix.ansible }}.tar.gz --disable-pip-version-check
4747

4848
# run ansible-test sanity inside of Docker.
49-
# The docker container has all the pinned dependencies that are required.
50-
# Explicity specify the version of Python we want to test
49+
# The docker container has all the pinned dependencies that are required
50+
# and all python versions ansible supports.
5151
- name: Run sanity tests
52-
run: ansible-test sanity --docker -v --color --python ${{ matrix.python }}
53-
working-directory: ./ansible_collections/t_systems_mms/icinga_director
52+
run: ansible-test sanity --docker -v --color
53+
working-directory: ./ansible_collections/${{env.NAMESPACE}}/${{env.COLLECTION_NAME}}
5454

5555
linting:
5656
name: Tox-Lint (py${{ matrix.python }})
@@ -65,7 +65,7 @@ jobs:
6565
- name: Check out code
6666
uses: actions/checkout@v2
6767
with:
68-
path: ansible_collections/t_systems_mms/icinga_director
68+
path: ansible_collections/${{env.NAMESPACE}}/${{env.COLLECTION_NAME}}
6969

7070
- name: Set up Python ${{ matrix.python }}
7171
uses: actions/setup-python@v2
@@ -77,10 +77,11 @@ jobs:
7777

7878
- name: Run lint test
7979
run: tox -elinters -vv
80-
working-directory: ./ansible_collections/t_systems_mms/icinga_director
80+
working-directory: ansible_collections/${{env.NAMESPACE}}/${{env.COLLECTION_NAME}}
8181

82-
integration-tests:
82+
integration:
8383
runs-on: ubuntu-latest
84+
name: I (Ⓐ${{ matrix.ansible }}+py${{ matrix.python }})
8485
strategy:
8586
fail-fast: false
8687
matrix:
@@ -90,39 +91,43 @@ jobs:
9091
- devel
9192
python:
9293
- 2.7
94+
- 3.5
95+
- 3.6
9396
- 3.7
97+
- 3.8
98+
- 3.9
9499
exclude:
95-
- python: 3.8 # blocked by ansible/ansible#70155
100+
# Because ansible-test doesn't support python3.9 for Ansible 2.9
101+
- ansible: stable-2.9
102+
python: 3.9
96103
defaults:
97104
run:
98-
working-directory: ansible_collections/t_systems_mms/icinga_director
105+
working-directory: ansible_collections/${{env.NAMESPACE}}/${{env.COLLECTION_NAME}}
99106
services:
100107
icinga:
101108
image: jordan/icinga2
102109
ports:
103110
- 80:80
104111
steps:
105-
- name: Check out code to collections-folder, so ansible finds it
112+
- name: Check out code
106113
uses: actions/checkout@v2
107114
with:
108-
path: ansible_collections/t_systems_mms/icinga_director
115+
path: ansible_collections/${{env.NAMESPACE}}/${{env.COLLECTION_NAME}}
109116

110-
- name: Set up Python ${{ matrix.ansible }}
117+
- name: Set up Python ${{ matrix.python }}
111118
uses: actions/setup-python@v2
112119
with:
113120
python-version: ${{ matrix.python }}
114121

115122
- name: Install ansible-base (${{ matrix.ansible }})
116-
run: python -m pip install https://github.com/ansible/ansible/archive/${{ matrix.ansible }}.tar.gz --disable-pip-version-check
123+
run: pip install https://github.com/ansible/ansible/archive/${{ matrix.ansible }}.tar.gz --disable-pip-version-check
117124

118125
- name: Run integration tests
119126
run: ansible-test integration -v --color --retry-on-error --continue-on-error --diff --python ${{ matrix.python }} --requirements --coverage
120-
working-directory: ./ansible_collections/t_systems_mms/icinga_director
121127

122-
# ansible-test support producing code coverage date
128+
# ansible-test support producing code coverage date
123129
- name: Generate coverage report
124130
run: ansible-test coverage xml -v --requirements --group-by command --group-by version
125-
working-directory: ./ansible_collections/t_systems_mms/icinga_director
126131

127132
# See the reports at https://codecov.io/gh/T-Systems-MMS/ansible-collection-icinga-director
128133
- uses: codecov/codecov-action@v1

plugins/module_utils/icinga.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,10 @@ def call_url(self, path, data="", method="GET"):
5555
content = ""
5656
error = ""
5757
if rsp:
58-
content = json.loads(rsp.read())
58+
content = json.loads(rsp.read().decode("utf-8"))
5959
if info["status"] >= 400:
6060
try:
61-
content = json.loads(info["body"])
61+
content = json.loads(info["body"].decode("utf-8"))
6262
error = content["error"]
6363
except (ValueError, KeyError):
6464
error = info["msg"]

0 commit comments

Comments
 (0)