Skip to content

Commit e57c612

Browse files
Setup github ci for pytest tests including static analysis
1 parent 15a1e48 commit e57c612

File tree

2 files changed

+370
-0
lines changed

2 files changed

+370
-0
lines changed

.github/workflows/ci.yml

Lines changed: 293 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,293 @@
1+
name: CI
2+
on:
3+
push:
4+
#branches: [master]
5+
pull_request:
6+
#branches: [master]
7+
concurrency:
8+
group: ${{ github.workflow }}-${{ github.ref }}
9+
cancel-in-progress: true
10+
jobs:
11+
tox:
12+
strategy:
13+
fail-fast: false
14+
matrix:
15+
python-version: ["3.11", "3.x"]
16+
upstream: ["pypi"]
17+
runs-on: ubuntu-latest
18+
permissions:
19+
contents: read
20+
steps:
21+
- name: Detect skipped environments
22+
id: skipenv
23+
env:
24+
UPSTREAM: ${{ matrix.upstream }}
25+
run: |
26+
set -ex
27+
case $UPSTREAM in
28+
upstream)
29+
echo 'skipenv=.*(?<!upstream)$' >> $GITHUB_OUTPUT
30+
;;
31+
*)
32+
echo 'skipenv=.*-upstream$' >> $GITHUB_OUTPUT
33+
;;
34+
esac
35+
- uses: actions/checkout@v3
36+
- uses: actions/setup-python@v4
37+
with:
38+
python-version: ${{ matrix.python-version }}
39+
- name: Install dependencies
40+
run: |
41+
sudo apt-get update
42+
43+
# Install dependencies for python-ldap
44+
sudo apt-get install -y libsasl2-dev python3-dev libldap2-dev libssl-dev libssh-dev
45+
46+
python -m pip install --upgrade pip
47+
pip install tox tox-gh
48+
- name: Prepare tox environment and install packages
49+
run: |
50+
tox --skip-env '${{ steps.skipenv.outputs.skipenv }}' --colored=yes --notest
51+
- name: Run tests
52+
run: |
53+
tox --skip-env '${{ steps.skipenv.outputs.skipenv }}' --colored=yes --skip-pkg-install
54+
55+
system:
56+
strategy:
57+
fail-fast: false
58+
matrix:
59+
tag:
60+
- fedora-latest
61+
runs-on: ubuntu-latest
62+
permissions:
63+
contents: read
64+
steps:
65+
- uses: actions/setup-python@v5
66+
with:
67+
python-version: 3.x
68+
69+
- name: Checkout sssd-test-framework repository
70+
uses: actions/checkout@v5
71+
with:
72+
# Fetch the entire history of the repository and tags to determine
73+
# correct framework version, as it is constructed from git describe
74+
repository: sssd/sssd-test-framework
75+
fetch-depth: 0
76+
fetch-tags: true
77+
path: sssd-test-framework
78+
79+
- name: Checkout sudo-tests repository
80+
uses: actions/checkout@v5
81+
with:
82+
repository: RedHat-SP-Security/sudo-tests
83+
path: sudo-tests
84+
85+
- name: Setup containers
86+
uses: SSSD/sssd-ci-containers/actions/setup@master
87+
with:
88+
path: sssd-ci-containers
89+
tag: ${{ matrix.tag }}
90+
override: |
91+
services:
92+
dns:
93+
restart: always
94+
image: ${REGISTRY}/ci-dns:latest
95+
container_name: dns
96+
env_file: ./env.containers
97+
volumes:
98+
- ./data/configs/dnsmasq.conf:/etc/dnsmasq.conf
99+
cap_add:
100+
- NET_RAW
101+
- NET_ADMIN
102+
- SYS_CHROOT
103+
security_opt:
104+
- apparmor=unconfined
105+
- label=disable
106+
- seccomp=unconfined
107+
networks:
108+
sssd:
109+
ipv4_address: 172.16.100.2
110+
ipa:
111+
image: ${REGISTRY}/ci-ipa:${TAG}
112+
container_name: ipa
113+
hostname: master.ipa.test
114+
dns: 172.16.100.2
115+
env_file: ./env.containers
116+
volumes:
117+
- ./shared:/shared:rw
118+
cap_add:
119+
- SYS_ADMIN
120+
- SYS_PTRACE
121+
- AUDIT_WRITE
122+
- AUDIT_CONTROL
123+
- SYS_CHROOT
124+
- NET_ADMIN
125+
- CAP_CHOWN
126+
- CAP_DAC_OVERRIDE
127+
- CAP_SETGID
128+
- CAP_SETUID
129+
- CAP_DAC_READ_SEARCH
130+
security_opt:
131+
- apparmor=unconfined
132+
- label=disable
133+
- seccomp=unconfined
134+
networks:
135+
sssd:
136+
ipv4_address: 172.16.100.10
137+
ldap:
138+
image: ${REGISTRY}/ci-ldap:${TAG}
139+
container_name: ldap
140+
hostname: master.ldap.test
141+
dns: 172.16.100.2
142+
env_file: ./env.containers
143+
volumes:
144+
- ./shared:/shared:rw
145+
cap_add:
146+
- SYS_ADMIN
147+
- SYS_PTRACE
148+
- AUDIT_WRITE
149+
- AUDIT_CONTROL
150+
- SYS_CHROOT
151+
- NET_ADMIN
152+
security_opt:
153+
- apparmor=unconfined
154+
- label=disable
155+
- seccomp=unconfined
156+
networks:
157+
sssd:
158+
ipv4_address: 172.16.100.20
159+
client:
160+
image: ${REGISTRY}/ci-client:${TAG}
161+
container_name: client
162+
hostname: client.test
163+
dns: 172.16.100.2
164+
env_file: ./env.containers
165+
volumes:
166+
- ./shared:/shared:rw
167+
cap_add:
168+
- SYS_ADMIN
169+
- SYS_PTRACE
170+
- NET_RAW
171+
- NET_ADMIN
172+
- AUDIT_WRITE
173+
- AUDIT_CONTROL
174+
- SYS_CHROOT
175+
- CAP_CHOWN
176+
- CAP_DAC_OVERRIDE
177+
- CAP_SETGID
178+
- CAP_SETUID
179+
- CAP_DAC_READ_SEARCH
180+
security_opt:
181+
- apparmor=unconfined
182+
- label=disable
183+
- seccomp=unconfined
184+
networks:
185+
sssd:
186+
ipv4_address: 172.16.100.40
187+
networks:
188+
sssd:
189+
name: sssd-ci
190+
driver: bridge
191+
ipam:
192+
config:
193+
- subnet: 172.16.100.0/24
194+
gateway: 172.16.100.1
195+
options:
196+
driver: host-local
197+
198+
- name: Patch the SSH configuration
199+
uses: SSSD/sssd-ci-containers/actions/exec@master
200+
with:
201+
user: root
202+
script: |
203+
#!/bin/bash
204+
test -x /usr/bin/sss_ssh_knownhosts && \
205+
sed -e 's/GlobalKnownHostsFile/#GlobalKnownHostsFile/' \
206+
-e 's/ProxyCommand \/usr\/bin\/sss_ssh_knownhostsproxy -p %p %h/KnownHostsCommand \/usr\/bin\/sss_ssh_knownhosts %H/' \
207+
-i /etc/ssh/ssh_config.d/04-ipa.conf
208+
209+
- name: Install system tests dependencies
210+
shell: bash
211+
working-directory: ./sudo-tests/pytest
212+
run: |
213+
set -ex
214+
215+
sudo apt-get update
216+
217+
# Install dependencies for python-ldap
218+
sudo apt-get install -y libsasl2-dev python3-dev libldap2-dev libssl-dev libssh-dev
219+
220+
# Virtualenv
221+
pip3 install virtualenv
222+
python3 -m venv .venv
223+
source .venv/bin/activate
224+
225+
# Install system tests requirements
226+
pip3 install -r ./requirements.txt
227+
228+
# Install yq to parse yaml files
229+
sudo wget -qO /usr/local/bin/yq https://github.com/mikefarah/yq/releases/latest/download/yq_linux_amd64
230+
sudo chmod a+x /usr/local/bin/yq
231+
232+
- name: Install test framework
233+
shell: bash
234+
run: |
235+
set -ex
236+
237+
source ./sudo-tests/pytest/.venv/bin/activate
238+
pip3 install ./sssd-test-framework
239+
240+
- name: Remove ad from mhc.yaml
241+
shell: bash
242+
working-directory: ./sudo-tests/pytest
243+
run: |
244+
yq -i 'del(.domains[0].hosts.[] | select(.role == "ad"))' mhc.yaml
245+
246+
- name: Check polarion metadata
247+
shell: bash
248+
working-directory: ./sudo-tests/pytest
249+
run: |
250+
# Run pytest in collect only mode to quickly catch issues in Polarion metadata.
251+
set -ex -o pipefail
252+
253+
mkdir -p $GITHUB_WORKSPACE/artifacts
254+
source .venv/bin/activate
255+
pytest \
256+
--color=yes \
257+
--mh-config=./mhc.yaml \
258+
--mh-artifacts-dir=$GITHUB_WORKSPACE/artifacts \
259+
--polarion-config=../polarion.yaml \
260+
--output-polarion-testcase=$GITHUB_WORKSPACE/artifacts/testcase.xml \
261+
--collect-only . |& tee $GITHUB_WORKSPACE/pytest-collect.log
262+
263+
- name: Run tests
264+
shell: bash
265+
working-directory: ./sudo-tests/pytest/
266+
run: |
267+
set -ex -o pipefail
268+
269+
mkdir -p $GITHUB_WORKSPACE/artifacts
270+
source .venv/bin/activate
271+
pytest \
272+
--durations=0 \
273+
--color=yes \
274+
--show-capture=no \
275+
--mh-config=./mhc.yaml \
276+
--mh-artifacts-dir=$GITHUB_WORKSPACE/artifacts \
277+
--polarion-config=../polarion.yaml \
278+
--output-polarion-testcase=$GITHUB_WORKSPACE/artifacts/testcase.xml \
279+
--output-polarion-testrun=$GITHUB_WORKSPACE/artifacts/testrun.xml \
280+
-vvv . |& tee $GITHUB_WORKSPACE/pytest.log
281+
282+
- name: Upload artifacts
283+
if: always()
284+
uses: actions/upload-artifact@v4
285+
with:
286+
if-no-files-found: ignore
287+
name: ${{ matrix.tag }}-system
288+
path: |
289+
artifacts
290+
build.log
291+
install.log
292+
pytest.log
293+
pytest-collect.log
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
name: "Static code analysis"
2+
on:
3+
push:
4+
branches: [master]
5+
pull_request:
6+
branches: [master]
7+
schedule:
8+
# Everyday at midnight
9+
- cron: '0 0 * * *'
10+
concurrency:
11+
group: ${{ github.workflow }}-${{ github.ref }}
12+
cancel-in-progress: true
13+
jobs:
14+
static-code-analysis-tests:
15+
runs-on: ubuntu-latest
16+
permissions:
17+
contents: read
18+
steps:
19+
- uses: actions/setup-python@v6
20+
with:
21+
python-version: '3.x'
22+
23+
- name: Checkout repository
24+
uses: actions/checkout@v5
25+
with:
26+
repository: RedHat-SP-Security/sudo-tests
27+
path: sudo-tests
28+
29+
- name: Setup virtual environment
30+
working-directory: ./sudo-tests/pytest
31+
run: |
32+
sudo apt-get update
33+
34+
# Install dependencies for python-ldap
35+
sudo apt-get install -y libsasl2-dev python3-dev libldap2-dev libssl-dev libssh-dev
36+
37+
pip3 install virtualenv
38+
python3 -m venv .venv
39+
source .venv/bin/activate
40+
pip3 install -r ./requirements.txt
41+
pip3 install flake8 pycodestyle isort mypy black
42+
43+
- name: flake8
44+
if: always()
45+
working-directory: ./sudo-tests/pytest
46+
run: source .venv/bin/activate && flake8 .
47+
48+
- name: pycodestyle
49+
if: always()
50+
working-directory: ./sudo-tests/pytest
51+
run: source .venv/bin/activate && pycodestyle .
52+
53+
- name: isort
54+
if: always()
55+
working-directory: ./sudo-tests/pytest
56+
run: source .venv/bin/activate && isort --check-only .
57+
58+
- name: black
59+
if: always()
60+
working-directory: ./sudo-tests/pytest
61+
run: source .venv/bin/activate && black --check --diff .
62+
63+
- name: mypy
64+
if: always()
65+
working-directory: ./sudo-tests/pytest
66+
run: source .venv/bin/activate && mypy --install-types --non-interactive tests
67+
68+
result:
69+
name: All tests are successful
70+
if: ${{ always() }}
71+
runs-on: ubuntu-latest
72+
needs: [pytest-tests]
73+
steps:
74+
- name: Fail on failure
75+
if: |
76+
needs.static-code-analysis-tests.result != 'success'
77+
run: exit 1

0 commit comments

Comments
 (0)